From 55d1d7656e4a4d80abf5241c4ce5472141be8150 Mon Sep 17 00:00:00 2001 From: abgr Date: Sat, 27 Nov 2021 17:51:16 +0330 Subject: [PATCH 1/3] ignore undefined functions --- arguments.go | 5 +++-- c2goasm.go | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arguments.go b/arguments.go index ea310ea..cd517d0 100644 --- a/arguments.go +++ b/arguments.go @@ -19,6 +19,7 @@ package main import ( "errors" "fmt" + "log" "regexp" "strconv" "strings" @@ -71,8 +72,8 @@ func parseCompanionFile(goCompanion, protoName string) ([]string, []string) { return args, rets } } - - panic(fmt.Sprintf("Failed to find function prototype for %s", protoName)) + log.Printf("Failed to find function prototype for %s", protoName) + return nil, nil } var regexpFuncAndArgs = regexp.MustCompile(`^\s*func\s+([^\(]*)\(([^\)]*)\)(.*)`) diff --git a/c2goasm.go b/c2goasm.go index 84ba554..eb252a1 100644 --- a/c2goasm.go +++ b/c2goasm.go @@ -85,6 +85,9 @@ func process(assembly []string, goCompanionFile string) ([]string, error) { for isubroutine, sub := range subroutines { golangArgs, golangReturns := parseCompanionFile(goCompanionFile, sub.name) + if golangArgs == nil && golangReturns == nil { + continue + } stackArgs := argumentsOnStack(sub.body) if len(golangArgs) > 6 && len(golangArgs)-6 < stackArgs.Number { panic(fmt.Sprintf("Found too few arguments on stack (%d) but needed %d", len(golangArgs)-6, stackArgs.Number)) From 5151a28bedd0611b7671c154558551000fb5b90f Mon Sep 17 00:00:00 2001 From: abgr Date: Sat, 27 Nov 2021 17:55:03 +0330 Subject: [PATCH 2/3] make ignoring undefined symbols optional by cmd arg -u --- c2goasm.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/c2goasm.go b/c2goasm.go index eb252a1..a8a66d7 100644 --- a/c2goasm.go +++ b/c2goasm.go @@ -30,6 +30,7 @@ import ( var ( assembleFlag = flag.Bool("a", false, "Immediately invoke asm2plan9s") + allowUndef = flag.Bool("u", false, "allow undefined symbols") stripFlag = flag.Bool("s", false, "Strip comments") compactFlag = flag.Bool("c", false, "Compact byte codes") formatFlag = flag.Bool("f", false, "Format using asmfmt") @@ -86,7 +87,10 @@ func process(assembly []string, goCompanionFile string) ([]string, error) { golangArgs, golangReturns := parseCompanionFile(goCompanionFile, sub.name) if golangArgs == nil && golangReturns == nil { - continue + if *allowUndef { + continue + } + panic(fmt.Sprintf("Failed to find function prototype for %s\n", sub.name)) } stackArgs := argumentsOnStack(sub.body) if len(golangArgs) > 6 && len(golangArgs)-6 < stackArgs.Number { From fcf4f15430490a7ae1406e05806366ca25666f0b Mon Sep 17 00:00:00 2001 From: abgr Date: Sat, 27 Nov 2021 18:01:21 +0330 Subject: [PATCH 3/3] impr readability --- arguments.go | 2 -- c2goasm.go | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arguments.go b/arguments.go index cd517d0..730216d 100644 --- a/arguments.go +++ b/arguments.go @@ -19,7 +19,6 @@ package main import ( "errors" "fmt" - "log" "regexp" "strconv" "strings" @@ -72,7 +71,6 @@ func parseCompanionFile(goCompanion, protoName string) ([]string, []string) { return args, rets } } - log.Printf("Failed to find function prototype for %s", protoName) return nil, nil } diff --git a/c2goasm.go b/c2goasm.go index a8a66d7..0e318d1 100644 --- a/c2goasm.go +++ b/c2goasm.go @@ -88,6 +88,7 @@ func process(assembly []string, goCompanionFile string) ([]string, error) { golangArgs, golangReturns := parseCompanionFile(goCompanionFile, sub.name) if golangArgs == nil && golangReturns == nil { if *allowUndef { + log.Printf("Failed to find function prototype for %s", sub.name) continue } panic(fmt.Sprintf("Failed to find function prototype for %s\n", sub.name))