diff --git a/chore/llgen/llgen.go b/chore/llgen/llgen.go index 50e9a89e..33fb48e7 100644 --- a/chore/llgen/llgen.go +++ b/chore/llgen/llgen.go @@ -21,14 +21,19 @@ import ( "fmt" "os" + "github.com/goplus/llgo/internal/build" "github.com/goplus/llgo/internal/llgen" ) +var ( + abi = flag.Int("abi", 0, "ABI mode (default 0). 0 = none, 1 = cfunc, 2 = allfunc.") +) + func main() { flag.Parse() if len(flag.Args()) != 1 { fmt.Fprintln(os.Stderr, "Usage: llgen [flags] ") return } - llgen.SmartDoFile(flag.Args()[0]) + llgen.SmartDoFileEx(flag.Args()[0], build.AbiMode(*abi)) } diff --git a/internal/llgen/llgenf.go b/internal/llgen/llgenf.go index 55e5d5af..4ac61b50 100644 --- a/internal/llgen/llgenf.go +++ b/internal/llgen/llgenf.go @@ -27,12 +27,12 @@ import ( ) func GenFrom(fileOrPkg string) string { - pkg, err := genFrom(fileOrPkg) + pkg, err := genFrom(fileOrPkg, 0) check(err) return pkg.LPkg.String() } -func genFrom(pkgPath string) (build.Package, error) { +func genFrom(pkgPath string, abiMode build.AbiMode) (build.Package, error) { oldDbg := os.Getenv("LLGO_DEBUG") oldDbgSyms := os.Getenv("LLGO_DEBUG_SYMBOLS") dbg := isDbgSymEnabled(filepath.Join(pkgPath, "flags.txt")) @@ -46,8 +46,9 @@ func genFrom(pkgPath string) (build.Package, error) { }() conf := &build.Config{ - Mode: build.ModeGen, - AppExt: build.DefaultAppExt(runtime.GOOS), + Mode: build.ModeGen, + AbiMode: abiMode, + AppExt: build.DefaultAppExt(runtime.GOOS), } pkgs, err := build.Do([]string{pkgPath}, conf) if err != nil { @@ -77,7 +78,11 @@ func isDbgSymEnabled(flagsFile string) bool { } func SmartDoFile(pkgPath string) { - pkg, err := genFrom(pkgPath) + SmartDoFileEx(pkgPath, 0) +} + +func SmartDoFileEx(pkgPath string, abiMode build.AbiMode) { + pkg, err := genFrom(pkgPath, abiMode) check(err) const autgenFile = "llgo_autogen.ll"