Reduced memory allocations
This commit is contained in:
parent
f4e4e49fce
commit
8b2cdfa841
@ -13,3 +13,12 @@ func (a *Assembler) Merge(b Assembler) {
|
||||
maps.Copy(a.Data, b.Data)
|
||||
a.Instructions = append(a.Instructions, b.Instructions...)
|
||||
}
|
||||
|
||||
// SetData sets the data for the given label.
|
||||
func (a *Assembler) SetData(label string, data []byte) {
|
||||
if a.Data == nil {
|
||||
a.Data = map[string][]byte{}
|
||||
}
|
||||
|
||||
a.Data[label] = data
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ func NewFunction(name string, file *fs.File, body token.List) *Function {
|
||||
state: state{
|
||||
assembler: asm.Assembler{
|
||||
Instructions: make([]asm.Instruction, 0, 32),
|
||||
Data: map[string][]byte{},
|
||||
},
|
||||
cpu: cpu.CPU{
|
||||
All: x64.AllRegisters,
|
||||
|
@ -40,8 +40,8 @@ func (f *Function) TokenToRegister(t token.Token, register cpu.Register) error {
|
||||
case token.String:
|
||||
f.count.data++
|
||||
label := fmt.Sprintf("%s_data_%d", f.Name, f.count.data)
|
||||
value := t.Text()[1 : len(t.Bytes)-1]
|
||||
f.assembler.Data[label] = []byte(value)
|
||||
value := t.Bytes[1 : len(t.Bytes)-1]
|
||||
f.assembler.SetData(label, value)
|
||||
f.RegisterLabel(asm.MOVE, register, label)
|
||||
return nil
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user