diff --git a/reid-llvm-lib/examples/libtest.rs b/reid-llvm-lib/examples/libtest.rs index 834a8fe..f33f871 100644 --- a/reid-llvm-lib/examples/libtest.rs +++ b/reid-llvm-lib/examples/libtest.rs @@ -1,4 +1,4 @@ -use reid_lib::{ConstValue, Context, Instr, CmpPredicate, TerminatorKind, Type}; +use reid_lib::{CmpPredicate, ConstValue, Context, FunctionFlags, Instr, TerminatorKind, Type}; fn main() { use ConstValue::*; @@ -8,10 +8,15 @@ fn main() { let mut module = context.module("test"); - let main = module.function("main", Type::I32, Vec::new()); + let main = module.function("main", Type::I32, Vec::new(), FunctionFlags::default()); let mut m_entry = main.block("entry"); - let fibonacci = module.function("fibonacci", Type::I32, vec![Type::I32]); + let fibonacci = module.function( + "fibonacci", + Type::I32, + vec![Type::I32], + FunctionFlags::default(), + ); let arg = m_entry.build(Constant(I32(5))).unwrap(); let fibonacci_call = m_entry diff --git a/reid-llvm-lib/src/lib.rs b/reid-llvm-lib/src/lib.rs index eba2147..819f93b 100644 --- a/reid-llvm-lib/src/lib.rs +++ b/reid-llvm-lib/src/lib.rs @@ -49,7 +49,13 @@ pub struct Module<'ctx> { } impl<'ctx> Module<'ctx> { - pub fn function(&mut self, name: &str, ret: Type, params: Vec) -> Function<'ctx> { + pub fn function( + &mut self, + name: &str, + ret: Type, + params: Vec, + flags: FunctionFlags, + ) -> Function<'ctx> { unsafe { Function { phantom: PhantomData, @@ -60,6 +66,7 @@ impl<'ctx> Module<'ctx> { name: name.to_owned(), ret, params, + flags, }, ), } @@ -76,6 +83,18 @@ pub struct FunctionData { name: String, ret: Type, params: Vec, + flags: FunctionFlags, +} + +#[derive(Debug, Clone, Copy, Hash)] +pub struct FunctionFlags { + pub is_extern: bool, +} + +impl Default for FunctionFlags { + fn default() -> FunctionFlags { + FunctionFlags { is_extern: false } + } } pub struct Function<'ctx> { diff --git a/reid/src/codegen.rs b/reid/src/codegen.rs index 8b02f81..53eb947 100644 --- a/reid/src/codegen.rs +++ b/reid/src/codegen.rs @@ -1,8 +1,8 @@ use std::{collections::HashMap, mem}; use reid_lib::{ - builder::InstructionValue, Block, CmpPredicate, ConstValue, Context, Function, Instr, Module, - TerminatorKind as Term, Type, + builder::InstructionValue, Block, CmpPredicate, ConstValue, Context, Function, FunctionFlags, + Instr, Module, TerminatorKind as Term, Type, }; use crate::mir::{self, types::ReturnType, IndexedVariableReference, NamedVariableRef, TypeKind}; @@ -60,10 +60,21 @@ impl mir::Module { .collect(); let func = match &function.kind { - mir::FunctionDefinitionKind::Local(_, _) => { - module.function(&function.name, function.return_type.get_type(), param_types) - } - mir::FunctionDefinitionKind::Extern => todo!(), + mir::FunctionDefinitionKind::Local(_, _) => module.function( + &function.name, + function.return_type.get_type(), + param_types, + FunctionFlags::default(), + ), + mir::FunctionDefinitionKind::Extern => module.function( + &function.name, + function.return_type.get_type(), + param_types, + FunctionFlags { + is_extern: true, + ..FunctionFlags::default() + }, + ), }; functions.insert(function.name.clone(), func); } diff --git a/reid/src/mir/typecheck.rs b/reid/src/mir/typecheck.rs index 68a2a98..f3c782f 100644 --- a/reid/src/mir/typecheck.rs +++ b/reid/src/mir/typecheck.rs @@ -536,7 +536,7 @@ impl Literal { (L::U64(_), TypeKind::U64) => self, (L::U128(_), TypeKind::U128) => self, (L::Bool(_), TypeKind::Bool) => self, - (L::String(val), TypeKind::StringPtr) => self, + (L::String(_), TypeKind::StringPtr) => self, // TODO make sure that v is actually able to fit in the // requested type (L::Vague(VagueL::Number(v)), TypeKind::I8) => L::I8(v as i8),