all: make targets configurable with a JSON file

This is intentionally similar to the target specifications in Rust:
https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/struct.TargetOptions.html
This commit is contained in:
Ayke van Laethem
2018-09-12 18:13:04 +02:00
parent 20c2552f8a
commit 9bec479041
4 changed files with 56 additions and 15 deletions
+3 -15
View File
@@ -12,21 +12,9 @@ import (
// Helper function for Compiler object.
func Compile(pkgName, runtimePath, outpath, target string, printIR, dumpSSA bool) error {
var buildTags []string
// TODO: put this somewhere else
if target == "pca10040" {
// Pretend to be a WASM target, not ARM (for standard library support).
buildTags = append(buildTags, "nrf", "nrf52", "nrf52832", "js", "wasm")
target = "armv7m-none-eabi"
} else if target == "arduino" {
// Pretend to be a WASM target, not AVR (for standard library support).
buildTags = append(buildTags, "avr", "avr8", "atmega", "atmega328p", "js", "wasm")
target = "avr--"
} else {
buildTags = append(buildTags, runtime.GOOS, runtime.GOARCH)
}
spec, err := LoadTarget(target)
c, err := NewCompiler(pkgName, target, dumpSSA)
c, err := NewCompiler(pkgName, spec.Triple, dumpSSA)
if err != nil {
return err
}
@@ -52,7 +40,7 @@ func Compile(pkgName, runtimePath, outpath, target string, printIR, dumpSSA bool
fmt.Println(c.IR())
}()
}
return c.Parse(pkgName, buildTags)
return c.Parse(pkgName, spec.BuildTags)
}()
if parseErr != nil {
return parseErr