diff --git a/src/ir/builder.rs b/src/ir/builder.rs index 17d9593..c804fbe 100644 --- a/src/ir/builder.rs +++ b/src/ir/builder.rs @@ -365,6 +365,27 @@ pub trait GlobalValueBuilder: QueryValueData + AddValue + ConstantBuilder { let data = FunctionData::new(name, ty.clone(), kind); self.add_function(data.new_value_data(), data) } + + /// Build a function definition. + fn function_def(&mut self, name: String, ty: Type) -> Result { + let data = FunctionData::new(name, ty.clone(), FunctionKind::Definition); + let function = self.add_function(data.new_value_data(), data)?; + Ok(function) + } + + /// Build a function declaration. + fn function_decl(&mut self, name: String, ty: Type) -> Result { + let data = FunctionData::new(name, ty.clone(), FunctionKind::Declaration); + let function = self.add_function(data.new_value_data(), data)?; + Ok(function) + } + + /// Build a intrinsic function. + fn function_intrinsic(&mut self, name: String, ty: Type) -> Result { + let data = FunctionData::new(name, ty.clone(), FunctionKind::Intrinsic); + let function = self.add_function(data.new_value_data(), data)?; + Ok(function) + } } pub struct LocalBuilder<'a> { diff --git a/src/main.rs b/src/main.rs index a4cb240..36df734 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use std::io; use ir::{ builder::{GlobalValueBuilder, LocalBlockBuilder, LocalValueBuilder}, - entities::FunctionKind, module::Module, pass::GlobalPass, types::Type, @@ -17,10 +16,9 @@ fn main() -> io::Result<()> { let mut module = Module::new("test".to_string()); let function = module .builder() - .function( + .function_def( "test_func".to_string(), Type::mk_function(vec![], Type::mk_void()), - FunctionKind::Definition, ) .unwrap();