Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Second State
SSVM
提交
1631aad9
S
SSVM
项目概览
Second State
/
SSVM
通知
5
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SSVM
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1631aad9
编写于
2月 10, 2021
作者:
Y
YiYing He
提交者:
Yi-Ying He
2月 17, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[VM] Add load wasm function with AST::Module input.
上级
1c815996
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
6 deletion
+22
-6
include/vm/vm.h
include/vm/vm.h
+6
-5
lib/vm/vm.cpp
lib/vm/vm.cpp
+16
-1
未找到文件。
include/vm/vm.h
浏览文件 @
1631aad9
...
@@ -45,6 +45,7 @@ public:
...
@@ -45,6 +45,7 @@ public:
Expect
<
void
>
registerModule
(
std
::
string_view
Name
,
Expect
<
void
>
registerModule
(
std
::
string_view
Name
,
const
std
::
filesystem
::
path
&
Path
);
const
std
::
filesystem
::
path
&
Path
);
Expect
<
void
>
registerModule
(
std
::
string_view
Name
,
Span
<
const
Byte
>
Code
);
Expect
<
void
>
registerModule
(
std
::
string_view
Name
,
Span
<
const
Byte
>
Code
);
Expect
<
void
>
registerModule
(
std
::
string_view
Name
,
const
AST
::
Module
&
Module
);
Expect
<
void
>
registerModule
(
const
Runtime
::
ImportObject
&
Obj
);
Expect
<
void
>
registerModule
(
const
Runtime
::
ImportObject
&
Obj
);
/// Rapidly load, validate, instantiate, and run wasm function.
/// Rapidly load, validate, instantiate, and run wasm function.
...
@@ -54,10 +55,14 @@ public:
...
@@ -54,10 +55,14 @@ public:
Expect
<
std
::
vector
<
ValVariant
>>
Expect
<
std
::
vector
<
ValVariant
>>
runWasmFile
(
Span
<
const
Byte
>
Code
,
std
::
string_view
Func
,
runWasmFile
(
Span
<
const
Byte
>
Code
,
std
::
string_view
Func
,
Span
<
const
ValVariant
>
Params
=
{});
Span
<
const
ValVariant
>
Params
=
{});
Expect
<
std
::
vector
<
ValVariant
>>
runWasmFile
(
const
AST
::
Module
&
Module
,
std
::
string_view
Func
,
Span
<
const
ValVariant
>
Params
=
{});
/// Load given wasm file
or wasm bytecod
e.
/// Load given wasm file
, wasm bytecode, or wasm modul
e.
Expect
<
void
>
loadWasm
(
const
std
::
filesystem
::
path
&
Path
);
Expect
<
void
>
loadWasm
(
const
std
::
filesystem
::
path
&
Path
);
Expect
<
void
>
loadWasm
(
Span
<
const
Byte
>
Code
);
Expect
<
void
>
loadWasm
(
Span
<
const
Byte
>
Code
);
Expect
<
void
>
loadWasm
(
const
AST
::
Module
&
Module
);
/// ======= Functions can be called after loaded stage. =======
/// ======= Functions can be called after loaded stage. =======
/// Validate loaded wasm module.
/// Validate loaded wasm module.
...
@@ -98,10 +103,6 @@ private:
...
@@ -98,10 +103,6 @@ private:
enum
class
VMStage
:
uint8_t
{
Inited
,
Loaded
,
Validated
,
Instantiated
};
enum
class
VMStage
:
uint8_t
{
Inited
,
Loaded
,
Validated
,
Instantiated
};
void
initVM
();
void
initVM
();
Expect
<
void
>
registerModule
(
std
::
string_view
Name
,
const
AST
::
Module
&
Module
);
Expect
<
std
::
vector
<
ValVariant
>>
runWasmFile
(
const
AST
::
Module
&
Module
,
std
::
string_view
Func
,
Span
<
const
ValVariant
>
Params
);
/// VM environment.
/// VM environment.
const
Configure
&
Config
;
const
Configure
&
Config
;
...
...
lib/vm/vm.cpp
浏览文件 @
1631aad9
...
@@ -58,7 +58,6 @@ Expect<void> VM::registerModule(std::string_view Name, Span<const Byte> Code) {
...
@@ -58,7 +58,6 @@ Expect<void> VM::registerModule(std::string_view Name, Span<const Byte> Code) {
Stage
=
VMStage
::
Validated
;
Stage
=
VMStage
::
Validated
;
}
}
/// Load module.
/// Load module.
std
::
unique_ptr
<
AST
::
Module
>
LoadedMod
;
if
(
auto
Res
=
LoaderEngine
.
parseModule
(
Code
))
{
if
(
auto
Res
=
LoaderEngine
.
parseModule
(
Code
))
{
return
registerModule
(
Name
,
*
(
*
Res
).
get
());
return
registerModule
(
Name
,
*
(
*
Res
).
get
());
}
else
{
}
else
{
...
@@ -77,6 +76,11 @@ Expect<void> VM::registerModule(const Runtime::ImportObject &Obj) {
...
@@ -77,6 +76,11 @@ Expect<void> VM::registerModule(const Runtime::ImportObject &Obj) {
Expect
<
void
>
VM
::
registerModule
(
std
::
string_view
Name
,
Expect
<
void
>
VM
::
registerModule
(
std
::
string_view
Name
,
const
AST
::
Module
&
Module
)
{
const
AST
::
Module
&
Module
)
{
if
(
Stage
==
VMStage
::
Instantiated
)
{
/// When registering module, instantiated module in store will be reset.
/// Therefore the instantiation should restart.
Stage
=
VMStage
::
Validated
;
}
/// Validate module.
/// Validate module.
if
(
auto
Res
=
ValidatorEngine
.
validate
(
Module
);
!
Res
)
{
if
(
auto
Res
=
ValidatorEngine
.
validate
(
Module
);
!
Res
)
{
return
Unexpect
(
Res
);
return
Unexpect
(
Res
);
...
@@ -119,6 +123,11 @@ Expect<std::vector<ValVariant>> VM::runWasmFile(Span<const Byte> Code,
...
@@ -119,6 +123,11 @@ Expect<std::vector<ValVariant>> VM::runWasmFile(Span<const Byte> Code,
Expect
<
std
::
vector
<
ValVariant
>>
VM
::
runWasmFile
(
const
AST
::
Module
&
Module
,
Expect
<
std
::
vector
<
ValVariant
>>
VM
::
runWasmFile
(
const
AST
::
Module
&
Module
,
std
::
string_view
Func
,
std
::
string_view
Func
,
Span
<
const
ValVariant
>
Params
)
{
Span
<
const
ValVariant
>
Params
)
{
if
(
Stage
==
VMStage
::
Instantiated
)
{
/// When running another module, instantiated module in store will be reset.
/// Therefore the instantiation should restart.
Stage
=
VMStage
::
Validated
;
}
if
(
auto
Res
=
ValidatorEngine
.
validate
(
Module
);
!
Res
)
{
if
(
auto
Res
=
ValidatorEngine
.
validate
(
Module
);
!
Res
)
{
return
Unexpect
(
Res
);
return
Unexpect
(
Res
);
}
}
...
@@ -161,6 +170,12 @@ Expect<void> VM::loadWasm(Span<const Byte> Code) {
...
@@ -161,6 +170,12 @@ Expect<void> VM::loadWasm(Span<const Byte> Code) {
return
{};
return
{};
}
}
Expect
<
void
>
VM
::
loadWasm
(
const
AST
::
Module
&
Module
)
{
Mod
=
std
::
make_unique
<
AST
::
Module
>
(
Module
);
Stage
=
VMStage
::
Loaded
;
return
{};
}
Expect
<
void
>
VM
::
validate
()
{
Expect
<
void
>
VM
::
validate
()
{
if
(
Stage
<
VMStage
::
Loaded
)
{
if
(
Stage
<
VMStage
::
Loaded
)
{
/// When module is not loaded, not validate.
/// When module is not loaded, not validate.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录