Compiler now takes in a format override parameter
This commit is contained in:
parent
ea0f2ca169
commit
203fb4fca4
|
@ -15,6 +15,7 @@ import "git.tebibyte.media/sashakoshka/fspl/generator/native"
|
|||
type Compiler struct {
|
||||
Output string
|
||||
Optimization string
|
||||
Format string
|
||||
}
|
||||
|
||||
func (this *Compiler) Compile (inputs []string) error {
|
||||
|
@ -39,14 +40,23 @@ func (this *Compiler) Compile (inputs []string) error {
|
|||
return errors.New(fmt.Sprintf("internal errror: %v", err))
|
||||
}
|
||||
|
||||
// if the format isn't specified, try to get it from the filename
|
||||
// extension of the input. if that isn't specified, default to .o
|
||||
if this.Format == "" {
|
||||
this.Format = filepath.Ext(this.Output)
|
||||
}
|
||||
if this.Format == "" {
|
||||
this.Format = ".o"
|
||||
}
|
||||
|
||||
if this.Output == "" {
|
||||
this.Output = strings.TrimSuffix (
|
||||
inputs[0],
|
||||
filepath.Ext(inputs[0])) + ".o"
|
||||
filepath.Ext(inputs[0])) + this.Format
|
||||
}
|
||||
|
||||
extension := filepath.Ext(this.Output)
|
||||
switch extension {
|
||||
|
||||
// do something based on the output extension
|
||||
switch this.Format {
|
||||
case ".s":
|
||||
return this.CompileModule(module, "asm")
|
||||
case ".o":
|
||||
|
@ -63,7 +73,7 @@ func (this *Compiler) Compile (inputs []string) error {
|
|||
"could not determine output type"))
|
||||
default:
|
||||
return errors.New(fmt.Sprintf (
|
||||
"unknown output type %s", extension))
|
||||
"unknown output type %s", this.Format))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ func main () {
|
|||
help := cli.NewFlag (
|
||||
'h', "help",
|
||||
"Display usage information and exit")
|
||||
format := cli.NewInputFlag (
|
||||
'm', "format",
|
||||
"Output format (.s, .o, .ll)", "",
|
||||
cli.NewValSet(".s", ".o", ".ll"))
|
||||
output := cli.NewInputFlag (
|
||||
'o', "output",
|
||||
"Output filename", "",
|
||||
|
@ -18,7 +22,13 @@ func main () {
|
|||
"Optimization level (0-3)", "0",
|
||||
cli.NewValSet("0", "1", "2", "3"))
|
||||
|
||||
application := cli.New("Compile FSPL source files", help, output, optimization)
|
||||
application := cli.New (
|
||||
"Compile FSPL source files",
|
||||
help,
|
||||
format,
|
||||
output,
|
||||
optimization)
|
||||
|
||||
application.Syntax = "[OPTION]... [FILE]..."
|
||||
application.ParseOrExit(os.Args)
|
||||
if help.Value != "" {
|
||||
|
@ -29,6 +39,7 @@ func main () {
|
|||
compiler := new(Compiler)
|
||||
compiler.Output = output.Value
|
||||
compiler.Optimization = optimization.Value
|
||||
compiler.Format = format.Value
|
||||
|
||||
err := compiler.Compile(application.Args)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue