Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455package codegen
import ( "slices"
"git.urbach.dev/cli/q/src/asm" "git.urbach.dev/cli/q/src/ssa" "git.urbach.dev/cli/q/src/types")
func (f *Function) executeLoad(step *Step, instr *ssa.Load) { if step.Register == -1 { return }
memory := instr.Memory address := f.ValueToStep[memory.Address] index := f.ValueToStep[memory.Index] elementType := step.Value.Type() elementSize := elementType.Size() live := slices.Concat(step.Live, []*Step{address, index}) baseRegister := f.resolveOperand(address, live) indexRegister := f.resolveOperand(index, live, baseRegister) destination := step.Register isSpilled := f.isSpilled(destination)
if isSpilled { destination = f.findTempRegister(live, baseRegister, indexRegister) }
if index.Register == -1 { fixedOffset := index.Value.(*ssa.Int).Int f.Assembler.Append(&asm.LoadFixedOffset{ Base: baseRegister, Index: fixedOffset, Destination: destination, Scale: memory.Scale, Length: byte(elementSize), Signed: types.IsSigned(elementType), }) } else { f.Assembler.Append(&asm.Load{ Base: baseRegister, Index: indexRegister, Destination: destination, Scale: memory.Scale, Length: byte(elementSize), Signed: types.IsSigned(elementType), }) }
if isSpilled { f.storeSpill(step, destination) }}