From fe336d16ec936512171ddcf290f555697ac617cf Mon Sep 17 00:00:00 2001 From: lshlyapnikov Date: Fri, 18 Oct 2019 00:47:41 -0400 Subject: [PATCH] Add name to FunctionBuilder --- src/function_builder.rs | 8 ++++++++ src/module/functions/mod.rs | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/function_builder.rs b/src/function_builder.rs index d71a3744..ea8b67d9 100644 --- a/src/function_builder.rs +++ b/src/function_builder.rs @@ -17,6 +17,7 @@ pub struct FunctionBuilder { pub(crate) arena: TombstoneArena, pub(crate) ty: TypeId, pub(crate) entry: Option, + pub(crate) name: Option, } impl FunctionBuilder { @@ -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() diff --git a/src/module/functions/mod.rs b/src/module/functions/mod.rs index 0dfc50b2..ddd8e4bc 100644 --- a/src/module/functions/mod.rs +++ b/src/module/functions/mod.rs @@ -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, }) }