提交 86ba7320 编写于 作者: chai2010's avatar chai2010

添加 pkg/app 包, 对应 cmd 实现

上级 7b94b991
// 版权 @2019 凹语言 作者。保留所有权利。
package app
// 命令行选项
type Option struct {
Debug bool
TargetArch string
TargetOS string
Clang string
WasmLLC string
WasmLD string
}
// 命令行程序对象
type App struct {
opt Option
path string
src string
}
// 构建命令行程序对象
func NewApp(opt *Option) *App {
panic("TODO")
}
func (p *App) InitApp(name, pkgpath string, update bool) error {
panic("TODO")
}
func (p *App) Fmt(path string) error {
panic("TODO")
}
func (p *App) Lex(filename string) error {
return nil
}
func (p *App) AST(filename string) error {
panic("TODO")
}
func (p *App) SSA(filename string) error {
panic("TODO")
}
func (p *App) ASM(filename string) error {
panic("TODO")
}
func (p *App) Build(filename string, src interface{}, outfile string) (output []byte, err error) {
panic("TODO")
}
func (p *App) Run(filename string, src interface{}) (data []byte, err error) {
panic("TODO")
}
// 版权 @2019 凹语言 作者。保留所有权利。
package app
import (
"fmt"
"os"
"path/filepath"
)
func findPkgInfo(workDir string) (pkgroot, pkgpath string, err error) {
var wd = workDir
if wd == "" {
if s, _ := os.Getwd(); s != "" {
wd = s
}
}
if abs, _ := filepath.Abs(wd); abs != "" {
wd = abs
}
if wd == "" {
return "", "", fmt.Errorf("pkg root not found")
}
pkgroot = wd
for pkgroot != "" {
waJsonPath := filepath.Join(pkgroot, "wa.json")
if fi, _ := os.Stat(waJsonPath); fi != nil {
pkgpath, err = filepath.Rel(pkgroot, wd)
pkgroot = filepath.ToSlash(pkgroot)
pkgpath = filepath.ToSlash(pkgpath)
return // OK
}
pkgroot = filepath.Dir(pkgroot)
if pkgroot == "" || pkgroot == "/" || pkgroot == filepath.Dir(pkgroot) {
break
}
}
return "", "", fmt.Errorf("pkg root not found")
}
// 版权 @2019 凹语言 作者。保留所有权利。
package pkg
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册