Advertisement
Guest User

Untitled

a guest
May 31st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LLVM 4.30 KB | None | 0 0
  1. * If + wypisanie
  2. ** C
  3. int puts(char*, int);
  4. int getchar();
  5.  
  6. int main(){
  7.     char* ret;
  8.     if(getchar() == 32)
  9.         ret = "spacja";
  10.     else
  11.         ret = "inny klawisz";
  12.  
  13.     puts(ret, 1);
  14.  
  15.     return 0;
  16. }
  17. ** IR
  18. ; ModuleID = "/home/maxmati/src/2017/maxmati/parser2/main.py"
  19. target triple = ""
  20. target datalayout = ""
  21.  
  22. declare i32 @"puts"(i8* %".1", i32 %".2")
  23.  
  24. declare i32 @"getchar"()
  25.  
  26. define i32 @"main"()
  27. {
  28. entry:
  29.   %"ret" = alloca i8*
  30.   %".2" = call i32 () @"getchar"()
  31.   %".3" = icmp eq i32 %".2", 32
  32.   br i1 %".3", label %"entry.if", label %"entry.else"
  33. entry.if:
  34.   %".5" = getelementptr inbounds [7 x i8], [7 x i8]* @".str", i32 0, i32 0
  35.   store i8* %".5", i8** %"ret"
  36.   br label %"entry.endif"
  37. entry.else:
  38.   %".8" = getelementptr inbounds [13 x i8], [13 x i8]* @".str.1", i32 0, i32 0
  39.   store i8* %".8", i8** %"ret"
  40.   br label %"entry.endif"
  41. entry.endif:
  42.   %".11" = load i8*, i8** %"ret"
  43.   %".12" = call i32 (i8*, i32) @"puts"(i8* %".11", i32 1)
  44.   ret i32 0
  45. }
  46.  
  47. @".str" = private  unnamed_addr  constant [7 x i8] [i8 115, i8 112, i8 97, i8 99, i8 106, i8 97, i8 0]
  48. @".str.1" = private  unnamed_addr  constant [13 x i8] [i8 105, i8 110, i8 110, i8 121, i8 32, i8 107, i8 108, i8 97, i8 119, i8 105, i8 115, i8 122, i8 0]
  49. ** explained
  50.    ; ModuleID = "/home/maxmati/src/2017/maxmati/parser2/main.py"
  51.    target triple = ""
  52.    target datalayout = ""
  53.  
  54. int puts(char*, int);
  55.    declare i32 @"puts"(i8* %".1", i32 %".2")
  56.  
  57. int getchar();
  58.    declare i32 @"getchar"()
  59.  
  60. int main(){
  61.    define i32 @"main"()
  62.    {
  63.    entry:
  64. char* ret;
  65.      %"ret" = alloca i8*
  66. if(getchar() == 32)
  67.      %".2" = call i32 () @"getchar"()
  68.      %".3" = icmp eq i32 %".2", 32
  69.      br i1 %".3", label %"entry.if", label %"entry.else"
  70.    entry.if:
  71. ret = "spacja";
  72.      %".5" = getelementptr inbounds [7 x i8], [7 x i8]* @".str", i32 0, i32 0
  73.      store i8* %".5", i8** %"ret"
  74.      br label %"entry.endif"
  75.    entry.else:
  76. ret = "inny klawisz";
  77.      %".8" = getelementptr inbounds [13 x i8], [13 x i8]* @".str.1", i32 0, i32 0
  78.      store i8* %".8", i8** %"ret"
  79.      br label %"entry.endif"
  80.    entry.endif:
  81. puts(ret, 1);
  82.      %".11" = load i8*, i8** %"ret"
  83.      %".12" = call i32 (i8*, i32) @"puts"(i8* %".11", i32 1)
  84. return 0;
  85.      ret i32 0
  86.    }
  87. "spacja"
  88.    @".str" = private  unnamed_addr  constant [7 x i8] [i8 115, i8 112, i8 97, i8 99, i8 106, i8 97, i8 0]
  89. "inny klawisz"
  90.    @".str.1" = private  unnamed_addr  constant [13 x i8] [i8 105, i8 110, i8 110, i8 121, i8 32, i8 107, i8 108, i8 97, i8 119, i8 105, i8 115, i8 122, i8 0]
  91. * funkcje
  92. ** C
  93. int test(int a, int b){
  94.     int c;
  95.     c = a * b;
  96.     return c + 2;
  97. }
  98.  
  99. int main(){
  100.     int a;
  101.     int b;
  102.     b = 15;
  103.     a = test(b, 10)
  104.     return a;
  105. }
  106. ** IR
  107. target triple = ""
  108. target datalayout = ""
  109.  
  110. define i32 @"test"(i32 %".1", i32 %".2")
  111. {
  112. entry:
  113.   %"a" = alloca i32
  114.   store i32 %".1", i32* %"a"
  115.   %"b" = alloca i32
  116.   store i32 %".2", i32* %"b"
  117.   %"c" = alloca i32
  118.   %".6" = load i32, i32* %"a"
  119.   %".7" = load i32, i32* %"b"
  120.   %".8" = mul i32 %".6", %".7"
  121.   store i32 %".8", i32* %"c"
  122.   %".10" = load i32, i32* %"c"
  123.   %".11" = add i32 %".10", 2
  124.   ret i32 %".11"
  125. }
  126.  
  127. define i32 @"main"()
  128. {
  129. entry:
  130.   %"a" = alloca i32
  131.   %"b" = alloca i32
  132.   store i32 15, i32* %"b"
  133.   %".3" = load i32, i32* %"b"
  134.   %".4" = call i32 (i32, i32) @"test"(i32 %".3", i32 10)
  135.   store i32 %".4", i32* %"a"
  136.   %".6" = load i32, i32* %"a"
  137.   ret i32 %".6"
  138. }
  139. ** explained
  140.   target triple = ""
  141.   target datalayout = ""
  142.  
  143. int test(int a, int b){
  144.   define i32 @"test"(i32 %".1", i32 %".2")
  145.   {
  146.   entry:
  147.     %"a" = alloca i32
  148.     store i32 %".1", i32* %"a"
  149.     %"b" = alloca i32
  150.     store i32 %".2", i32* %"b"
  151. int c;
  152.     %"c" = alloca i32
  153. c = a * b;
  154.     %".6" = load i32, i32* %"a"
  155.     %".7" = load i32, i32* %"b"
  156.     %".8" = mul i32 %".6", %".7"
  157.     store i32 %".8", i32* %"c"
  158. return c + 2;
  159.     %".10" = load i32, i32* %"c"
  160.     %".11" = add i32 %".10", 2
  161.     ret i32 %".11"
  162.   }
  163.  
  164. int main(){
  165.   define i32 @"main"()
  166.   {
  167.   entry:
  168. int a;
  169.     %"a" = alloca i32
  170. int b;
  171.     %"b" = alloca i32
  172. b = 15;
  173.     store i32 15, i32* %"b"
  174. a = test(b, 10)
  175.     %".3" = load i32, i32* %"b"
  176.     %".4" = call i32 (i32, i32) @"test"(i32 %".3", i32 10)
  177.     store i32 %".4", i32* %"a"
  178. return a;
  179.     %".6" = load i32, i32* %"a"
  180.     ret i32 %".6"
  181.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement