all: use compiler-rt for builtins

This commit is contained in:
Ayke van Laethem
2018-10-07 17:37:27 +02:00
parent e8f211935e
commit 22da104530
11 changed files with 350 additions and 13 deletions
+27
View File
@@ -17,6 +17,11 @@ import (
"github.com/aykevl/tinygo/compiler"
)
var commands = map[string]string{
"ar": "ar",
"clang": "clang-7",
}
// Helper function for Compiler object.
func Compile(pkgName, outpath string, spec *TargetSpec, printIR, dumpSSA, debug bool, printSizes string, action func(string) error) error {
config := compiler.Config{
@@ -95,10 +100,24 @@ func Compile(pkgName, outpath string, spec *TargetSpec, printIR, dumpSSA, debug
return err
}
// Load builtins library from the cache, possibly compiling it on the
// fly.
var cachePath string
if spec.CompilerRT {
librt, err := loadBuiltins(spec.Triple)
if err != nil {
return err
}
cachePath, _ = filepath.Split(librt)
}
// Link the object file with the system compiler.
executable := filepath.Join(dir, "main")
tmppath := executable // final file
args := append(spec.PreLinkArgs, "-o", executable, objfile)
if spec.CompilerRT {
args = append(args, "-L", cachePath, "-lrt-"+spec.Triple)
}
cmd := exec.Command(spec.Linker, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
@@ -371,6 +390,14 @@ func main() {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
case "clean":
// remove cache directory
dir := cacheDir()
err := os.RemoveAll(dir)
if err != nil {
fmt.Fprintln(os.Stderr, "cannot clean cache:", err)
os.Exit(1)
}
case "help":
usage()
case "run":