-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllvm.aat
68 lines (52 loc) · 2.18 KB
/
llvm.aat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
type LLVMType
type LLVMValue
type LLVMContext
type LLVMModule
type LLVMBasicBlock
type LLVMBuilder
type LLVMTypeRef = LLVMType*
type LLVMValueRef = LLVMValue*
type LLVMContextRef = LLVMContext*
type LLVMModuleRef = LLVMModule*
type LLVMBasicBlockRef = LLVMBasicBlock*
type LLVMBuilderRef = LLVMBuilder*
extern fn LLVMGetGlobalContext () -> LLVMContextRef
extern fn LLVMInitializeNativeTarget () -> bool
extern fn LLVMInitializeNativeAsmPrinter () -> bool
extern fn LLVMModuleCreateWithName str -> LLVMModuleRef
extern fn LLVMDumpModule m: LLVMModuleRef -> ()
extern fn LLVMAddFunction m: LLVMModuleRef, str, ty: LLVMTypeRef -> LLVMValueRef
extern fn LLVMCreateBuilder () -> LLVMBuilderRef
extern fn LLVMAppendBasicBlock LLVMValueRef, str -> LLVMBasicBlockRef
extern fn LLVMPositionBuilderAtEnd LLVMBuilderRef, LLVMBasicBlockRef -> ()
extern fn LLVMVoidType () -> LLVMTypeRef
extern fn LLVMPointerType p: LLVMTypeRef, u32 -> LLVMTypeRef
extern fn LLVMInt8Type () -> LLVMTypeRef
extern fn LLVMInt32Type () -> LLVMTypeRef
extern fn LLVMFunctionType r: LLVMTypeRef, p: [LLVMTypeRef], u32, bool -> LLVMTypeRef
extern fn LLVMConstInt LLVMTypeRef, u64, bool -> LLVMValueRef
extern fn LLVMBuildAdd LLVMBuilderRef, LLVMValueRef, LLVMValueRef, str -> LLVMValueRef
extern fn LLVMBuildRet LLVMBuilderRef, LLVMValueRef -> LLVMValueRef
extern fn malloc u64 -> char*
extern fn printf str, ... -> ()
fn sint32 value: u64 -> LLVMValueRef = LLVMConstInt (LLVMInt32Type ()), value, true
fn main () = {
val module = LLVMModuleCreateWithName "test"
val cty = LLVMInt8Type ()
val cpty = LLVMPointerType cty, 0u32
val vty = LLVMVoidType ()
val args = [cpty]
val fty = LLVMFunctionType vty, args as [LLVMTypeRef], 1u32, true
LLVMAddFunction module, "printf", fty
val margs = [vty]
val mty = LLVMFunctionType (LLVMInt32Type ()), margs as [LLVMTypeRef], 1u32, false
val m = LLVMAddFunction module, "main", mty
val ebb = LLVMAppendBasicBlock m, "entry"
val builder = LLVMCreateBuilder ()
LLVMPositionBuilderAtEnd builder, ebb
val x = sint32 64u64
val y = sint32 128u64
val res = LLVMBuildAdd builder, x, y, "res"
LLVMBuildRet builder, res
LLVMDumpModule module
}