-
-
Notifications
You must be signed in to change notification settings - Fork 78
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 7211aca
Showing
5 changed files
with
256 additions
and
63 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,28 @@ | ||
--- | ||
source: crates/mun_codegen/src/test.rs | ||
expression: "fn foo(a:int):int {\n let b = if a > 3 {\n let c = if a > 4 {\n a+1\n } else {\n a+3\n }\n c\n } else {\n a-1\n }\n b\n}" | ||
--- | ||
; ModuleID = 'main.mun' | ||
source_filename = "main.mun" | ||
|
||
define i64 @foo(i64 %a) { | ||
body: | ||
%greater = icmp sgt i64 %a, 3 | ||
br i1 %greater, label %then, label %else | ||
|
||
then: ; preds = %body | ||
%greater1 = icmp sgt i64 %a, 4 | ||
%add = add i64 %a, 1 | ||
%add5 = add i64 %a, 3 | ||
%iftmp = select i1 %greater1, i64 %add, i64 %add5 | ||
br label %if_merge | ||
|
||
else: ; preds = %body | ||
%sub = sub i64 %a, 1 | ||
br label %if_merge | ||
|
||
if_merge: ; preds = %else, %then | ||
%iftmp7 = phi i64 [ %iftmp, %then ], [ %sub, %else ] | ||
ret i64 %iftmp7 | ||
} | ||
|
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