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 {
|
type Compiler struct {
|
||||||
Output string
|
Output string
|
||||||
Optimization string
|
Optimization string
|
||||||
|
Format string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Compiler) Compile (inputs []string) error {
|
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))
|
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 == "" {
|
if this.Output == "" {
|
||||||
this.Output = strings.TrimSuffix (
|
this.Output = strings.TrimSuffix (
|
||||||
inputs[0],
|
inputs[0],
|
||||||
filepath.Ext(inputs[0])) + ".o"
|
filepath.Ext(inputs[0])) + this.Format
|
||||||
}
|
}
|
||||||
|
|
||||||
extension := filepath.Ext(this.Output)
|
// do something based on the output extension
|
||||||
switch extension {
|
switch this.Format {
|
||||||
case ".s":
|
case ".s":
|
||||||
return this.CompileModule(module, "asm")
|
return this.CompileModule(module, "asm")
|
||||||
case ".o":
|
case ".o":
|
||||||
@ -63,7 +73,7 @@ func (this *Compiler) Compile (inputs []string) error {
|
|||||||
"could not determine output type"))
|
"could not determine output type"))
|
||||||
default:
|
default:
|
||||||
return errors.New(fmt.Sprintf (
|
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 (
|
help := cli.NewFlag (
|
||||||
'h', "help",
|
'h', "help",
|
||||||
"Display usage information and exit")
|
"Display usage information and exit")
|
||||||
|
format := cli.NewInputFlag (
|
||||||
|
'm', "format",
|
||||||
|
"Output format (.s, .o, .ll)", "",
|
||||||
|
cli.NewValSet(".s", ".o", ".ll"))
|
||||||
output := cli.NewInputFlag (
|
output := cli.NewInputFlag (
|
||||||
'o', "output",
|
'o', "output",
|
||||||
"Output filename", "",
|
"Output filename", "",
|
||||||
@ -18,7 +22,13 @@ func main () {
|
|||||||
"Optimization level (0-3)", "0",
|
"Optimization level (0-3)", "0",
|
||||||
cli.NewValSet("0", "1", "2", "3"))
|
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.Syntax = "[OPTION]... [FILE]..."
|
||||||
application.ParseOrExit(os.Args)
|
application.ParseOrExit(os.Args)
|
||||||
if help.Value != "" {
|
if help.Value != "" {
|
||||||
@ -29,6 +39,7 @@ func main () {
|
|||||||
compiler := new(Compiler)
|
compiler := new(Compiler)
|
||||||
compiler.Output = output.Value
|
compiler.Output = output.Value
|
||||||
compiler.Optimization = optimization.Value
|
compiler.Optimization = optimization.Value
|
||||||
|
compiler.Format = format.Value
|
||||||
|
|
||||||
err := compiler.Compile(application.Args)
|
err := compiler.Compile(application.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user