Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Source Code ///
- add:: (a: float, b: float) -> int {
- return a + b;
- }
- main:: () -> int {
- hello_world := "Hello World!";
- a := -12.0;
- b := 16.0;
- return add(a, b);
- }
- /// AST ///
- Create function declaration: add
- Parameters :
- float a
- float b
- Create return statement
- Create binary operation +
- Create identifier reference: a
- Create identifier reference: b
- Create function declaration: puts
- Parameters :
- int8* str
- Create function declaration: main
- Create assignment for hello_world
- Create string: 'Hello World'
- Create assignment for a
- Create double: -12
- Create assignment for b
- Create double: 16
- Create return statement
- Create function call: add
- Arguments are:
- Create identifier reference: a
- Create identifier reference: b
- End block
- /// LLVM IR: -O3 ///
- @.str = private constant [12 x i8] c"Hello World\00", align 1
- define i32 @add(i32 %a1, i32 %b2) {
- %1 = add i32 %b2, %a1
- ret i32 %1
- }
- declare void @puts(i8*)
- define i32 @main() {
- %1 = call i32 @add(i32 -12, i32 16)
- ret i32 %1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement