..
This commit is contained in:
79
examples/array/.build/out.asm
Normal file
79
examples/array/.build/out.asm
Normal file
@@ -0,0 +1,79 @@
|
||||
.text
|
||||
.cstring_len:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $0, %eax
|
||||
.Lbb2:
|
||||
movzbl (%rdi, %rax, 1), %ecx
|
||||
cmpl $0, %ecx
|
||||
jz .Lbb4
|
||||
addq $1, %rax
|
||||
jmp .Lbb2
|
||||
.Lbb4:
|
||||
leave
|
||||
ret
|
||||
.type .cstring_len, @function
|
||||
.size .cstring_len, .-.cstring_len
|
||||
/* end function .cstring_len */
|
||||
|
||||
.text
|
||||
.memcpy:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $0, %eax
|
||||
.Lbb7:
|
||||
cmpq %rdx, %rax
|
||||
jae .Lbb9
|
||||
movzbl (%rdi, %rax, 1), %ecx
|
||||
movb %cl, (%rsi, %rax, 1)
|
||||
addq $1, %rax
|
||||
jmp .Lbb7
|
||||
.Lbb9:
|
||||
leave
|
||||
ret
|
||||
.type .memcpy, @function
|
||||
.size .memcpy, .-.memcpy
|
||||
/* end function .memcpy */
|
||||
|
||||
.text
|
||||
.memset:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $0, %eax
|
||||
.Lbb12:
|
||||
cmpq %rdx, %rax
|
||||
jae .Lbb14
|
||||
movb %sil, (%rdi, %rax, 1)
|
||||
addq $1, %rax
|
||||
jmp .Lbb12
|
||||
.Lbb14:
|
||||
leave
|
||||
ret
|
||||
.type .memset, @function
|
||||
.size .memset, .-.memset
|
||||
/* end function .memset */
|
||||
|
||||
.text
|
||||
.array_size:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movq (%rdi), %rax
|
||||
leave
|
||||
ret
|
||||
.type .array_size, @function
|
||||
.size .array_size, .-.array_size
|
||||
/* end function .array_size */
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $0, %eax
|
||||
leave
|
||||
ret
|
||||
.type main, @function
|
||||
.size main, .-main
|
||||
/* end function main */
|
||||
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
BIN
examples/array/.build/out.o
Normal file
BIN
examples/array/.build/out.o
Normal file
Binary file not shown.
65
examples/array/.build/out.ssa
Normal file
65
examples/array/.build/out.ssa
Normal file
@@ -0,0 +1,65 @@
|
||||
# ========== Builtin functions ==========
|
||||
function l $.cstring_len(l %str) {
|
||||
@start
|
||||
%count =l copy 0
|
||||
@loop
|
||||
%address =l add %str, %count
|
||||
%value =w loadub %address
|
||||
jnz %value, @continue, @end
|
||||
@continue
|
||||
%count =l add %count, 1
|
||||
jmp @loop
|
||||
@end
|
||||
ret %count
|
||||
}
|
||||
|
||||
function $.memcpy(l %source, l %destination, l %length) {
|
||||
@start
|
||||
%count =l copy 0
|
||||
@loop
|
||||
%condition =w cultl %count, %length
|
||||
jnz %condition, @continue, @end
|
||||
@continue
|
||||
%source_address =l add %source, %count
|
||||
%destination_address =l add %destination, %count
|
||||
%value =w loadub %source_address
|
||||
storeb %value, %destination_address
|
||||
%count =l add %count, 1
|
||||
jmp @loop
|
||||
@end
|
||||
ret
|
||||
}
|
||||
|
||||
function $.memset(l %destination, l %value, l %length) {
|
||||
@start
|
||||
%count =l copy 0
|
||||
@loop
|
||||
%condition =w cultl %count, %length
|
||||
jnz %condition, @continue, @end
|
||||
@continue
|
||||
%destination_address =l add %destination, %count
|
||||
storeb %value, %destination_address
|
||||
%count =l add %count, 1
|
||||
jmp @loop
|
||||
@end
|
||||
ret
|
||||
}
|
||||
|
||||
function l $.array_size(l %array) {
|
||||
@start
|
||||
%size =l loadl %array
|
||||
ret %size
|
||||
}
|
||||
|
||||
# ========== Referenced structs ==========
|
||||
|
||||
# ========== Struct definitions ==========
|
||||
# ========== Function definitions ==========
|
||||
export function l $main(l %args) {
|
||||
@start
|
||||
ret 0
|
||||
}
|
||||
|
||||
# ========== cstring literals ==========
|
||||
|
||||
# ========== string literals ==========
|
||||
6
examples/array/main.nub
Normal file
6
examples/array/main.nub
Normal file
@@ -0,0 +1,6 @@
|
||||
module "main"
|
||||
|
||||
extern "main" func main(args: []cstring): i64
|
||||
{
|
||||
return 0
|
||||
}
|
||||
15
examples/array/makefile
Normal file
15
examples/array/makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
NUBC = ../../compiler/NubLang.CLI/bin/Debug/net9.0/nubc
|
||||
|
||||
out: .build/out.o
|
||||
gcc -nostartfiles -o out x86_64.s .build/out.o
|
||||
|
||||
.build/out.o: $(NUBC) main.nub
|
||||
$(NUBC) main.nub
|
||||
|
||||
.PHONY: $(NUBC)
|
||||
$(NUBC):
|
||||
dotnet build ../../compiler/NubLang.CLI/NubLang.CLI.csproj
|
||||
|
||||
clean:
|
||||
@rm -r .build 2>/dev/null || true
|
||||
@rm out 2>/dev/null || true
|
||||
BIN
examples/array/out
Executable file
BIN
examples/array/out
Executable file
Binary file not shown.
10
examples/array/x86_64.s
Normal file
10
examples/array/x86_64.s
Normal file
@@ -0,0 +1,10 @@
|
||||
.intel_syntax noprefix
|
||||
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
mov rdi, rsp
|
||||
call main
|
||||
mov rdi, rax
|
||||
mov rax, 60
|
||||
syscall
|
||||
@@ -1,4 +1,3 @@
|
||||
import "core"
|
||||
import "raylib"
|
||||
|
||||
module "main"
|
||||
|
||||
Reference in New Issue
Block a user