LLVM-2.X系の文法
1.X系から大きく変わってます。
Cコードhellostruct.c
int puts(const char*); struct Hello { int age; char* name; }; int main() { struct Hello hello; hello.age = 15; hello.name = "Taro"; puts(hello.name); return 0; }
相当のLLVMコードhellostruct.ll
; int puts(char*) declare i32 @puts(i8*) ; struct Hello {int age; char* name;} %Hello = type { i32, i8* } ; static char taro[5] = "Taro" @taro = internal constant [5 x i8] c"Taro\00" ; int main() define i32 @main() { entry: ; hello = new Hello : Hello* %hello = alloca %Hello ; page = &(hello[0].age) : int* %page = getelementptr %Hello* %hello, i32 0, i32 0 ; *page = 15 : int store i32 15, i32* %page ; pname = &(hello[0].name) : char** %pname = getelementptr %Hello* %hello, i32 0, i32 1 ; *pname = &(taro[0][0]) : char* store i8* getelementptr ([5 x i8]* @taro, i32 0, i32 0), i8** %pname ; vname = *pname : char* %vname = load i8** %pname ; ret = puts(vname) : int %ret = call i32 @puts(i8* %vname) ; return 0 : int ret i32 0 }
i32やi8はtypedefっぽくしたほうがいいのかも
; int = i32, byte = i8, strng = byte*, offset_t = uint32 %int = type i32 %byte = type i8 %string = type %byte* %offset_t = type i32 ; int puts(char*) declare %int @puts(%string) ; struct Hello {int age; char* name;} %Hello = type { %int, %string } ; static char taro[5] = "Taro" @taro = internal constant [5 x %byte] c"Taro\00" ; int main() define %int @main() { entry: ; hello = new Hello : Hello* %hello = alloca %Hello ; page = &(hello[0].age) : int* %page = getelementptr %Hello* %hello, %offset_t 0, %offset_t 0 ; *page = 15 : int store %int 15, %int* %page ; pname = &(hello[0].name) : char** %pname = getelementptr %Hello* %hello, %offset_t 0, %offset_t 1 ; *pname = &(taro[0][0]) : char* %vtaro = getelementptr [5 x %byte]* @taro, %offset_t 0, %offset_t 0 store %string %vtaro, %string* %pname ; vname = *pname : char* %vname = load %string* %pname ; ret = puts(vname) : int %ret = call %int @puts(%string %vname) ; return 0 : int ret %int 0 }