From ef600965aa3e4f81466437508cf38d46c1c7f37d Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 31 Oct 2019 15:54:28 +0100 Subject: [PATCH] compiler: move Config struct to compileopts --- compileopts/config.go | 31 +++++++++++++++++++++++++++++++ compiler/compiler.go | 33 +++------------------------------ main.go | 4 ++-- 3 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 compileopts/config.go diff --git a/compileopts/config.go b/compileopts/config.go new file mode 100644 index 00000000..b861034a --- /dev/null +++ b/compileopts/config.go @@ -0,0 +1,31 @@ +// Package compileopts contains the configuration for a single to-be-built +// binary. +package compileopts + +// Config keeps all configuration affecting the build in a single struct. +type Config struct { + Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default) + CPU string // LLVM CPU name, e.g. atmega328p (empty string means default) + Features []string // LLVM CPU features + GOOS string // + GOARCH string // + GC string // garbage collection strategy + Scheduler string // scheduler implementation ("coroutines" or "tasks") + PanicStrategy string // panic strategy ("print" or "trap") + CFlags []string // cflags to pass to cgo + LDFlags []string // ldflags to pass to cgo + ClangHeaders string // Clang built-in header include path + DumpSSA bool // dump Go SSA, for compiler debugging + VerifyIR bool // run extra checks on the IR + Debug bool // add debug symbols for gdb + GOROOT string // GOROOT + TINYGOROOT string // GOROOT for TinyGo + GOPATH string // GOPATH, like `go env GOPATH` + BuildTags []string // build tags for TinyGo (empty means {Config.GOOS/Config.GOARCH}) + TestConfig TestConfig +} + +type TestConfig struct { + CompileTestBinary bool + // TODO: Filter the test functions to run, include verbose flag, etc +} diff --git a/compiler/compiler.go b/compiler/compiler.go index 1787a5e7..427bffe7 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" + "github.com/tinygo-org/tinygo/compileopts" "github.com/tinygo-org/tinygo/ir" "github.com/tinygo-org/tinygo/loader" "golang.org/x/tools/go/ssa" @@ -57,36 +58,8 @@ var coroFunctionsUsedInTransforms = []string{ "runtime.llvmCoroRefHolder", } -// Configure the compiler. -type Config struct { - Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default) - CPU string // LLVM CPU name, e.g. atmega328p (empty string means default) - Features []string // LLVM CPU features - GOOS string // - GOARCH string // - GC string // garbage collection strategy - Scheduler string // scheduler implementation ("coroutines" or "tasks") - PanicStrategy string // panic strategy ("print" or "trap") - CFlags []string // cflags to pass to cgo - LDFlags []string // ldflags to pass to cgo - ClangHeaders string // Clang built-in header include path - DumpSSA bool // dump Go SSA, for compiler debugging - VerifyIR bool // run extra checks on the IR - Debug bool // add debug symbols for gdb - GOROOT string // GOROOT - TINYGOROOT string // GOROOT for TinyGo - GOPATH string // GOPATH, like `go env GOPATH` - BuildTags []string // build tags for TinyGo (empty means {Config.GOOS/Config.GOARCH}) - TestConfig TestConfig -} - -type TestConfig struct { - CompileTestBinary bool - // TODO: Filter the test functions to run, include verbose flag, etc -} - type Compiler struct { - Config + *compileopts.Config mod llvm.Module ctx llvm.Context builder llvm.Builder @@ -129,7 +102,7 @@ type Phi struct { llvm llvm.Value } -func NewCompiler(pkgName string, config Config) (*Compiler, error) { +func NewCompiler(pkgName string, config *compileopts.Config) (*Compiler, error) { if config.Triple == "" { config.Triple = llvm.DefaultTargetTriple() } diff --git a/main.go b/main.go index 009fcc00..b8254f5f 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,7 @@ type BuildConfig struct { tags string wasmAbi string heapSize int64 - testConfig compiler.TestConfig + testConfig compileopts.TestConfig } // Helper function for Compiler object. @@ -108,7 +108,7 @@ func Compile(pkgName, outpath string, spec *compileopts.TargetSpec, config *Buil if config.scheduler != "" { scheduler = config.scheduler } - compilerConfig := compiler.Config{ + compilerConfig := &compileopts.Config{ Triple: spec.Triple, CPU: spec.CPU, Features: spec.Features,