Inkwell
basic
let context = Context::create();
// module
let module = context.create_module("main");
// builder
let builder = context.create_builder();
// i32
let i32_type = context.i32_type();
// main: () -> i32
let main_fn_type = i32_type.fn_type(&[i32_type.into()], false);
let main_fn = module.add_function("main", main_fn_type, None);
// block
let basic_block = context.append_basic_block(main_fn, "entry");
builder.position_at_end(basic_block);
// a = 3, b = 5
let a = builder.build_alloca(context.i32_type(), "a");
let b = builder.build_alloca(context.i32_type(), "b");
let three = i32_type.const_int(3, false);
let five = i32_type.const_int(5, false);
builder.build_store(a, three);
builder.build_store(b, five);
// load a, b
let bload = builder.build_load(b, "bload");
let aload = builder.build_load(a, "aload");
// add a, b
let c = builder.build_int_add(aload.into_int_value(), bload.into_int_value(), "c");
builder.build_return(Some(&c));
function declare
// decrare builtin function
let i32_type = ctx.i32_type();
let putchar_type = i32_type.fn_type(&[i32_type.into()], false);
functions.insert("putchar".to_owned());
module.add_function("putchar", putchar_type, None);
大体同じことしてた