Skip to content

Commit

Permalink
feat(ir): add builder for function kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniMay committed Feb 17, 2024
1 parent 904df79 commit 33d349f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/ir/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Function, BuilderErr> {
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<Function, BuilderErr> {
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<Function, BuilderErr> {
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> {
Expand Down
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::io;

use ir::{
builder::{GlobalValueBuilder, LocalBlockBuilder, LocalValueBuilder},
entities::FunctionKind,
module::Module,
pass::GlobalPass,
types::Type,
Expand All @@ -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();

Expand Down

0 comments on commit 33d349f

Please sign in to comment.