-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: if expressions code generation
- Loading branch information
1 parent
efdd9fb
commit 2968ada
Showing
5 changed files
with
218 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
source: crates/mun_codegen/src/test.rs | ||
expression: "fn fibonacci(n:int):int {\n if n <= 1 {\n n\n } else {\n fibonacci(n-1) + fibonacci(n-2)\n }\n}" | ||
--- | ||
; ModuleID = 'main.mun' | ||
source_filename = "main.mun" | ||
|
||
%DispatchTable = type { i64 (i64)* } | ||
|
||
@dispatchTable = global %DispatchTable { i64 (i64)* @fibonacci } | ||
|
||
define i64 @fibonacci(i64 %n) { | ||
body: | ||
%lesseq = icmp sle i64 %n, 1 | ||
br i1 %lesseq, label %if_merge, label %else | ||
|
||
else: ; preds = %body | ||
%sub = sub i64 %n, 1 | ||
%fibonacci_ptr = load i64 (i64)*, i64 (i64)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0) | ||
%fibonacci = call i64 %fibonacci_ptr(i64 %sub) | ||
%sub1 = sub i64 %n, 2 | ||
%fibonacci_ptr2 = load i64 (i64)*, i64 (i64)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0) | ||
%fibonacci3 = call i64 %fibonacci_ptr2(i64 %sub1) | ||
%add = add i64 %fibonacci, %fibonacci3 | ||
br label %if_merge | ||
|
||
if_merge: ; preds = %body, %else | ||
%iftmp = phi i64 [ %add, %else ], [ %n, %body ] | ||
ret i64 %iftmp | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
source: crates/mun_codegen/src/test.rs | ||
expression: "fn foo(a:int):int {\n if a > 3 {\n a+1\n } else {\n a-1\n }\n}" | ||
--- | ||
; ModuleID = 'main.mun' | ||
source_filename = "main.mun" | ||
|
||
define i64 @foo(i64 %a) { | ||
body: | ||
%greater = icmp sgt i64 %a, 3 | ||
%add = add i64 %a, 1 | ||
%sub = sub i64 %a, 1 | ||
%iftmp = select i1 %greater, i64 %add, i64 %sub | ||
ret i64 %iftmp | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters