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

完善 wasm 命令行参数, action 中暂时屏蔽执行输出的 wat 文件

上级 58775034
......@@ -44,8 +44,8 @@ jobs:
- run: wa run _examples/hello
- run: wa run _examples/prime
- run: wa wasm _examples/hi
- run: wasmer run a.out.wat
- run: wa wasm hello.wa
# - run: wasmer a.out.wat
- uses: shogo82148/actions-goveralls@v1
with:
......
......@@ -13,9 +13,7 @@ prime:
go run main.go run _examples/prime
wasm:
go run main.go ssa _examples/hi
go run main.go wasm _examples/hi
wasmer run a.out.wat
go run main.go wasm hello.wa
wasmer a.out.wat
clean:
# 版权 @2019 凹语言 作者。保留所有权利。
fn main() {
println("凹凹,吃了吗")
println(add(40, 2))
}
......
......@@ -311,20 +311,19 @@ func (p *App) ASM(filename string) error {
return nil
}
func (p *App) WASM(filename string) error {
func (p *App) WASM(filename string) ([]byte, error) {
cfg := config.DefaultConfig()
prog, err := loader.LoadProgram(cfg, filename)
if err != nil {
return err
return nil, err
}
output, err := compiler_wat.New().Compile(prog)
if err != nil {
return err
return nil, err
}
a_out := "a.out.wat"
return os.WriteFile(a_out, []byte(output), 0666)
return []byte(output), nil
}
func (p *App) Build(filename string, src interface{}, outfile string) (output []byte, err error) {
......
......@@ -273,18 +273,39 @@ func main() {
{
Name: "wasm",
Usage: "parse Wa and print ouput WebAssembly text",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "set output file",
Value: "a.out.wat",
},
},
Action: func(c *cli.Context) error {
outfile := c.String("output")
if c.NArg() == 0 {
fmt.Fprintf(os.Stderr, "no input file")
os.Exit(1)
}
ctx := app.NewApp(build_Options(c))
err := ctx.WASM(c.Args().First())
output, err := ctx.WASM(c.Args().First())
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if outfile != "" && outfile != "-" {
err := os.WriteFile(outfile, []byte(output), 0666)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
} else {
fmt.Println(string(output))
}
return nil
},
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册