Implemented dead code elimination
This commit is contained in:
@ -8,7 +8,8 @@ import (
|
||||
|
||||
// Result contains all the compiled functions in a build.
|
||||
type Result struct {
|
||||
Functions map[string]*Function
|
||||
Used []*Function
|
||||
Unused map[string]*Function
|
||||
instructionCount int
|
||||
}
|
||||
|
||||
@ -27,13 +28,8 @@ func (r Result) Finalize() ([]byte, []byte) {
|
||||
final.RegisterNumber(asm.MOVE, x64.SyscallRegisters[1], 0)
|
||||
final.Syscall()
|
||||
|
||||
// Place the `main` function immediately after the entry point.
|
||||
main := r.Functions["main"]
|
||||
delete(r.Functions, "main")
|
||||
final.Merge(&main.Assembler)
|
||||
|
||||
// Merge all the remaining functions.
|
||||
for _, f := range r.Functions {
|
||||
// Merge all the called functions.
|
||||
for _, f := range r.Used {
|
||||
final.Merge(&f.Assembler)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user