summaryrefslogtreecommitdiff
path: root/tnslc/compile
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-10-09 01:47:02 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-10-09 01:47:02 -0400
commit82bddb5aa27873695d22a5af9150a6c763c6351b (patch)
tree8ee0e7ecd1c7499c3f27ffa9d951df7f53775dcd /tnslc/compile
parent34bfedcd1e5e67b630fb7648cf7709d4a400abc5 (diff)
Registry name generation
Diffstat (limited to 'tnslc/compile')
-rw-r--r--tnslc/compile/compile.tnsl12
-rw-r--r--tnslc/compile/isa_x86.tnsl124
2 files changed, 135 insertions, 1 deletions
diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl
index 80656e4..6bfa07e 100644
--- a/tnslc/compile/compile.tnsl
+++ b/tnslc/compile/compile.tnsl
@@ -15,10 +15,12 @@
#/
/; module compile
+
# :include "compile/arch/arch.tnsl"
# :include "compile/comp.tnsl"
;/
+:include "isa_x86.tnsl"
;{}{}charp COMMON_ASM = {
"\tret",
@@ -57,7 +59,17 @@
/; index_to_loc (int index, ~VTrack tab) [{}charp]
;{}charp out = ""
+ ;int stack_bytes = 0
+ ;int reg = 0
+ ;int i = 0
+ /; loop (i < index) [i++]
+ /; if (tab`.sym_types{i}._size <= 8 && reg < 7)
+ ;reg++
+ ;; else
+ ;stack_bytes = stack_bytes + tab`.sym_types{i}._size
+ ;/
+ ;/
;/
diff --git a/tnslc/compile/isa_x86.tnsl b/tnslc/compile/isa_x86.tnsl
index 664108f..1dff3f7 100644
--- a/tnslc/compile/isa_x86.tnsl
+++ b/tnslc/compile/isa_x86.tnsl
@@ -14,6 +14,128 @@
EXPRESS OR IMPLIED
#/
-/; add_asm
+/; push_asm ({}charp reg) [{}charp]
+ ;{}charp out = "\tpush "
+ ;add_strings(~out, ~reg)
+ ;out.append('\n')
+ ;return out
+;/
+/; pop_asm ({}charp reg) [{}charp]
+ ;{}charp out = "\tpop "
+ ;add_strings(~out, ~reg)
+ ;out.append('\n')
+ ;return out
+;/
+
+/; header_guard [{}charp]
+ ;{}charp out = "", tmp = ""
+ ;tmp = push_asm("%r8")
+ ;add_strings(~out, ~tmp)
+ ;tmp = push_asm("%r9")
+ ;add_strings(~out, ~tmp)
+ ;tmp = push_asm("%r10")
+ ;add_strings(~out, ~tmp)
+ ;tmp = push_asm("%r11")
+ ;add_strings(~out, ~tmp)
+ ;tmp = push_asm("%r12")
+ ;add_strings(~out, ~tmp)
+ ;tmp = push_asm("%r13")
+ ;add_strings(~out, ~tmp)
+ ;tmp = push_asm("%r14")
+ ;add_strings(~out, ~tmp)
+ ;tmp = push_asm("%r15")
+ ;add_strings(~out, ~tmp)
+ ;return out
+;/
+
+/; tail_guard [{}charp]
+ ;{}charp out = "", tmp = ""
+ ;tmp = pop_asm("%r15")
+ ;add_strings(~out, ~tmp)
+ ;tmp = pop_asm("%r14")
+ ;add_strings(~out, ~tmp)
+ ;tmp = pop_asm("%r13")
+ ;add_strings(~out, ~tmp)
+ ;tmp = pop_asm("%r12")
+ ;add_strings(~out, ~tmp)
+ ;tmp = pop_asm("%r11")
+ ;add_strings(~out, ~tmp)
+ ;tmp = pop_asm("%r10")
+ ;add_strings(~out, ~tmp)
+ ;tmp = pop_asm("%r9")
+ ;add_strings(~out, ~tmp)
+ ;tmp = pop_asm("%r8")
+ ;add_strings(~out, ~tmp)
+ ;return out
+;/
+
+/# Accepted common names:
+# - ax
+# - bx
+# - cx
+# - dx
+# - sp
+# - bp
+# - si
+# - di
+# - 8-15
+#/
+/; get_reg (uint size, {}charp common) [{}charp]
+ ;{}charp out = "%"
+
+ /; if (string_equate(common, "ax") || string_equate(common, "bx") || string_equate(common, "cx") || string_equate(common, "dx"))
+
+ /; if (size == 1)
+ common{1} = 'l'
+ ;; else if (size == 4)
+ ;out.append('e')
+ ;; else if (size == 8)
+ ;out.append('r')
+ ;/
+
+ ;add_strings(~out, ~common)
+
+ ;; else if (string_equate(common, "sp") || string_equate(common, "bp") || string_equate(common, "si") || string_equate(common, "di"))
+
+ /; if (size == 1)
+ ;common.append('l')
+ ;; else if (size == 4)
+ ;out.append('e')
+ ;; else if (size == 8)
+ ;out.append('r')
+ ;/
+
+ ;add_strings(~out, ~common)
+
+ ;; else
+
+ ;{}charp out = "r"
+ ;add_strings(~out, ~common)
+ /; if (size == 1)
+ ;out.append('b')
+ ;; else if (size == 2)
+ ;out.append('w')
+ ;; else if (size == 4)
+ ;out.append('d')
+ ;/
+ ;return out
+ ;/
+
+ ;return out
+;/
+
+/; literal_num ({}charp num) [{}charp]
+ ;{}charp out = "$"
+ ;add_strings(~out, ~num)
+ ;return out
+;/
+
+/; add_asm ({}charp from, to) [{}charp]
+ ;{}charp out = "\tadd "
+ ;add_strings(~out, ~from)
+ ;out.append(',')
+ ;out.append(' ')
+ ;add_strings(~out, ~to)
+ ;
;/ \ No newline at end of file