Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added a.out
Binary file not shown.
Binary file added examples/test_2
Binary file not shown.
1 change: 1 addition & 0 deletions examples/test_2.gom
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io;

// struct
type Point = {
x: int,
y: int
Expand Down
147 changes: 147 additions & 0 deletions examples/test_2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 14, 0
.globl _square ; -- Begin function square
.p2align 2
_square: ; @square
.cfi_startproc
; %bb.0: ; %entry
sub sp, sp, #16
.cfi_def_cfa_offset 16
mov w8, w0
mul w0, w0, w0
str w8, [sp, #12]
add sp, sp, #16
ret
.cfi_endproc
; -- End function
.globl _add ; -- Begin function add
.p2align 2
_add: ; @add
.cfi_startproc
; %bb.0: ; %entry
sub sp, sp, #16
.cfi_def_cfa_offset 16
mov w8, w0
add w0, w0, w1
stp w1, w8, [sp, #8]
add sp, sp, #16
ret
.cfi_endproc
; -- End function
.globl _distance ; -- Begin function distance
.p2align 2
_distance: ; @distance
.cfi_startproc
; %bb.0: ; %entry
sub sp, sp, #48
stp x20, x19, [sp, #16] ; 16-byte Folded Spill
stp x29, x30, [sp, #32] ; 16-byte Folded Spill
.cfi_def_cfa_offset 48
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w19, -24
.cfi_offset w20, -32
sub w8, w0, w2
stp w0, w1, [sp, #8]
mov w0, w8
stp w2, w3, [sp]
bl _square
ldr w8, [sp, #12]
mov w19, w0
ldr w9, [sp, #4]
sub w0, w8, w9
bl _square
add w0, w19, w0
ldp x29, x30, [sp, #32] ; 16-byte Folded Reload
ldp x20, x19, [sp, #16] ; 16-byte Folded Reload
add sp, sp, #48
ret
.cfi_endproc
; -- End function
.globl _main ; -- Begin function main
.p2align 2
_main: ; @main
.cfi_startproc
; %bb.0: ; %entry
sub sp, sp, #96
stp x22, x21, [sp, #48] ; 16-byte Folded Spill
stp x20, x19, [sp, #64] ; 16-byte Folded Spill
stp x29, x30, [sp, #80] ; 16-byte Folded Spill
.cfi_def_cfa_offset 96
.cfi_offset w30, -8
.cfi_offset w29, -16
.cfi_offset w19, -24
.cfi_offset w20, -32
.cfi_offset w21, -40
.cfi_offset w22, -48
mov x8, #1
mov x9, #3
movk x8, #2, lsl #32
movk x9, #4, lsl #32
mov w0, #1
mov w1, #2
mov w2, #3
mov w3, #4
stp x9, x8, [sp, #32]
bl _distance
mov w19, w0
str w0, [sp, #28]
Lloh0:
adrp x0, l_.strliteral@PAGE
Lloh1:
add x0, x0, l_.strliteral@PAGEOFF
bl _printf
Lloh2:
adrp x20, l_fmt.int@PAGE
str x19, [sp]
Lloh3:
add x20, x20, l_fmt.int@PAGEOFF
mov x0, x20
bl _printf
Lloh4:
adrp x19, l_newline@PAGE
Lloh5:
add x19, x19, l_newline@PAGEOFF
mov x0, x19
bl _printf
ldp w0, w1, [sp, #40]
ldp w2, w3, [sp, #32]
stp w0, w1, [sp, #8]
stp w2, w3, [sp, #16]
bl _distance
mov w21, w0
Lloh6:
adrp x0, l_.strliteral.1@PAGE
Lloh7:
add x0, x0, l_.strliteral.1@PAGEOFF
bl _printf
mov x0, x20
str x21, [sp]
bl _printf
mov x0, x19
bl _printf
ldp x29, x30, [sp, #80] ; 16-byte Folded Reload
ldp x20, x19, [sp, #64] ; 16-byte Folded Reload
ldp x22, x21, [sp, #48] ; 16-byte Folded Reload
add sp, sp, #96
ret
.loh AdrpAdd Lloh6, Lloh7
.loh AdrpAdd Lloh4, Lloh5
.loh AdrpAdd Lloh2, Lloh3
.loh AdrpAdd Lloh0, Lloh1
.cfi_endproc
; -- End function
.section __TEXT,__cstring,cstring_literals
l_.strliteral: ; @.strliteral
.asciz "Distance between p1 and p2: "

l_fmt.int: ; @fmt.int
.asciz "%d"

l_newline: ; @newline
.asciz "\n"

l_.strliteral.1: ; @.strliteral.1
.asciz "Distance between l.p1 and l.p2: "

.subsections_via_symbols
Binary file added examples/test_3
Binary file not shown.
31 changes: 31 additions & 0 deletions examples/test_3.gom
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import io;

// tuple
type HttpResponse = { int, bool };


fn process_http(url: str): HttpResponse {
if(url == "http://www.example.com") {
return { 200, true };
}

return { 401, false };
}

fn process_http_retry(url: str, retries: int): HttpResponse {
let i = 0;
for(i = retries; i > 0; i = i - 1) {
io.log("Round: ", retries - i + 1);
let resp = process_http(url);
if(resp.1) {
return resp;
}
}

return { 500, false };
}

fn main() {
let resp = process_http_retry("http://www.example.com", 10);
io.log("Status: ", resp.0, " Success: ", resp.1);
}
115 changes: 115 additions & 0 deletions examples/test_3.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
; ModuleID = 'mod'
source_filename = "mod"

@.strliteral = private unnamed_addr constant [23 x i8] c"http://www.example.com\00", align 1
@.strliteral.1 = private unnamed_addr constant [8 x i8] c"Round: \00", align 1
@fmt.int = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@newline = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@.strliteral.2 = private unnamed_addr constant [23 x i8] c"http://www.example.com\00", align 1
@.strliteral.3 = private unnamed_addr constant [9 x i8] c"Status: \00", align 1
@.strliteral.4 = private unnamed_addr constant [11 x i8] c" Success: \00", align 1
@fmt.bool = private unnamed_addr constant [3 x i8] c"%d\00", align 1

declare i32 @printf(i8*, ...)

define void @process_http({ i32, i1 }* "noalias" "sret" %0, i8* %1) {
entry:
%2 = alloca i8*, align 8
store i8* %1, i8** %2, align 8
%url.load = load i8*, i8** %2, align 8
%eqtmp = icmp eq i8* %url.load, getelementptr inbounds ([23 x i8], [23 x i8]* @.strliteral, i32 0, i32 0)
br i1 %eqtmp, label %then, label %else

then: ; preds = %entry
%fieldptr = getelementptr { i32, i1 }, { i32, i1 }* %0, i32 0, i32 0
store i32 200, i32* %fieldptr, align 4
%fieldptr1 = getelementptr { i32, i1 }, { i32, i1 }* %0, i32 0, i32 1
store i1 true, i1* %fieldptr1, align 1
ret void
br label %merge

else: ; preds = %entry
br label %merge

merge: ; preds = %else, %then
%fieldptr2 = getelementptr { i32, i1 }, { i32, i1 }* %0, i32 0, i32 0
store i32 401, i32* %fieldptr2, align 4
%fieldptr3 = getelementptr { i32, i1 }, { i32, i1 }* %0, i32 0, i32 1
store i1 false, i1* %fieldptr3, align 1
ret void
}

define void @process_http_retry({ i32, i1 }* "noalias" "sret" %0, i8* %1, i32 %2) {
entry:
%3 = alloca i8*, align 8
store i8* %1, i8** %3, align 8
%4 = alloca i32, align 4
store i32 %2, i32* %4, align 4
%i = alloca i32, align 4
store i32 0, i32* %i, align 4
store i32 0, i32* %i, align 4
%retries.load = load i32, i32* %4, align 4
store i32 %retries.load, i32* %i, align 4
br label %loop

loop: ; preds = %loopupdate, %entry
%i.load = load i32, i32* %i, align 4
%gttmp = icmp sgt i32 %i.load, 0
br i1 %gttmp, label %loopbody, label %afterloop

loopbody: ; preds = %loop
%retries.load1 = load i32, i32* %4, align 4
%i.load2 = load i32, i32* %i, align 4
%subtmp = sub i32 %retries.load1, %i.load2
%addtmp = add i32 %subtmp, 1
%calltmp0 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.strliteral.1, i32 0, i32 0))
%calltmp1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %addtmp)
%newline = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @newline, i32 0, i32 0))
%resp = alloca { i32, i1 }, align 8
%url.load = load i8*, i8** %3, align 8
call void @process_http({ i32, i1 }* %resp, i8* %url.load)
%fieldptr = getelementptr { i32, i1 }, { i32, i1 }* %resp, i32 0, i32 1
%fieldload = load i1, i1* %fieldptr, align 1
br i1 %fieldload, label %then, label %else

loopupdate: ; preds = %merge
%i.load3 = load i32, i32* %i, align 4
%subtmp4 = sub i32 %i.load3, 1
store i32 %subtmp4, i32* %i, align 4
br label %loop

afterloop: ; preds = %loop
%fieldptr5 = getelementptr { i32, i1 }, { i32, i1 }* %0, i32 0, i32 0
store i32 500, i32* %fieldptr5, align 4
%fieldptr6 = getelementptr { i32, i1 }, { i32, i1 }* %0, i32 0, i32 1
store i1 false, i1* %fieldptr6, align 1
ret void

then: ; preds = %loopbody
%resp.load = load { i32, i1 }, { i32, i1 }* %resp, align 4
store { i32, i1 } %resp.load, { i32, i1 }* %0, align 4
ret void
br label %merge

else: ; preds = %loopbody
br label %merge

merge: ; preds = %else, %then
br label %loopupdate
}

define void @main() {
entry:
%resp = alloca { i32, i1 }, align 8
call void @process_http_retry({ i32, i1 }* %resp, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.strliteral.2, i32 0, i32 0), i32 10)
%fieldptr = getelementptr { i32, i1 }, { i32, i1 }* %resp, i32 0, i32 0
%fieldload = load i32, i32* %fieldptr, align 4
%fieldptr1 = getelementptr { i32, i1 }, { i32, i1 }* %resp, i32 0, i32 1
%fieldload2 = load i1, i1* %fieldptr1, align 1
%calltmp0 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.strliteral.3, i32 0, i32 0))
%calltmp1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %fieldload)
%calltmp2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.strliteral.4, i32 0, i32 0))
%calltmp3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i32 0, i32 0), i1 %fieldload2)
%newline = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @newline, i32 0, i32 0))
ret void
}
41 changes: 37 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading