Files
llgo/cmd/internal/flags/flags.go

71 lines
1.8 KiB
Go
Raw Normal View History

2025-04-18 12:54:04 +08:00
package flags
import (
"flag"
"github.com/goplus/llgo/internal/build"
"github.com/goplus/llgo/internal/buildenv"
2025-04-18 12:54:04 +08:00
)
var OutputFile string
var FileFormat string
2025-04-18 12:54:04 +08:00
func AddOutputFlags(fs *flag.FlagSet) {
fs.StringVar(&OutputFile, "o", "", "Output file")
fs.StringVar(&FileFormat, "file-format", "", "File format for target output (e.g., bin, hex, elf, uf2, zip)")
2025-04-18 12:54:04 +08:00
}
var Verbose bool
var BuildEnv string
var Tags string
var Target string
2025-09-05 17:47:34 +08:00
var Emulator bool
2025-08-12 09:43:47 +08:00
var AbiMode int
var CheckLinkArgs bool
var CheckLLFiles bool
var GenLLFiles bool
2025-04-18 12:54:04 +08:00
func AddBuildFlags(fs *flag.FlagSet) {
fs.BoolVar(&Verbose, "v", false, "Verbose mode")
fs.StringVar(&Tags, "tags", "", "Build tags")
fs.StringVar(&BuildEnv, "buildenv", "", "Build environment")
fs.StringVar(&Target, "target", "", "Target platform (e.g., rp2040, wasi)")
if buildenv.Dev {
fs.IntVar(&AbiMode, "abi", 2, "ABI mode (default 2). 0 = none, 1 = cfunc, 2 = allfunc.")
fs.BoolVar(&CheckLinkArgs, "check-linkargs", false, "check link args valid")
fs.BoolVar(&CheckLLFiles, "check-llfiles", false, "check .ll files valid")
fs.BoolVar(&GenLLFiles, "gen-llfiles", false, "generate .ll files for pkg export")
}
2025-04-18 12:54:04 +08:00
}
var Gen bool
2025-09-05 17:47:34 +08:00
func AddRunFlags(fs *flag.FlagSet) {
fs.BoolVar(&Emulator, "emulator", false, "Run in emulator mode")
}
2025-04-18 12:54:04 +08:00
func AddCmpTestFlags(fs *flag.FlagSet) {
fs.BoolVar(&Gen, "gen", false, "Generate llgo.expect file")
}
func UpdateConfig(conf *build.Config) {
conf.Tags = Tags
conf.Verbose = Verbose
conf.Target = Target
switch conf.Mode {
case build.ModeBuild:
conf.OutFile = OutputFile
conf.FileFormat = FileFormat
2025-09-05 17:47:34 +08:00
case build.ModeRun:
conf.Emulator = Emulator
case build.ModeCmpTest:
conf.GenExpect = Gen
}
if buildenv.Dev {
conf.AbiMode = build.AbiMode(AbiMode)
conf.CheckLinkArgs = CheckLinkArgs
conf.CheckLLFiles = CheckLLFiles
conf.GenLL = GenLLFiles
}
}