Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wa-lang
wa
提交
e8fa425c
wa
项目概览
wa-lang
/
wa
12 个月 前同步成功
通知
68
Star
655
Fork
45
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
wa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e8fa425c
编写于
9月 11, 2022
作者:
chai2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
默认输出 wa 规范的 wat 文件
上级
78581bbd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
52 addition
and
88 deletion
+52
-88
api/api.go
api/api.go
+1
-2
internal/app/wabt_wat2wasm.go
internal/app/wabt_wat2wasm.go
+8
-6
internal/backends/compiler_wat/base.wat.go
internal/backends/compiler_wat/base.wat.go
+18
-1
internal/backends/compiler_wat/compile.go
internal/backends/compiler_wat/compile.go
+11
-1
internal/backends/target_spec/target.go
internal/backends/target_spec/target.go
+0
-3
main.go
main.go
+14
-40
main_wasm.go
main_wasm.go
+0
-35
未找到文件。
api/api.go
浏览文件 @
e8fa425c
...
...
@@ -45,8 +45,7 @@ type StdSize = config.StdSizes
type
Machine
=
target_spec
.
Machine
const
(
// 默认输出的目标类型
Machine_default
=
target_spec
.
Machine_Wasm32_wa
Machine_default
=
Machine_Wasm32_wa
// 默认输出的目标类型
Machine_Wasm32_wa
=
target_spec
.
Machine_Wasm32_wa
// 凹语言定义的 WASM 规范
Machine_Wasm32_wasi
=
target_spec
.
Machine_Wasm32_wasi
// WASI 定义的 WASM 规范
...
...
internal/app/wabt_wat2wasm.go
浏览文件 @
e8fa425c
...
...
@@ -14,7 +14,6 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/wa-lang/wa/internal/config"
"github.com/wa-lang/wa/internal/logger"
...
...
@@ -44,11 +43,6 @@ func RunWasm(filename string) (stdoutStderr []byte, err error) {
)
defer
r
.
Close
(
ctx
)
if
false
{
if
_
,
err
:=
wasi_snapshot_preview1
.
Instantiate
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
}
}
_
,
err
=
r
.
NewModuleBuilder
(
"wasi_snapshot_preview1"
)
.
ExportFunction
(
"fd_write"
,
func
(
m
api
.
Module
,
fd
,
iov
,
iov_len
,
p_nwritten
uint32
)
uint32
{
pos
,
_
:=
m
.
Memory
()
.
ReadUint32Le
(
ctx
,
iov
)
...
...
@@ -57,6 +51,14 @@ func RunWasm(filename string) (stdoutStderr []byte, err error) {
fmt
.
Print
(
string
(
bytes
))
return
0
})
.
ExportFunction
(
"PrintI32"
,
func
(
m
api
.
Module
,
v
uint32
)
{
fmt
.
Print
(
v
)
return
})
.
ExportFunction
(
"PrintRune"
,
func
(
m
api
.
Module
,
ch
uint32
)
{
fmt
.
Printf
(
"%c"
,
rune
(
ch
))
return
})
.
Instantiate
(
ctx
,
r
)
if
err
!=
nil
{
return
nil
,
err
...
...
internal/backends/compiler_wat/base.wat.go
浏览文件 @
e8fa425c
...
...
@@ -43,7 +43,24 @@ const (
_waStart
=
"_start"
)
const
modBaseWat
=
`
const
modBaseWat_wa
=
`
(import "wasi_snapshot_preview1" "PrintI32" (func $$PrintI32 (param $x i32)))
(import "wasi_snapshot_preview1" "PrintRune" (func $$PrintRune (param $ch i32)))
(memory $memory 1)
(export "memory" (memory $memory))
(export "_start" (func $_start))
(func $_start
;; {{$_start/body/begin}}
;; (call $main.init)
(call $main)
;; {{$_start/body/end}}
)
`
const
modBaseWat_wasi
=
`
(import "wasi_snapshot_preview1" "fd_write"
(func $$FdWrite (param i32 i32 i32 i32) (result i32))
)
...
...
internal/backends/compiler_wat/compile.go
浏览文件 @
e8fa425c
...
...
@@ -3,6 +3,8 @@
package
compiler_wat
import
(
"fmt"
"github.com/wa-lang/wa/internal/backends/compiler_wat/wir/wat"
"github.com/wa-lang/wa/internal/backends/target_spec"
"github.com/wa-lang/wa/internal/loader"
...
...
@@ -17,11 +19,19 @@ type Compiler struct {
func
New
()
*
Compiler
{
p
:=
new
(
Compiler
)
p
.
module
.
BaseWat
=
modBaseWat
return
p
}
func
(
p
*
Compiler
)
Compile
(
prog
*
loader
.
Program
,
target
target_spec
.
Machine
)
(
output
string
,
err
error
)
{
switch
target
{
case
target_spec
.
Machine_Wasm32_wa
,
""
:
p
.
module
.
BaseWat
=
modBaseWat_wa
case
target_spec
.
Machine_Wasm32_wasi
:
p
.
module
.
BaseWat
=
modBaseWat_wasi
default
:
return
""
,
fmt
.
Errorf
(
"compiler_wat.Compiler: unsupport target: %v"
,
target
)
}
p
.
CompilePackage
(
prog
.
SSAMainPkg
)
return
p
.
module
.
String
(),
nil
...
...
internal/backends/target_spec/target.go
浏览文件 @
e8fa425c
...
...
@@ -6,9 +6,6 @@ package target_spec
type
Machine
string
const
(
// 默认输出的目标类型
Machine_default
=
Machine_Wasm32_wa
Machine_Wasm32_wa
Machine
=
"wasm32-wa"
// 凹语言定义的 WASM 规范
Machine_Wasm32_wasi
Machine
=
"wasm32-wasi"
// WASI 定义的 WASM 规范
Machine_llir_64bit
Machine
=
"llir-64bit"
// LLVM IR 64 位
...
...
main.go
浏览文件 @
e8fa425c
...
...
@@ -62,13 +62,8 @@ func main() {
cli
.
ShowAppHelpAndExit
(
c
,
0
)
}
var
target
=
target_spec
.
Machine_Wasm32_wasi
if
c
.
Bool
(
"html"
)
{
target
=
target_spec
.
Machine_Wasm32_wa
}
ctx
:=
app
.
NewApp
(
build_Options
(
c
))
output
,
err
:=
ctx
.
WASM
(
c
.
Args
()
.
First
(),
target
)
output
,
err
:=
ctx
.
WASM
(
c
.
Args
()
.
First
(),
target
_spec
.
Machine_Wasm32_wa
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
...
...
@@ -159,10 +154,6 @@ func main() {
Name
:
"html"
,
Usage
:
"output html"
,
},
&
cli
.
StringFlag
{
Name
:
"target"
,
Usage
:
"set target"
,
},
},
Action
:
func
(
c
*
cli
.
Context
)
error
{
if
c
.
NArg
()
==
0
{
...
...
@@ -170,25 +161,8 @@ func main() {
os
.
Exit
(
1
)
}
var
target
target_spec
.
Machine
if
s
:=
c
.
String
(
"target"
);
s
!=
""
{
if
t
,
ok
:=
api
.
ParseMachine
(
s
);
ok
{
target
=
t
}
else
{
fmt
.
Printf
(
"imvalid target: %q"
,
s
)
os
.
Exit
(
1
)
}
}
if
target
==
""
{
if
c
.
Bool
(
"html"
)
{
target
=
target_spec
.
Machine_Wasm32_wa
}
else
{
target
=
target_spec
.
Machine_Wasm32_wasi
}
}
ctx
:=
app
.
NewApp
(
build_Options
(
c
))
output
,
err
:=
ctx
.
WASM
(
c
.
Args
()
.
First
(),
target
)
output
,
err
:=
ctx
.
WASM
(
c
.
Args
()
.
First
(),
target
_spec
.
Machine_Wasm32_wa
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
...
...
@@ -204,16 +178,20 @@ func main() {
os
.
Exit
(
1
)
}
stdoutStderr
,
err
:=
app
.
RunWasm
(
outfile
)
if
err
!=
nil
{
if
c
.
Bool
(
"html"
)
{
// todo
}
else
{
stdoutStderr
,
err
:=
app
.
RunWasm
(
outfile
)
if
err
!=
nil
{
if
len
(
stdoutStderr
)
>
0
{
fmt
.
Println
(
string
(
stdoutStderr
))
}
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
if
len
(
stdoutStderr
)
>
0
{
fmt
.
Println
(
string
(
stdoutStderr
))
}
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
if
len
(
stdoutStderr
)
>
0
{
fmt
.
Println
(
string
(
stdoutStderr
))
}
return
nil
...
...
@@ -255,11 +233,7 @@ func main() {
}
}
if
target
==
""
{
if
c
.
Bool
(
"html"
)
{
target
=
target_spec
.
Machine_Wasm32_wa
}
else
{
target
=
target_spec
.
Machine_Wasm32_wasi
}
target
=
target_spec
.
Machine_Wasm32_wa
}
ctx
:=
app
.
NewApp
(
build_Options
(
c
))
...
...
main_wasm.go
已删除
100644 → 0
浏览文件 @
78581bbd
// 版权 @2022 凹语言 作者。保留所有权利。
//go:build wasm
// +build wasm
// 凹语言™ 命令行程序。
package
main
import
(
"encoding/json"
"github.com/wa-lang/wa/api"
)
func
main
()
{
println
(
"hello wasm"
)
}
type
WASMResut
struct
{
Result
string
`json:"result"`
Error
string
`json:"error"`
}
//export walang_api_BuildCode
func
walang_api_BuildCode
(
code
string
)
string
{
var
result
WASMResut
wat
,
err
:=
api
.
BuildFile
(
"hello.wa"
,
code
)
if
err
!=
nil
{
result
.
Error
=
err
.
Error
()
}
result
.
Result
=
string
(
wat
)
b
,
_
:=
json
.
Marshal
(
result
)
return
string
(
b
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录