diff --git a/chore/gentests/gentests.go b/chore/gentests/gentests.go index 576a2aee..cc7d5692 100644 --- a/chore/gentests/gentests.go +++ b/chore/gentests/gentests.go @@ -21,6 +21,7 @@ import ( "os" "strings" + "github.com/goplus/llgo/cl" "github.com/goplus/llgo/internal/llgen" "github.com/goplus/llgo/ssa" "github.com/goplus/mod" @@ -41,6 +42,20 @@ func main() { llgenDir(dir+"/cl/_testdata", "") } +func isDbgSymEnabled(flagsFile string) bool { + data, err := os.ReadFile(flagsFile) + if err != nil { + return false + } + toks := strings.Split(strings.Join(strings.Split(string(data), "\n"), " "), " ") + for _, tok := range toks { + if tok == "-dbg" { + return true + } + } + return false +} + func llgenDir(dir string, pkgPath ...string) { fis, err := os.ReadDir(dir) check(err) @@ -49,10 +64,17 @@ func llgenDir(dir string, pkgPath ...string) { if !fi.IsDir() || strings.HasPrefix(name, "_") { continue } - testDir := dir + "/" + name - fmt.Fprintln(os.Stderr, "llgen", testDir) - os.Chdir(testDir) - llgen.SmartDoFile("in.go", pkgPath...) + func() { + testDir := dir + "/" + name + fmt.Fprintln(os.Stderr, "llgen", testDir) + os.Chdir(testDir) + dbg := isDbgSymEnabled("flags.txt") + if dbg { + cl.EnableDebugSymbols() + } + defer cl.DisableDebugSymbols() + llgen.SmartDoFile("in.go", pkgPath...) + }() } } diff --git a/cl/cltest/cltest.go b/cl/cltest/cltest.go index 5d4c2913..9ce09eb1 100644 --- a/cl/cltest/cltest.go +++ b/cl/cltest/cltest.go @@ -107,6 +107,20 @@ func Pkg(t *testing.T, pkgPath, outFile string) { } } +func isDbgSymEnabled(flagsFile string) bool { + data, err := os.ReadFile(flagsFile) + if err != nil { + return false + } + toks := strings.Split(strings.Join(strings.Split(string(data), "\n"), " "), " ") + for _, tok := range toks { + if tok == "-dbg" { + return true + } + } + return false +} + func testFrom(t *testing.T, pkgDir, sel string, byLLGen bool) { if sel != "" && !strings.Contains(pkgDir, sel) { return @@ -114,6 +128,11 @@ func testFrom(t *testing.T, pkgDir, sel string, byLLGen bool) { log.Println("Parsing", pkgDir) in := pkgDir + "/in.go" out := pkgDir + "/out.ll" + dbg := isDbgSymEnabled(pkgDir + "/flags.txt") + if dbg { + cl.EnableDebugSymbols() + } + defer cl.DisableDebugSymbols() b, err := os.ReadFile(out) if err != nil { t.Fatal("ReadFile failed:", err)