LLVM程序的输入数据的基本转换模块是Moudle.
每个Moudle有一下的元素构成:函数,全局变量,符号表入口;以及LLVM linker(联系Moudles之间:其他模块的 全局变量,函数的前向声明,以及外部符号表入口);
; Declare the string constant as a global constant.
@.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
; External declaration of the puts function
declare i32 @puts(i8* nocapture) nounwind
; Definition of main function
define i32 @main() { ; i32()*
; Convert [13 x i8]* to i8*...
%cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0
; Call puts function to write out the string to stdout.
call i32 @puts(i8* %cast210)
ret i32 0
}
; Named metadata
!0 = !{i32 42, null, !"string"}
!foo = !{!0}
此示例由名为“.str”的全局变量(global variable)、“put”函数的外部声明(External Declaration)、“main”的函数定义和命名的元数(Named metadata)据“foo”组成。
通常,一个模块由一个全局值列表组成(其中函数和全局变量都是全局值)。全局值由指向内存位置的指针(在本例中为指向char数组的指针和指向函数的指针)表示,并且具有以下链接类型(linkage type)之一。