This commit is contained in:
parent
c9c6b94c18
commit
3301cf5542
49 changed files with 690 additions and 262 deletions
|
@ -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())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue