forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update subroutine methods to match functions
- Loading branch information
Showing
6 changed files
with
113 additions
and
11 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,17 @@ | ||
program main | ||
integer :: main_out = 999 | ||
call main1(main_out) | ||
print *, "main1 called" | ||
contains | ||
subroutine main1(out_var) | ||
integer :: out_var | ||
integer :: i = 10 | ||
if (i .GT. 5) then | ||
out_var = i | ||
print *, "early return" | ||
return | ||
end if | ||
print *, "normal return" | ||
out_var = i | ||
end subroutine main1 | ||
end program |
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,13 @@ | ||
{ | ||
"basename": "llvm-return_03-fd5ee01", | ||
"cmd": "lfortran --show-llvm {infile} -o {outfile}", | ||
"infile": "tests/../integration_tests/return_03.f90", | ||
"infile_hash": "7d4898b23c807b105723b597c037469040fba56ee6c9891c93947d14", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": "llvm-return_03-fd5ee01.stdout", | ||
"stdout_hash": "f5de0548d6690b15f07d47f1b94e6af28ecf80b55404c37a4ea9f4e5", | ||
"stderr": null, | ||
"stderr_hash": null, | ||
"returncode": 0 | ||
} |
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,48 @@ | ||
; ModuleID = 'LFortran' | ||
source_filename = "LFortran" | ||
|
||
@0 = private unnamed_addr constant [13 x i8] c"early return\00", align 1 | ||
@1 = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1 | ||
@2 = private unnamed_addr constant [14 x i8] c"normal return\00", align 1 | ||
@3 = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1 | ||
@4 = private unnamed_addr constant [13 x i8] c"main1 called\00", align 1 | ||
@5 = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1 | ||
|
||
define void @main1(i32* %out_var) { | ||
.entry: | ||
%i = alloca i32, align 4 | ||
store i32 10, i32* %i, align 4 | ||
%0 = load i32, i32* %i, align 4 | ||
%1 = icmp sgt i32 %0, 5 | ||
br i1 %1, label %then, label %else | ||
|
||
then: ; preds = %.entry | ||
%2 = load i32, i32* %i, align 4 | ||
store i32 %2, i32* %out_var, align 4 | ||
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @0, i32 0, i32 0)) | ||
br label %return | ||
|
||
return: ; preds = %ifcont, %then | ||
ret void | ||
|
||
else: ; preds = %.entry | ||
br label %ifcont | ||
|
||
ifcont: ; preds = %else | ||
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @2, i32 0, i32 0)) | ||
%3 = load i32, i32* %i, align 4 | ||
store i32 %3, i32* %out_var, align 4 | ||
br label %return | ||
} | ||
|
||
declare void @_lfortran_printf(i8*, ...) | ||
|
||
define i32 @main() { | ||
.entry: | ||
%main_out = alloca i32, align 4 | ||
store i32 999, i32* %main_out, align 4 | ||
call void @main1(i32* %main_out) | ||
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @4, i32 0, i32 0)) | ||
ret i32 0 | ||
} | ||
|
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