From 6ba60b755548c0ab749ceb214299734e034eaa6f Mon Sep 17 00:00:00 2001 From: meta Date: Sat, 13 Jul 2019 16:14:19 -0500 Subject: [PATCH 1/2] support optionally passing arguments directly to as; add -v flag for logging --- gecko.go | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/gecko.go b/gecko.go index 9295534..3d84fe3 100644 --- a/gecko.go +++ b/gecko.go @@ -50,6 +50,8 @@ type GeckoCode struct { type GeckoSettings struct { AreIncludesRelativeFromFile bool + AsFlags string + Verbose bool } type compileResult struct { @@ -137,9 +139,19 @@ func main() { "project from more than one location. Setting this to true adds a pre-processing step where "+ "include statements are translated to make them be relative from the file's location.", ) + asFlagsPtr := assembleFlags.String( + "asflags", + "", + "A string of additional arguments to-be-passed to `as`.", + ) + isVerbosePtr := assembleFlags.Bool( + "v", + false, + "Enable verbose output. Writes debug/logging information to stdout.", + ) assembleFlags.Parse(os.Args[2:]) - globalSettings = GeckoSettings{AreIncludesRelativeFromFile: *irffPtr} + globalSettings = GeckoSettings{AreIncludesRelativeFromFile: *irffPtr, AsFlags: *asFlagsPtr, Verbose: *isVerbosePtr} outputFiles = append(outputFiles, FileDetails{File: *outputFilePtr}) output = generateInjectionFolderLines(*assemblePathPtr, *isRecursivePtr) case "-h": @@ -551,14 +563,20 @@ func compile(file string) []byte { // instruction is ignored and not compiled buildTempAsmFile(file, compileFilePath) + const asCmdWin = "powerpc-gekko-as.exe" + const asCmdLinux string = "powerpc-eabi-as" + const objcopyCmdLinux string = "powerpc-eabi-objcopy" + if runtime.GOOS == "windows" { - const asCmdWin = "powerpc-gekko-as.exe" _, err := exec.LookPath(asCmdWin) if err != nil { log.Panicf("%s not available in $PATH", asCmdWin) } + if globalSettings.Verbose { + fmt.Println("[*] Executing", asCmdWin, compileFilePath, "-a32 -mbig -mregnames -mgekko", globalSettings.AsFlags, "-o", outputFilePath) + } - cmd := exec.Command(asCmdWin, "-a32", "-mbig", "-mregnames", "-mgekko", "-o", outputFilePath, compileFilePath) + cmd := exec.Command(asCmdWin, compileFilePath, "-a32", "-mbig", "-mregnames", "-mgekko", globalSettings.AsFlags, "-o", outputFilePath) output, err := cmd.CombinedOutput() if err != nil { fmt.Printf("Failed to compile file: %s\n", file) @@ -576,8 +594,6 @@ func compile(file string) []byte { } if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { - const asCmdLinux string = "powerpc-eabi-as" - const objcopyCmdLinux string = "powerpc-eabi-objcopy" _, err := exec.LookPath(asCmdLinux) if err != nil { log.Panicf("%s not available in $PATH. You may need to install devkitPPC", asCmdLinux) @@ -586,8 +602,11 @@ func compile(file string) []byte { if err != nil { log.Panicf("%s not available in $PATH. You may need to install devkitPPC", objcopyCmdLinux) } + if globalSettings.Verbose { + fmt.Println("[*] Executing", asCmdLinux, compileFilePath, "-a32 -mbig -mregnames -mgekko", globalSettings.AsFlags, "-o", outputFilePath) + } - cmd := exec.Command(asCmdLinux, "-a32", "-mbig", "-mregnames", "-o", outputFilePath, compileFilePath) + cmd := exec.Command(asCmdLinux, compileFilePath, "-a32", "-mbig", "-mregnames", globalSettings.AsFlags, "-o", outputFilePath) output, err := cmd.CombinedOutput() if err != nil { fmt.Printf("Failed to compile file: %s\n", file) From f23576a6adfd32d557514faedb37ec2b67c51d57 Mon Sep 17 00:00:00 2001 From: meta Date: Sat, 13 Jul 2019 23:42:52 -0500 Subject: [PATCH 2/2] fix --asflags, print assembler output by default --- gecko.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/gecko.go b/gecko.go index 3d84fe3..8f296ff 100644 --- a/gecko.go +++ b/gecko.go @@ -51,7 +51,6 @@ type GeckoCode struct { type GeckoSettings struct { AreIncludesRelativeFromFile bool AsFlags string - Verbose bool } type compileResult struct { @@ -104,6 +103,12 @@ func main() { "codes.json", "Used to specify a path to a config file.", ) + asFlagsPtr := buildFlags.String( + "asflags", + "", + "A string of additional arguments to-be-passed to the assembler (takes precedence over config file).", + ) + buildFlags.Parse(os.Args[2:]) config := readConfigFile(*configFilePathPtr) @@ -112,8 +117,15 @@ func main() { } globalSettings = config.Settings + + // Let command-line arguments take precedence over settings in the configuration file + if (len(*asFlagsPtr) > 0) { + globalSettings.AsFlags = *asFlagsPtr + } + buildBody(config) outputFiles = config.OutputFiles + case "assemble": assembleFlags := flag.NewFlagSet("assemble", flag.ExitOnError) outputFilePtr := assembleFlags.String( @@ -142,26 +154,23 @@ func main() { asFlagsPtr := assembleFlags.String( "asflags", "", - "A string of additional arguments to-be-passed to `as`.", - ) - isVerbosePtr := assembleFlags.Bool( - "v", - false, - "Enable verbose output. Writes debug/logging information to stdout.", + "A string of additional arguments to-be-passed to the assembler.", ) + assembleFlags.Parse(os.Args[2:]) - globalSettings = GeckoSettings{AreIncludesRelativeFromFile: *irffPtr, AsFlags: *asFlagsPtr, Verbose: *isVerbosePtr} + globalSettings = GeckoSettings{AreIncludesRelativeFromFile: *irffPtr, AsFlags: *asFlagsPtr} outputFiles = append(outputFiles, FileDetails{File: *outputFilePtr}) output = generateInjectionFolderLines(*assemblePathPtr, *isRecursivePtr) + case "-h": - // Print help information fmt.Print("Usage: gecko [flags]\n\n") fmt.Println("Supported commands:") fmt.Println("\tbuild - Uses a configuration file to build codes. Recommended for larger projects.") fmt.Print("\tassemble - Assembles asm files in a given directory.\n\n") fmt.Println("Use gecko -h for information about the flags for the different commands") os.Exit(1) + default: log.Panic("Currently only the build and assemble commands are supported. Try typing 'gecko build'\n") } @@ -572,12 +581,10 @@ func compile(file string) []byte { if err != nil { log.Panicf("%s not available in $PATH", asCmdWin) } - if globalSettings.Verbose { - fmt.Println("[*] Executing", asCmdWin, compileFilePath, "-a32 -mbig -mregnames -mgekko", globalSettings.AsFlags, "-o", outputFilePath) - } cmd := exec.Command(asCmdWin, compileFilePath, "-a32", "-mbig", "-mregnames", "-mgekko", globalSettings.AsFlags, "-o", outputFilePath) output, err := cmd.CombinedOutput() + fmt.Printf("%s", output); if err != nil { fmt.Printf("Failed to compile file: %s\n", file) fmt.Printf("%s", output) @@ -602,12 +609,10 @@ func compile(file string) []byte { if err != nil { log.Panicf("%s not available in $PATH. You may need to install devkitPPC", objcopyCmdLinux) } - if globalSettings.Verbose { - fmt.Println("[*] Executing", asCmdLinux, compileFilePath, "-a32 -mbig -mregnames -mgekko", globalSettings.AsFlags, "-o", outputFilePath) - } cmd := exec.Command(asCmdLinux, compileFilePath, "-a32", "-mbig", "-mregnames", globalSettings.AsFlags, "-o", outputFilePath) output, err := cmd.CombinedOutput() + fmt.Printf("%s", output); if err != nil { fmt.Printf("Failed to compile file: %s\n", file) fmt.Printf("%s", output)