Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing arguments to the assembler #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions gecko.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type GeckoCode struct {

type GeckoSettings struct {
AreIncludesRelativeFromFile bool
AsFlags string
}

type compileResult struct {
Expand Down Expand Up @@ -102,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)
Expand All @@ -110,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(
Expand All @@ -137,19 +151,26 @@ 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 the assembler.",
)

assembleFlags.Parse(os.Args[2:])

globalSettings = GeckoSettings{AreIncludesRelativeFromFile: *irffPtr}
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 <command> [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 <command> -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")
}
Expand Down Expand Up @@ -551,15 +572,19 @@ 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)
}

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()
fmt.Printf("%s", output);
if err != nil {
fmt.Printf("Failed to compile file: %s\n", file)
fmt.Printf("%s", output)
Expand All @@ -576,8 +601,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)
Expand All @@ -587,8 +610,9 @@ func compile(file string) []byte {
log.Panicf("%s not available in $PATH. You may need to install devkitPPC", objcopyCmdLinux)
}

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()
fmt.Printf("%s", output);
if err != nil {
fmt.Printf("Failed to compile file: %s\n", file)
fmt.Printf("%s", output)
Expand Down