internal/build: cabi transformer

This commit is contained in:
visualfc
2025-08-12 09:31:43 +08:00
parent 3ac2929789
commit 8e87bb6e86

View File

@@ -38,6 +38,7 @@ import (
"golang.org/x/tools/go/ssa" "golang.org/x/tools/go/ssa"
"github.com/goplus/llgo/cl" "github.com/goplus/llgo/cl"
"github.com/goplus/llgo/internal/cabi"
"github.com/goplus/llgo/internal/crosscompile" "github.com/goplus/llgo/internal/crosscompile"
"github.com/goplus/llgo/internal/env" "github.com/goplus/llgo/internal/env"
"github.com/goplus/llgo/internal/mockable" "github.com/goplus/llgo/internal/mockable"
@@ -63,6 +64,8 @@ const (
ModeGen ModeGen
) )
type AbiMode = cabi.Mode
const ( const (
debugBuild = packages.DebugPackagesLoad debugBuild = packages.DebugPackagesLoad
) )
@@ -76,6 +79,7 @@ type Config struct {
OutFile string // only valid for ModeBuild when len(pkgs) == 1 OutFile string // only valid for ModeBuild when len(pkgs) == 1
RunArgs []string // only valid for ModeRun RunArgs []string // only valid for ModeRun
Mode Mode Mode Mode
AbiMode AbiMode
GenExpect bool // only valid for ModeCmpTest GenExpect bool // only valid for ModeCmpTest
Verbose bool Verbose bool
GenLL bool // generate pkg .ll files GenLL bool // generate pkg .ll files
@@ -108,6 +112,7 @@ func NewDefaultConf(mode Mode) *Config {
Goarch: goarch, Goarch: goarch,
BinPath: bin, BinPath: bin,
Mode: mode, Mode: mode,
AbiMode: cabi.ModeAllFunc,
AppExt: DefaultAppExt(goos), AppExt: DefaultAppExt(goos),
} }
return conf return conf
@@ -276,6 +281,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
crossCompile: export, crossCompile: export,
isCheckEnabled: IsCheckEnabled(), isCheckEnabled: IsCheckEnabled(),
isCheckLinkArgsEnabled: IsCheckLinkArgsEnabled(), isCheckLinkArgsEnabled: IsCheckLinkArgsEnabled(),
cTransformer: cabi.NewTransformer(prog, conf.AbiMode),
} }
pkgs, err := buildAllPkgs(ctx, initial, verbose) pkgs, err := buildAllPkgs(ctx, initial, verbose)
check(err) check(err)
@@ -374,6 +380,8 @@ type context struct {
buildConf *Config buildConf *Config
crossCompile crosscompile.Export crossCompile crosscompile.Export
cTransformer *cabi.Transformer
testFail bool testFail bool
} }
@@ -803,6 +811,9 @@ func buildPkg(ctx *context, aPkg *aPackage, verbose bool) error {
cl.SetDebug(0) cl.SetDebug(0)
} }
check(err) check(err)
ctx.cTransformer.TransformModule(ret)
aPkg.LPkg = ret aPkg.LPkg = ret
cgoLLFiles, cgoLdflags, err := buildCgo(ctx, aPkg, aPkg.Package.Syntax, externs, verbose) cgoLLFiles, cgoLdflags, err := buildCgo(ctx, aPkg, aPkg.Package.Syntax, externs, verbose)
if err != nil { if err != nil {