all: make garbage collector configurable

This commit is contained in:
Ayke van Laethem
2018-11-17 15:01:30 +01:00
parent ecb4742316
commit c220c140ef
3 changed files with 23 additions and 3 deletions
+11 -1
View File
@@ -32,6 +32,7 @@ func init() {
// Configure the compiler.
type Config struct {
Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default)
GC string // garbage collection strategy
DumpSSA bool // dump Go SSA, for compiler debugging
Debug bool // add debug symbols for gdb
RootDir string // GOROOT for TinyGo
@@ -170,6 +171,15 @@ func (c *Compiler) TargetData() llvm.TargetData {
return c.targetData
}
// selectGC picks an appropriate GC strategy if none was provided.
func (c *Compiler) selectGC() string {
gc := c.GC
if gc == "" {
gc = "dumb"
}
return gc
}
// Compile the given package path or .go file path. Return an error when this
// fails (in any stage).
func (c *Compiler) Compile(mainPath string) error {
@@ -200,7 +210,7 @@ func (c *Compiler) Compile(mainPath string) error {
CgoEnabled: true,
UseAllFiles: false,
Compiler: "gc", // must be one of the recognized compilers
BuildTags: append([]string{"tinygo"}, c.BuildTags...),
BuildTags: append([]string{"tinygo", "gc." + c.selectGC()}, c.BuildTags...),
},
ParserMode: parser.ParseComments,
}