forked from go-llvm/llgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (30 loc) · 1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2012 The llgo Authors.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package runtime
// #llgo linkage: appending
var ctors [1]*int8 // nil, used to find end of list
// helper function to call a raw function pointer.
// TODO move all of this code to .ll/.c
func callNiladicFunc(f *int8)
// A Go program will enter this function before doing anything else.
func main(argc int32, argv **byte, envp **byte, mainmain *int8) int32 {
// Initialise the runtime before calling any constructors.
setosargs(argc, argv, envp)
// Constructors are in reverse order (see llgo/compiler.go for
// an explanation). Since runtime module must always come last,
// we can use a sentinel nil value to find the end.
for i := 0; ; i++ {
if ctors[i] == nil {
for i > 0 {
i--
callNiladicFunc(ctors[i])
}
break
}
}
// All done, call "main.main".
// TODO recover from panics, alter return code accordingly.
callNiladicFunc(mainmain)
return 0
}