mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
compiler: refactor compiler into separate package
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
package main
|
||||
package compiler
|
||||
|
||||
import (
|
||||
"go/types"
|
||||
@@ -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.
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user