Advertisement
mattparks5855

Hash LLVM IR

Jul 21st, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.14 KB | None | 0 0
  1. /// Source Code ///
  2. add:: (a: float, b: float) -> int {
  3.     return a + b;
  4. }
  5.  
  6. main:: () -> int {
  7.     hello_world := "Hello World!";
  8.     a := -12.0;
  9.     b := 16.0;
  10.     return add(a, b);
  11. }
  12.  
  13.  
  14.  
  15. /// AST ///
  16. Create function declaration: add
  17.     Parameters :
  18.       float a
  19.       float b
  20.     Create return statement
  21.       Create binary operation +
  22.         Create identifier reference: a
  23.         Create identifier reference: b
  24.   Create function declaration: puts
  25.     Parameters :
  26.       int8* str
  27.   Create function declaration: main
  28.     Create assignment for hello_world
  29.       Create string: 'Hello World'
  30.     Create assignment for a
  31.       Create double: -12
  32.     Create assignment for b
  33.       Create double: 16
  34.     Create return statement
  35.       Create function call: add
  36.         Arguments are:
  37.         Create identifier reference: a
  38.         Create identifier reference: b
  39. End block
  40.  
  41.  
  42.  
  43. /// LLVM IR: -O3 ///
  44. @.str = private constant [12 x i8] c"Hello World\00", align 1
  45.  
  46. define i32 @add(i32 %a1, i32 %b2) {
  47.   %1 = add i32 %b2, %a1
  48.   ret i32 %1
  49. }
  50.  
  51. declare void @puts(i8*)
  52.  
  53. define i32 @main() {
  54.   %1 = call i32 @add(i32 -12, i32 16)
  55.   ret i32 %1
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement