89 lines
2.2 KiB
Go
89 lines
2.2 KiB
Go
package main
|
|
|
|
import "os"
|
|
import "io"
|
|
import "fmt"
|
|
import "git.tebibyte.media/fspl/fspl/cli"
|
|
import "git.tebibyte.media/fspl/fspl/entity"
|
|
import "git.tebibyte.media/fspl/fspl/compiler"
|
|
import ferrors "git.tebibyte.media/fspl/fspl/errors"
|
|
import "git.tebibyte.media/fspl/fspl/compiler/native"
|
|
|
|
func main () {
|
|
// instantiate the compiler
|
|
comp := new(compiler.Compiler)
|
|
comp.Writer = os.Stderr
|
|
|
|
resolver, err := native.NativeResolver()
|
|
if err != nil {
|
|
comp.Errorln(err)
|
|
os.Exit(2)
|
|
}
|
|
comp.Resolver = resolver
|
|
|
|
// take in CLI flags
|
|
debug := cli.NewFlag (
|
|
0, "debug",
|
|
"Print extra debug information while compiling")
|
|
quiet := cli.NewFlag (
|
|
'q', "quiet",
|
|
"Don't print warnings, errors, etc.")
|
|
filetype := cli.NewInputFlag (
|
|
't', "filetype",
|
|
fmt.Sprintf (
|
|
"Output format (%s, %s, %s)",
|
|
compiler.FiletypeAssembly,
|
|
compiler.FiletypeObject,
|
|
compiler.FiletypeIR), "",
|
|
cli.NewValSet (
|
|
compiler.FiletypeAssembly.String(),
|
|
compiler.FiletypeObject.String(),
|
|
compiler.FiletypeIR.String()))
|
|
output := cli.NewInputFlag (
|
|
'o', "output",
|
|
"Output filename", "",
|
|
cli.ValString)
|
|
optimization := cli.NewInputFlag (
|
|
'O', "optimization",
|
|
"Optimization level (0-3)", "0",
|
|
cli.NewValSet("0", "1", "2", "3"))
|
|
includePath := cli.NewInputFlag (
|
|
'u', "unit-directory",
|
|
"Extra directory(s) to search for units in", "",
|
|
cli.ValString)
|
|
includePath.Found = func (application *cli.Cli, value string) {
|
|
comp.Resolver.AddPathFront(value)
|
|
}
|
|
|
|
application := cli.New (
|
|
"Compile FSPL source files",
|
|
cli.NewHelp(),
|
|
debug,
|
|
quiet,
|
|
filetype,
|
|
output,
|
|
optimization,
|
|
includePath)
|
|
|
|
application.Syntax = "[OPTION]... ADDRESS"
|
|
application.ParseOrExit(os.Args)
|
|
if len(application.Args) != 1 {
|
|
comp.Errorln("please specify one unit address")
|
|
application.Usage()
|
|
os.Exit(2)
|
|
}
|
|
|
|
// configure the compiler based on user input
|
|
comp.Output = output.Value
|
|
comp.Optimization = optimization.Value
|
|
comp.Filetype, _ = compiler.FiletypeFromString(filetype.Value)
|
|
comp.Debug = debug.Value != ""
|
|
if quiet.Value != "" { comp.Writer = io.Discard }
|
|
|
|
err = comp.CompileUnit(entity.Address(application.Args[0]))
|
|
if err != nil {
|
|
comp.Errorln(ferrors.Format(err))
|
|
os.Exit(1)
|
|
}
|
|
}
|