Skip to content

Commit

Permalink
Merge pull request #134 from lshlyapnikov/master
Browse files Browse the repository at this point in the history
Add name to FunctionBuilder
  • Loading branch information
fitzgen committed Oct 18, 2019
2 parents d4f84ea + fe336d1 commit c54470a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/function_builder.rs
Expand Up @@ -17,6 +17,7 @@ pub struct FunctionBuilder {
pub(crate) arena: TombstoneArena<InstrSeq>,
pub(crate) ty: TypeId,
pub(crate) entry: Option<InstrSeqId>,
pub(crate) name: Option<String>,
}

impl FunctionBuilder {
Expand All @@ -42,9 +43,16 @@ impl FunctionBuilder {
arena,
ty,
entry: None,
name: None,
}
}

/// Set function name.
pub fn name(&mut self, function_name: String) -> &mut FunctionBuilder {
self.name = Some(function_name);
self
}

/// Get the id of this function's body's instruction sequence.
pub fn func_body_id(&self) -> InstrSeqId {
self.entry.unwrap()
Expand Down
3 changes: 2 additions & 1 deletion src/module/functions/mod.rs
Expand Up @@ -157,10 +157,11 @@ impl ModuleFunctions {

/// Create a new internally defined function
pub fn add_local(&mut self, func: LocalFunction) -> FunctionId {
let func_name = func.builder().name.clone();
self.arena.alloc_with_id(|id| Function {
id,
kind: FunctionKind::Local(func),
name: None,
name: func_name,
})
}

Expand Down

0 comments on commit c54470a

Please sign in to comment.