Improved ssa compiler
All checks were successful
/ test (push) Successful in 15s

This commit is contained in:
Eduard Urbach 2025-07-02 16:55:24 +02:00
parent c9c6b94c18
commit 3301cf5542
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
49 changed files with 690 additions and 262 deletions

View file

@ -1,48 +1,24 @@
package core
import (
"git.urbach.dev/cli/q/src/ssa"
"git.urbach.dev/cli/q/src/types"
)
import "git.urbach.dev/cli/q/src/types"
// Compile turns a function into machine code.
func (f *Function) Compile() {
extra := 0
offset := 0
for i, input := range f.Input {
if input.Name == "_" {
continue
}
array, isArray := input.Typ.(*types.Array)
if isArray {
pointer := &ssa.Parameter{
Index: uint8(i + extra),
Name: input.Name,
Typ: &types.Pointer{To: array.Of},
Source: input.Source,
}
f.Append(pointer)
f.Identifiers[pointer.Name] = pointer
extra++
length := &ssa.Parameter{
Index: uint8(i + extra),
Name: input.Name + ".len",
Typ: types.AnyInt,
Source: input.Source,
}
f.Append(length)
f.Identifiers[length.Name] = length
continue
}
input.Index = uint8(i + extra)
input.Index = uint8(offset + i)
f.Append(input)
f.Identifiers[input.Name] = input
structure, isStruct := input.Typ.(*types.Struct)
if isStruct {
offset += len(structure.Fields) - 1
}
}
for instr := range f.Body.Instructions {
@ -59,5 +35,5 @@ func (f *Function) Compile() {
return
}
f.ssaToAsm()
f.GenerateAssembly(f.IR, f.IsLeaf())
}