all: make garbage collector configurable
Этот коммит содержится в:
родитель
ecb4742316
коммит
c220c140ef
3 изменённых файлов: 23 добавлений и 3 удалений
|
@ -32,6 +32,7 @@ func init() {
|
||||||
// Configure the compiler.
|
// Configure the compiler.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default)
|
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
|
DumpSSA bool // dump Go SSA, for compiler debugging
|
||||||
Debug bool // add debug symbols for gdb
|
Debug bool // add debug symbols for gdb
|
||||||
RootDir string // GOROOT for TinyGo
|
RootDir string // GOROOT for TinyGo
|
||||||
|
@ -170,6 +171,15 @@ func (c *Compiler) TargetData() llvm.TargetData {
|
||||||
return c.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
|
// Compile the given package path or .go file path. Return an error when this
|
||||||
// fails (in any stage).
|
// fails (in any stage).
|
||||||
func (c *Compiler) Compile(mainPath string) error {
|
func (c *Compiler) Compile(mainPath string) error {
|
||||||
|
@ -200,7 +210,7 @@ func (c *Compiler) Compile(mainPath string) error {
|
||||||
CgoEnabled: true,
|
CgoEnabled: true,
|
||||||
UseAllFiles: false,
|
UseAllFiles: false,
|
||||||
Compiler: "gc", // must be one of the recognized compilers
|
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,
|
ParserMode: parser.ParseComments,
|
||||||
}
|
}
|
||||||
|
|
4
main.go
4
main.go
|
@ -25,6 +25,7 @@ var commands = map[string]string{
|
||||||
|
|
||||||
type BuildConfig struct {
|
type BuildConfig struct {
|
||||||
opt string
|
opt string
|
||||||
|
gc string
|
||||||
printIR bool
|
printIR bool
|
||||||
dumpSSA bool
|
dumpSSA bool
|
||||||
debug bool
|
debug bool
|
||||||
|
@ -36,6 +37,7 @@ type BuildConfig struct {
|
||||||
func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, action func(string) error) error {
|
func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, action func(string) error) error {
|
||||||
compilerConfig := compiler.Config{
|
compilerConfig := compiler.Config{
|
||||||
Triple: spec.Triple,
|
Triple: spec.Triple,
|
||||||
|
GC: config.gc,
|
||||||
Debug: config.debug,
|
Debug: config.debug,
|
||||||
DumpSSA: config.dumpSSA,
|
DumpSSA: config.dumpSSA,
|
||||||
RootDir: sourceDir(),
|
RootDir: sourceDir(),
|
||||||
|
@ -433,6 +435,7 @@ func handleCompilerError(err error) {
|
||||||
func main() {
|
func main() {
|
||||||
outpath := flag.String("o", "", "output filename")
|
outpath := flag.String("o", "", "output filename")
|
||||||
opt := flag.String("opt", "z", "optimization level: 0, 1, 2, s, z")
|
opt := flag.String("opt", "z", "optimization level: 0, 1, 2, s, z")
|
||||||
|
gc := flag.String("gc", "dumb", "garbage collector to use (dumb)")
|
||||||
printIR := flag.Bool("printir", false, "print LLVM IR")
|
printIR := flag.Bool("printir", false, "print LLVM IR")
|
||||||
dumpSSA := flag.Bool("dumpssa", false, "dump internal Go SSA")
|
dumpSSA := flag.Bool("dumpssa", false, "dump internal Go SSA")
|
||||||
target := flag.String("target", "", "LLVM target")
|
target := flag.String("target", "", "LLVM target")
|
||||||
|
@ -452,6 +455,7 @@ func main() {
|
||||||
flag.CommandLine.Parse(os.Args[2:])
|
flag.CommandLine.Parse(os.Args[2:])
|
||||||
config := &BuildConfig{
|
config := &BuildConfig{
|
||||||
opt: *opt,
|
opt: *opt,
|
||||||
|
gc: *gc,
|
||||||
printIR: *printIR,
|
printIR: *printIR,
|
||||||
dumpSSA: *dumpSSA,
|
dumpSSA: *dumpSSA,
|
||||||
debug: !*nodebug,
|
debug: !*nodebug,
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
|
// +build gc.dumb
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
// This GC implementation is the simplest useful memory allocator possible: it
|
||||||
|
// only allocates memory and never frees it. For some constrained systems, it
|
||||||
|
// may be the only memory allocator possible.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -22,11 +28,11 @@ func alloc(size uintptr) unsafe.Pointer {
|
||||||
}
|
}
|
||||||
|
|
||||||
func free(ptr unsafe.Pointer) {
|
func free(ptr unsafe.Pointer) {
|
||||||
// TODO: use a GC
|
// Memory is never freed.
|
||||||
}
|
}
|
||||||
|
|
||||||
func GC() {
|
func GC() {
|
||||||
// Unimplemented.
|
// No-op.
|
||||||
}
|
}
|
||||||
|
|
||||||
func KeepAlive(x interface{}) {
|
func KeepAlive(x interface{}) {
|
Загрузка…
Создание таблицы
Сослаться в новой задаче