Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare void @printInt(i32)
- declare i8* @calloc(i32, i32)
- %arr1 = type {[ 0 x %arr2 ], i32 }*
- %arr2 = type {[ 0 x i32 ], i32 }*
- define i32 @main() {
- entry:
- ; int[][] x = new int[3][4]; -----------------------------------------
- %x = alloca %arr1
- %x1 = alloca %arr2 ; we need these four allocas, right ? implies the need of a structure in LLVM AS to keep these
- %x2 = alloca %arr2
- %x3 = alloca %arr2
- %x4 = alloca %arr2
- ; START "new" scheme
- %ca = call i8* @calloc(i32 4, i32 4) ; 3 elems + length
- %co = bitcast i8* %ca to %arr1
- %ca1 = call i8* @calloc(i32 4, i32 4)
- %co1 = bitcast i8* %ca1 to %arr2
- %ca2 = call i8* @calloc(i32 4, i32 4)
- %co2 = bitcast i8* %ca2 to %arr2
- %ca3 = call i8* @calloc(i32 4, i32 4)
- %co3 = bitcast i8* %ca3 to %arr2
- ; END "new" scheme
- store %arr2 %co1, %arr2* %x1
- store %arr2 %co2, %arr2* %x2
- store %arr2 %co3, %arr2* %x3
- store %arr1 %co, %arr1* %x
- ; ----------------------------------------------------------------
- ; printInt(x[1][2]); ---------------------------------------------
- %t0 = load %arr1* %x
- %t1 = getelementptr %arr1 %t0, i32 0, i32 0, i32 1
- %t2 = load %arr2* %t1
- %t3 = getelementptr %arr2 %t2, i32 0, i32 0, i32 2
- %t4 = load i32* %t3
- call void @printInt(i32 %t4)
- ; ----------------------------------------------------------------
- ret i32 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement