Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. declare void @printInt(i32)
  2. declare i8* @calloc(i32, i32)
  3.  
  4. %arr1 = type {[ 0 x %arr2 ], i32 }*
  5. %arr2 = type {[ 0 x i32 ], i32 }*
  6.  
  7. define i32 @main() {
  8.   entry:
  9.    
  10.     ; int[][] x = new int[3][4]; -----------------------------------------
  11.    
  12.     %x = alloca %arr1
  13.    
  14.     %x1 = alloca %arr2 ; we need these four allocas, right ? implies the need of a structure in LLVM AS to keep these
  15.     %x2 = alloca %arr2
  16.     %x3 = alloca %arr2
  17.     %x4 = alloca %arr2
  18.    
  19.     ; START "new" scheme
  20.    
  21.     %ca = call i8* @calloc(i32 4, i32 4) ; 3 elems + length
  22.     %co = bitcast i8* %ca to %arr1
  23.    
  24.     %ca1 = call i8* @calloc(i32 4, i32 4)
  25.     %co1 = bitcast i8* %ca1 to %arr2
  26.    
  27.     %ca2 = call i8* @calloc(i32 4, i32 4)
  28.     %co2 = bitcast i8* %ca2 to %arr2
  29.    
  30.     %ca3 = call i8* @calloc(i32 4, i32 4)
  31.     %co3 = bitcast i8* %ca3 to %arr2
  32.    
  33.     ; END "new" scheme
  34.    
  35.     store %arr2 %co1, %arr2* %x1
  36.     store %arr2 %co2, %arr2* %x2
  37.     store %arr2 %co3, %arr2* %x3
  38.    
  39.     store %arr1 %co, %arr1* %x
  40.    
  41.     ; ----------------------------------------------------------------
  42.    
  43.     ; printInt(x[1][2]); ---------------------------------------------
  44.    
  45.     %t0 = load %arr1* %x
  46.     %t1 = getelementptr %arr1 %t0, i32 0, i32 0, i32 1
  47.     %t2 = load %arr2* %t1
  48.     %t3 = getelementptr %arr2 %t2, i32 0, i32 0, i32 2
  49.     %t4 = load i32* %t3
  50.    
  51.     call void @printInt(i32 %t4)
  52.    
  53.     ; ----------------------------------------------------------------
  54.    
  55.     ret i32 0
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement