diff --git a/cl/_testdata/importpkg/in.go b/cl/_testdata/importpkg/in.go index f9c1c830..96afbd51 100644 --- a/cl/_testdata/importpkg/in.go +++ b/cl/_testdata/importpkg/in.go @@ -5,5 +5,6 @@ import "github.com/goplus/llgo/cl/internal/stdio" var hello = [...]int8{'H', 'e', 'l', 'l', 'o', '\n', 0} func main() { + _ = stdio.Max(2, 100) stdio.Printf(&hello[0]) } diff --git a/cl/_testdata/importpkg/out.ll b/cl/_testdata/importpkg/out.ll index c07ae22b..de2212b5 100644 --- a/cl/_testdata/importpkg/out.ll +++ b/cl/_testdata/importpkg/out.ll @@ -28,10 +28,13 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0 define void @main() { _llgo_0: call void @main.init() + %0 = call i64 @"github.com/goplus/llgo/cl/internal/stdio.Max"(i64 2, i64 100) call void (ptr, ...) @printf(ptr @main.hello) ret void } declare void @"github.com/goplus/llgo/cl/internal/stdio.init"() +declare i64 @"github.com/goplus/llgo/cl/internal/stdio.Max"(i64, i64) + declare void @printf(ptr, ...) diff --git a/cl/internal/stdio/printf.go b/cl/internal/stdio/printf.go index 38fffa6f..ac080937 100644 --- a/cl/internal/stdio/printf.go +++ b/cl/internal/stdio/printf.go @@ -8,3 +8,10 @@ const ( //go:linkname Printf printf func Printf(format *int8, __llgo_va_list ...any) + +func Max(a, b int) int { + if a > b { + return a + } + return b +} diff --git a/internal/build/build_install.go b/internal/build/build_install.go index 166fcaf8..84075441 100644 --- a/internal/build/build_install.go +++ b/internal/build/build_install.go @@ -48,7 +48,7 @@ const ( ) func Do(args []string, mode Mode) { - flags, patterns := parseArgs(args) + flags, patterns, verbose := parseArgs(args) cfg := &packages.Config{ Mode: loadSyntax | packages.NeedExportFile, BuildFlags: flags, @@ -67,8 +67,10 @@ func Do(args []string, mode Mode) { } llssa.Initialize(llssa.InitAll) - // llssa.SetDebug(llssa.DbgFlagAll) - // cl.SetDebug(cl.DbgFlagAll) + if verbose { + llssa.SetDebug(llssa.DbgFlagAll) + cl.SetDebug(cl.DbgFlagAll) + } prog := llssa.NewProgram(nil) llFiles := make([]string, 0, len(pkgs)) @@ -122,13 +124,18 @@ func allPkgs(initial []*packages.Package, mode ssa.BuilderMode) (prog *ssa.Progr return } -func parseArgs(args []string) (flags, patterns []string) { +func parseArgs(args []string) (flags, patterns []string, verbose bool) { for i, arg := range args { if !strings.HasPrefix(arg, "-") { - return args[:i], args[i:] + flags, patterns = args[:i], args[i:] + return + } + if arg == "-v" { + verbose = true } } - return args, nil + flags = args + return } func check(err error) {