llgen: smart fname of outFile (llgo_autogen.ll or out.ll)

This commit is contained in:
xushiwei
2024-04-28 23:07:59 +08:00
parent f09d5bd155
commit e88f7e6659

View File

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