compiler: refactor compiler into separate package

This commit is contained in:
Ayke van Laethem
2018-09-22 20:30:46 +02:00
parent b75a02e66d
commit b2cbfa78ca
5 changed files with 12 additions and 7 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ clean:
@rm -rf build
fmt:
@go fmt . ./ir ./src/examples/* ./src/machine ./src/runtime ./src/sync
@go fmt . ./compiler ./ir ./src/examples/* ./src/machine ./src/runtime ./src/sync
gen-device: gen-device-nrf gen-device-avr
+5 -1
View File
@@ -1,4 +1,4 @@
package main
package compiler
import (
"errors"
@@ -139,6 +139,10 @@ func NewCompiler(pkgName, triple string, dumpSSA bool) (*Compiler, error) {
return c, nil
}
func (c *Compiler) Module() llvm.Module {
return c.mod
}
func (c *Compiler) Parse(mainPath string, buildTags []string) error {
tripleSplit := strings.Split(c.triple, "-")
+1 -1
View File
@@ -1,4 +1,4 @@
package main
package compiler
import (
"go/types"
+1 -1
View File
@@ -1,4 +1,4 @@
package main
package compiler
// This file contains functions that are also used by the runtime. These must be
// kept in sync.
+4 -3
View File
@@ -13,11 +13,12 @@ import (
"strings"
"github.com/aykevl/llvm/bindings/go/llvm"
"github.com/aykevl/tinygo/compiler"
)
// Helper function for Compiler object.
func Compile(pkgName, outpath string, spec *TargetSpec, printIR, dumpSSA bool, printSizes string, action func(string) error) error {
c, err := NewCompiler(pkgName, spec.Triple, dumpSSA)
c, err := compiler.NewCompiler(pkgName, spec.Triple, dumpSSA)
if err != nil {
return err
}
@@ -187,7 +188,7 @@ func Flash(pkgName, target, port string, printIR, dumpSSA bool, printSizes strin
// Run the specified package directly (using JIT or interpretation).
func Run(pkgName string) error {
c, err := NewCompiler(pkgName, llvm.DefaultTargetTriple(), false)
c, err := compiler.NewCompiler(pkgName, llvm.DefaultTargetTriple(), false)
if err != nil {
return errors.New("compiler: " + err.Error())
}
@@ -200,7 +201,7 @@ func Run(pkgName string) error {
}
c.Optimize(1, 0, 0) // -O1, the fastest optimization level that doesn't crash
engine, err := llvm.NewExecutionEngine(c.mod)
engine, err := llvm.NewExecutionEngine(c.Module())
if err != nil {
return errors.New("interpreter setup: " + err.Error())
}