From e88f7e6659846d77b3a5c80f25816a46dadee183 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sun, 28 Apr 2024 23:07:59 +0800 Subject: [PATCH] llgen: smart fname of outFile (llgo_autogen.ll or out.ll) --- chore/llgen/llgen.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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/") +}