mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-12 15:03:41 +00:00
compiler: refactor compiler into separate package
This commit is contained in:
@@ -54,7 +54,7 @@ clean:
|
|||||||
@rm -rf build
|
@rm -rf build
|
||||||
|
|
||||||
fmt:
|
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
|
gen-device: gen-device-nrf gen-device-avr
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package compiler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -139,6 +139,10 @@ func NewCompiler(pkgName, triple string, dumpSSA bool) (*Compiler, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Compiler) Module() llvm.Module {
|
||||||
|
return c.mod
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
func (c *Compiler) Parse(mainPath string, buildTags []string) error {
|
||||||
tripleSplit := strings.Split(c.triple, "-")
|
tripleSplit := strings.Split(c.triple, "-")
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package compiler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go/types"
|
"go/types"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package compiler
|
||||||
|
|
||||||
// This file contains functions that are also used by the runtime. These must be
|
// This file contains functions that are also used by the runtime. These must be
|
||||||
// kept in sync.
|
// kept in sync.
|
||||||
@@ -13,11 +13,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aykevl/llvm/bindings/go/llvm"
|
"github.com/aykevl/llvm/bindings/go/llvm"
|
||||||
|
"github.com/aykevl/tinygo/compiler"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Helper function for Compiler object.
|
// Helper function for Compiler object.
|
||||||
func Compile(pkgName, outpath string, spec *TargetSpec, printIR, dumpSSA bool, printSizes string, action func(string) error) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
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).
|
// Run the specified package directly (using JIT or interpretation).
|
||||||
func Run(pkgName string) error {
|
func Run(pkgName string) error {
|
||||||
c, err := NewCompiler(pkgName, llvm.DefaultTargetTriple(), false)
|
c, err := compiler.NewCompiler(pkgName, llvm.DefaultTargetTriple(), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("compiler: " + err.Error())
|
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
|
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 {
|
if err != nil {
|
||||||
return errors.New("interpreter setup: " + err.Error())
|
return errors.New("interpreter setup: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user