From 4dd40f6fecc9ae0b4f02e61f03f79826c5119241 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 10 Feb 2025 17:17:59 +0100 Subject: [PATCH] Added number of used functions to the statistics --- src/compiler/Result.go | 23 ++++++++++++++++++++--- src/core/PrintInstructions.go | 4 ++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/compiler/Result.go b/src/compiler/Result.go index 0788a36..9ca52e4 100644 --- a/src/compiler/Result.go +++ b/src/compiler/Result.go @@ -22,6 +22,7 @@ import ( type Result struct { Main *core.Function Functions map[string]*core.Function + Traversed map[*core.Function]bool InstructionCount int DataCount int Code []byte @@ -60,9 +61,11 @@ func (r *Result) finalize() { {Name: "kernel32", Functions: []string{"ExitProcess"}}, } + r.Traversed = make(map[*core.Function]bool, len(r.Functions)) + // This will place the main function immediately after the entry point // and also add everything the main function calls recursively. - r.eachFunction(r.Main, map[*core.Function]bool{}, func(f *core.Function) { + r.eachFunction(r.Main, r.Traversed, func(f *core.Function) { final.Merge(f.Assembler) for _, library := range f.DLLs { @@ -127,8 +130,22 @@ func (r *Result) PrintInstructions() { // PrintStatistics shows the statistics. func (r *Result) PrintStatistics() { ansi.Dim.Println("╭──────────────────────────────────────────────────────────────────────────────╮") - ansi.Dim.Printf("│ %-44s%-32s │\n", "Code:", fmt.Sprintf("%d bytes", len(r.Code))) - ansi.Dim.Printf("│ %-44s%-32s │\n", "Data:", fmt.Sprintf("%d bytes", len(r.Data))) + + ansi.Dim.Print("│ ") + ansi.Dim.Printf("%-44s", "Code:") + fmt.Printf("%-32s", fmt.Sprintf("%d bytes", len(r.Code))) + ansi.Dim.Print(" │\n") + + ansi.Dim.Print("│ ") + ansi.Dim.Printf("%-44s", "Data:") + fmt.Printf("%-32s", fmt.Sprintf("%d bytes", len(r.Data))) + ansi.Dim.Print(" │\n") + + ansi.Dim.Print("│ ") + ansi.Dim.Printf("%-44s", "Functions:") + fmt.Printf("%-32s", fmt.Sprintf("%d / %d", len(r.Traversed), len(r.Functions))) + ansi.Dim.Print(" │\n") + ansi.Dim.Println("╰──────────────────────────────────────────────────────────────────────────────╯") } diff --git a/src/core/PrintInstructions.go b/src/core/PrintInstructions.go index d777ff0..3a1acf5 100644 --- a/src/core/PrintInstructions.go +++ b/src/core/PrintInstructions.go @@ -46,9 +46,9 @@ func (f *Function) PrintInstructions() { for _, reg := range f.CPU.All { if used&(1<