-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCompileToAssembly.go
More file actions
39 lines (31 loc) · 873 Bytes
/
Copy pathCompileToAssembly.go
File metadata and controls
39 lines (31 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package codegen
import (
"slices"
"git.urbach.dev/cli/q/src/config"
"git.urbach.dev/cli/q/src/ssa"
)
// CompileToAssembly converts the SSA IR to assembler instructions.
func (f *Function) CompileToAssembly(ir ssa.IR, build *config.Build, hasStackFrame bool, hasExternCalls bool) {
f.hasStackFrame = hasStackFrame
f.hasExternCalls = hasExternCalls
f.needsFramePointer = (hasStackFrame || hasExternCalls) && !f.IsExit
f.build = build
f.IR = createSteps(ir)
for _, step := range slices.Backward(f.Steps) {
f.hintABI(step)
f.createLiveRanges(step)
}
for _, step := range slices.Backward(f.Steps) {
if step.Register == -1 && f.needsRegister(step) {
f.assignFreeRegister(step)
}
f.hintDestination(step)
}
f.reorderParameters()
f.fixRegisterConflicts()
f.addPreservedRegisters()
f.enter()
for _, step := range f.Steps {
f.execute(step)
}
}