mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
all: move bootstrapping IR to Go runtime
This has the benefit of not requiring a 'runtime' IR file, so that complete relocatable files can be built without requiring input IR. This makes the compiler a lot easier to use without the Makefile. Code size is not affected.
This commit is contained in:
@@ -6,6 +6,39 @@ import (
|
||||
|
||||
const Compiler = "tgo"
|
||||
|
||||
// The compiler will fill this with calls to the initialization function of each
|
||||
// package.
|
||||
func initAll()
|
||||
|
||||
// These signatures are used to call the correct main function: with scheduling
|
||||
// or without scheduling.
|
||||
func main_main()
|
||||
func main_mainAsync(parent *coroutine) *coroutine
|
||||
|
||||
// The compiler will change this to true if there are 'go' statements in the
|
||||
// compiled program and turn it into a const.
|
||||
var hasScheduler bool
|
||||
|
||||
// Entry point for Go. Initialize all packages and call main.main().
|
||||
//go:export main
|
||||
func main() int {
|
||||
// Run initializers of all packages.
|
||||
initAll()
|
||||
|
||||
// This branch must be optimized away. Only one of the targets must remain,
|
||||
// or there will be link errors.
|
||||
if hasScheduler {
|
||||
// Initialize main and run the scheduler.
|
||||
coro := main_mainAsync(nil)
|
||||
scheduler(coro)
|
||||
return 0
|
||||
} else {
|
||||
// No scheduler is necessary. Call main directly.
|
||||
main_main()
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func Sleep(d Duration) {
|
||||
// This function is treated specially by the compiler: when goroutines are
|
||||
// used, it is transformed into a llvm.coro.suspend() call.
|
||||
|
||||
Reference in New Issue
Block a user