Implemented an assembler
All checks were successful
/ test (push) Successful in 28s

This commit is contained in:
Eduard Urbach 2025-06-24 12:55:26 +02:00
parent 2b703e9af2
commit 70c2da4a4d
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
40 changed files with 821 additions and 117 deletions

View file

@ -1,9 +1,5 @@
package ssa
import (
"git.urbach.dev/cli/q/src/cpu"
)
// IR is a list of basic blocks.
type IR struct {
Blocks []*Block
@ -44,8 +40,8 @@ func (f *IR) AppendInt(x int) *Int {
}
// AppendRegister adds a new register value to the last block.
func (f *IR) AppendRegister(reg cpu.Register) *Register {
v := &Register{Register: reg}
func (f *IR) AppendRegister(index int) *Parameter {
v := &Parameter{Index: uint8(index)}
f.Append(v)
return v
}

31
src/ssa/Parameter.go Normal file
View file

@ -0,0 +1,31 @@
package ssa
import "fmt"
type Parameter struct {
Index uint8
Liveness
HasToken
}
func (v *Parameter) Dependencies() []Value {
return nil
}
func (a *Parameter) Equals(v Value) bool {
b, sameType := v.(*Parameter)
if !sameType {
return false
}
return a.Index == b.Index
}
func (v *Parameter) IsConst() bool {
return true
}
func (v *Parameter) String() string {
return fmt.Sprintf("arg[%d]", v.Index)
}

View file

@ -1,31 +0,0 @@
package ssa
import "git.urbach.dev/cli/q/src/cpu"
type Register struct {
Register cpu.Register
Liveness
HasToken
}
func (v *Register) Dependencies() []Value {
return nil
}
func (a *Register) Equals(v Value) bool {
b, sameType := v.(*Register)
if !sameType {
return false
}
return a.Register == b.Register
}
func (v *Register) IsConst() bool {
return true
}
func (v *Register) String() string {
return v.Register.String()
}