Skip to content

Commit

Permalink
Merge pull request #56 from alexcrichton/finish-parts
Browse files Browse the repository at this point in the history
Allow finishing `FunctionBuilder` with module parts
  • Loading branch information
alexcrichton authored Feb 15, 2019
2 parents 0c54875 + dc8b2b6 commit 52eef76
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/function_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::ir::*;
use crate::{FunctionId, LocalFunction, Module, TypeId, ValType};
use crate::{ModuleTypes, ModuleFunctions};
use id_arena::Arena;
use std::mem;
use std::ops::{Deref, DerefMut, Drop};
Expand Down Expand Up @@ -114,21 +115,34 @@ impl FunctionBuilder {
/// Finishes this builder, wrapping it all up and inserting it into the
/// specified `Module`.
pub fn finish(
mut self,
self,
ty_id: TypeId,
args: Vec<LocalId>,
exprs: Vec<ExprId>,
module: &mut Module,
) -> FunctionId {
let ty = module.types.get(ty_id);
self.finish_parts(ty_id, args, exprs, &mut module.types, &mut module.funcs)
}

/// Finishes this builder, wrapping it all up and inserting it into the
/// specified `Module`.
pub fn finish_parts(
mut self,
ty_id: TypeId,
args: Vec<LocalId>,
exprs: Vec<ExprId>,
types: &mut ModuleTypes,
funcs: &mut ModuleFunctions,
) -> FunctionId {
let ty = types.get(ty_id);
let entry = self.alloc(Block {
kind: BlockKind::FunctionEntry,
params: ty.params().to_vec().into_boxed_slice(),
results: ty.results().to_vec().into_boxed_slice(),
exprs,
});
let func = LocalFunction::new(ty_id, args, self.arena, entry);
module.funcs.add_local(func)
funcs.add_local(func)
}
}

Expand Down

0 comments on commit 52eef76

Please sign in to comment.