LLVM heap allocation

分からなくなってきたので直接 LLVM IR を書いてみている。以下 cons のつもりで書いたけど違うな、これだと唯の配列操作か。もう少し LLVM を調べないと。

define [2 x i32]* @cons(i32 %arg1, i32 %arg2) nounwind {
entry:
	%tmp1 = alloca i32
	store i32 %arg1, i32* %tmp1
	%tmp2 = alloca i32
	store i32 %arg2, i32* %tmp2
	
	%cons = malloc [ 2 x i32]

	%car = getelementptr [ 2 x i32 ]* %cons, i32 0, i32 0
	%tmp3 = load i32* %tmp1
	store i32 %tmp3, i32* %car

	%cdr = getelementptr [ 2 x i32 ]* %cons, i32 0, i32 1
	%tmp4 = load i32* %tmp2
	store i32 %tmp4, i32* %cdr
	
	ret [ 2 x i32 ]* %cons
}

define i32 @scheme_entry() nounwind {
entry:
	%c1 = call [2 x i32]* @cons (i32 3, i32 5)

	%cdr = getelementptr [ 2 x i32 ]* %c1, i32 0, i32 1
	%tmp = load i32* %cdr

	ret i32 %tmp
}