Implemented dead code elimination

This commit is contained in:
Eduard Urbach 2024-06-27 17:36:45 +02:00
parent 10d195d286
commit 8beed6dd21
Signed by: eduard
GPG key ID: 49226B848C78F6C8
7 changed files with 51 additions and 17 deletions

View file

@ -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)
}