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

app 添加 wasm 子命令用于 WebAssembly 后端测试

上级 2d2c0f7e
......@@ -21,6 +21,7 @@ import (
"github.com/wa-lang/wa/internal/backends/compiler_c"
"github.com/wa-lang/wa/internal/backends/compiler_ll"
"github.com/wa-lang/wa/internal/backends/compiler_ll/builtin"
"github.com/wa-lang/wa/internal/backends/compiler_wasm"
"github.com/wa-lang/wa/internal/config"
"github.com/wa-lang/wa/internal/format"
"github.com/wa-lang/wa/internal/loader"
......@@ -310,6 +311,22 @@ func (p *App) ASM(filename string) error {
return nil
}
func (p *App) WASM(filename string) error {
cfg := config.DefaultConfig()
prog, err := loader.LoadProgram(cfg, filename)
if err != nil {
return err
}
output, err := compiler_wasm.New().Compile(prog)
if err != nil {
return err
}
fmt.Print(output)
return nil
}
func (p *App) Build(filename string, src interface{}, outfile string) (output []byte, err error) {
return p.build(filename, src, outfile, p.opt.TargetOS, p.opt.TargetArch)
}
......
......@@ -168,7 +168,7 @@ func (p *Compiler) emitGlobals() error {
if len(p.module.Global.Globals) > 0 {
return nil
}
panic("TODO")
panic("TODO: support WASM")
}
func (p *Compiler) emitMainBody() error {
......@@ -206,7 +206,7 @@ func (p *Compiler) compileNone(ctx *module.Expr, node ast.Node) error {
return nil
}
panic("TODO")
panic("TODO: support WASM")
}
func (p *Compiler) globalIndexByName(name string) uint32 {
......
......@@ -250,6 +250,24 @@ func main() {
return nil
},
},
{
Name: "wasm",
Usage: "parse Wa and print ouput WebAssembly code",
Action: func(c *cli.Context) error {
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())
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return nil
},
},
{
Name: "test",
Usage: "test packages",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册