Skip to content

Commit

Permalink
Merge pull request #35 from tamaroning/cleanup
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
ainozaki authored Jun 28, 2024
2 parents be66b30 + 03db23a commit 16f78dd
Show file tree
Hide file tree
Showing 5 changed files with 1,349 additions and 1,362 deletions.
5 changes: 0 additions & 5 deletions src/insts.rs

This file was deleted.

33 changes: 17 additions & 16 deletions src/insts/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a> ControlFrame<'a> {
}
}

pub fn gen_block(environment: &mut Environment<'_, '_>, blockty: BlockType) -> Result<()> {
pub(super) fn gen_block(environment: &mut Environment<'_, '_>, blockty: &BlockType) -> Result<()> {
let current_block = environment.builder.get_insert_block().unwrap();
let next_block = environment.context.append_basic_block(
environment.function_list[environment.current_function_idx as usize],
Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn gen_block(environment: &mut Environment<'_, '_>, blockty: BlockType) -> R
Ok(())
}

pub fn gen_loop(environment: &mut Environment<'_, '_>, blockty: BlockType) -> Result<()> {
pub(super) fn gen_loop(environment: &mut Environment<'_, '_>, blockty: &BlockType) -> Result<()> {
let current_block = environment.builder.get_insert_block().unwrap();

// Create blocks
Expand Down Expand Up @@ -152,7 +152,7 @@ pub fn gen_loop(environment: &mut Environment<'_, '_>, blockty: BlockType) -> Re
Ok(())
}

pub fn gen_if(environment: &mut Environment<'_, '_>, blockty: BlockType) -> Result<()> {
pub(super) fn gen_if(environment: &mut Environment<'_, '_>, blockty: &BlockType) -> Result<()> {
let current_block = environment
.builder
.get_insert_block()
Expand Down Expand Up @@ -221,7 +221,7 @@ pub fn gen_if(environment: &mut Environment<'_, '_>, blockty: BlockType) -> Resu
Ok(())
}

pub fn gen_else(environment: &mut Environment<'_, '_>) -> Result<()> {
pub(super) fn gen_else(environment: &mut Environment<'_, '_>) -> Result<()> {
let current_block = environment
.builder
.get_insert_block()
Expand Down Expand Up @@ -263,7 +263,8 @@ pub fn gen_else(environment: &mut Environment<'_, '_>) -> Result<()> {
}
Ok(())
}
pub fn gen_br(environment: &mut Environment<'_, '_>, relative_depth: u32) -> Result<()> {

pub(super) fn gen_br(environment: &mut Environment<'_, '_>, relative_depth: u32) -> Result<()> {
let current_block = environment
.builder
.get_insert_block()
Expand All @@ -289,7 +290,7 @@ pub fn gen_br(environment: &mut Environment<'_, '_>, relative_depth: u32) -> Res
Ok(())
}

pub fn gen_brif(environment: &mut Environment<'_, '_>, relative_depth: u32) -> Result<()> {
pub(super) fn gen_brif(environment: &mut Environment<'_, '_>, relative_depth: u32) -> Result<()> {
let current_block = environment
.builder
.get_insert_block()
Expand Down Expand Up @@ -332,7 +333,7 @@ pub fn gen_brif(environment: &mut Environment<'_, '_>, relative_depth: u32) -> R
Ok(())
}

pub fn gen_br_table(environment: &mut Environment<'_, '_>, targets: BrTable) -> Result<()> {
pub(super) fn gen_br_table(environment: &mut Environment<'_, '_>, targets: &BrTable) -> Result<()> {
let current_block = environment
.builder
.get_insert_block()
Expand Down Expand Up @@ -389,9 +390,9 @@ pub fn gen_br_table(environment: &mut Environment<'_, '_>, targets: BrTable) ->
Ok(())
}

pub fn gen_end<'a>(
pub(super) fn gen_end<'a>(
environment: &mut Environment<'a, '_>,
current_fn: FunctionValue<'a>,
current_fn: &FunctionValue<'a>,
) -> Result<()> {
let current_block = environment
.builder
Expand Down Expand Up @@ -512,7 +513,7 @@ pub fn gen_end<'a>(
Ok(())
}

pub fn gen_call(environment: &mut Environment<'_, '_>, function_index: u32) -> Result<()> {
pub(super) fn gen_call(environment: &mut Environment<'_, '_>, function_index: u32) -> Result<()> {
let fn_called = environment.function_list[function_index as usize];

// collect args from stack
Expand Down Expand Up @@ -560,7 +561,7 @@ pub fn gen_call(environment: &mut Environment<'_, '_>, function_index: u32) -> R
Ok(())
}

pub fn gen_call_indirect(
pub(super) fn gen_call_indirect(
environment: &mut Environment<'_, '_>,
type_index: u32,
table_index: u32,
Expand Down Expand Up @@ -617,14 +618,14 @@ pub fn gen_call_indirect(
Ok(())
}

pub fn gen_drop(environment: &mut Environment<'_, '_>) -> Result<()> {
pub(super) fn gen_drop(environment: &mut Environment<'_, '_>) -> Result<()> {
environment.stack.pop().expect("stack empty");
Ok(())
}

pub fn gen_return(
pub(super) fn gen_return(
environment: &mut Environment<'_, '_>,
current_fn: FunctionValue<'_>,
current_fn: &FunctionValue<'_>,
) -> Result<()> {
// Phi
environment.unreachable_depth += 1;
Expand All @@ -642,7 +643,7 @@ pub fn gen_return(
Ok(())
}

pub fn gen_select(environment: &mut Environment<'_, '_>) -> Result<()> {
pub(super) fn gen_select(environment: &mut Environment<'_, '_>) -> Result<()> {
let v3 = environment.stack.pop().expect("stack empty");
let v2 = environment.stack.pop().expect("stack empty");
let v1 = environment.stack.pop().expect("stack empty");
Expand All @@ -657,7 +658,7 @@ pub fn gen_select(environment: &mut Environment<'_, '_>) -> Result<()> {
Ok(())
}

pub fn gen_unreachable(environment: &mut Environment<'_, '_>) -> Result<()> {
pub(super) fn gen_unreachable(environment: &mut Environment<'_, '_>) -> Result<()> {
environment.unreachable_depth += 1;
environment.unreachable_reason = UnreachableReason::Unreachable;
environment.builder.build_unreachable();
Expand Down
4 changes: 2 additions & 2 deletions src/insts/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn memory_fill(environment: &mut Environment<'_, '_>, mem: u32) -> Result<()

// generate IR for load instructions
pub fn generate_load<'a>(
memarg: MemArg,
memarg: &MemArg,
extended_type: inkwell::types::BasicTypeEnum<'a>,
load_type: inkwell::types::BasicTypeEnum<'a>,
signed: bool,
Expand Down Expand Up @@ -189,7 +189,7 @@ pub fn generate_load<'a>(
// generate IR for store instructions
// see generate_load
pub fn generate_store<'a>(
memarg: MemArg,
memarg: &MemArg,
store_type: inkwell::types::BasicTypeEnum<'a>,
require_narrow: bool,
environment: &mut Environment<'a, '_>,
Expand Down
Loading

0 comments on commit 16f78dd

Please sign in to comment.