diff --git a/chore/llgen/llgen.go b/chore/llgen/llgen.go index ca7ce200..3473fa1d 100644 --- a/chore/llgen/llgen.go +++ b/chore/llgen/llgen.go @@ -20,20 +20,25 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/goplus/llgo/internal/llgen" ) func main() { if len(os.Args) < 2 { - fmt.Fprintln(os.Stderr, "Usage: llgen xxx.go [pkgPath]") + fmt.Fprintln(os.Stderr, "Usage: llgen [pkgPath]") return } inFile := os.Args[1] dir, _ := filepath.Split(inFile) - outFile := dir + "out.ll" + fname := "llgo_autogen.ll" + if inCompilerDir(dir) { + fname = "out.ll" + } + outFile := dir + fname llgen.Init() if len(os.Args) >= 3 { @@ -42,3 +47,8 @@ func main() { llgen.DoFile(inFile, outFile) } } + +func inCompilerDir(dir string) bool { + dir, _ = filepath.Abs(dir) + return strings.Contains(filepath.ToSlash(dir), "/llgo/cl/") +}