chore: llgen -abi flags (default 0)

This commit is contained in:
visualfc
2025-08-12 09:42:58 +08:00
parent 8e87bb6e86
commit 6460724feb
2 changed files with 16 additions and 6 deletions

View File

@@ -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] <pkg>")
return
}
llgen.SmartDoFile(flag.Args()[0])
llgen.SmartDoFileEx(flag.Args()[0], build.AbiMode(*abi))
}

View File

@@ -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"