Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Second State
SSVM
提交
8aceedb3
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 搜索 >>
提交
8aceedb3
编写于
1月 29, 2021
作者:
Y
YiYing He
提交者:
Yi-Ying He
2月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[VM] Simplify the cost table class.
上级
ae768d2b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
9 addition
and
46 deletion
+9
-46
include/vm/costtable.h
include/vm/costtable.h
+8
-28
include/vm/vm.h
include/vm/vm.h
+0
-10
lib/vm/vm.cpp
lib/vm/vm.cpp
+1
-8
未找到文件。
include/vm/costtable.h
浏览文件 @
8aceedb3
...
...
@@ -11,8 +11,6 @@
//===----------------------------------------------------------------------===//
#pragma once
#include "configure.h"
#include <array>
#include <vector>
...
...
@@ -21,40 +19,22 @@ namespace VM {
class
CostTable
{
public:
CostTable
()
{
setCostTable
(
Configure
::
VMType
::
Wasm
);
};
CostTable
()
{
Costs
.
assign
(
UINT16_MAX
+
1
,
1
);
};
~
CostTable
()
=
default
;
/// Add default cost table by types.
bool
setCostTable
(
const
Configure
::
VMType
&
Type
)
{
if
(
Type
>=
Configure
::
VMType
::
Max
)
{
return
false
;
}
Costs
[
uint8_t
(
Type
)].
assign
(
UINT16_MAX
+
1
,
1
);
return
true
;
}
/// Set customized cost table.
bool
setCostTable
(
Configure
::
VMType
Type
,
std
::
vector
<
uint64_t
>
Table
)
{
if
(
Table
.
size
()
<=
UINT16_MAX
)
{
return
false
;
void
setCostTable
(
Span
<
const
uint64_t
>
Table
)
{
Costs
.
assign
(
Table
.
begin
(),
Table
.
end
());
if
(
Costs
.
size
()
<=
UINT16_MAX
)
{
Costs
.
resize
(
UINT16_MAX
+
1
,
0ULL
);
}
if
(
Type
>=
Configure
::
VMType
::
Max
)
{
Type
=
Configure
::
VMType
::
Wasm
;
}
Costs
[
uint8_t
(
Type
)]
=
std
::
move
(
Table
);
return
true
;
}
/// Get cost table reference by types.
const
std
::
vector
<
uint64_t
>
&
getCostTable
(
Configure
::
VMType
Type
)
{
if
(
Type
>=
Configure
::
VMType
::
Max
)
{
Type
=
Configure
::
VMType
::
Wasm
;
}
return
Costs
[
uint8_t
(
Type
)];
}
/// Get cost table array.
Span
<
const
uint64_t
>
getCostTable
()
{
return
Costs
;
}
private:
std
::
array
<
std
::
vector
<
uint64_t
>
,
uint8_t
(
Configure
::
VMType
::
Max
)
>
Costs
;
std
::
vector
<
uint64_t
>
Costs
;
};
}
// namespace VM
...
...
include/vm/vm.h
浏览文件 @
8aceedb3
...
...
@@ -95,12 +95,6 @@ public:
/// Getter of statistics.
Statistics
::
Statistics
&
getStatistics
()
{
return
Stat
;
}
/// Getter of service name.
std
::
string
&
getServiceName
()
{
return
ServiceName
;
}
/// Getter of UUID.
uint64_t
&
getUUID
()
{
return
UUID
;
}
private:
enum
class
VMStage
:
uint8_t
{
Inited
,
Loaded
,
Validated
,
Instantiated
};
...
...
@@ -126,10 +120,6 @@ private:
Runtime
::
StoreManager
&
StoreRef
;
std
::
map
<
Configure
::
VMType
,
std
::
unique_ptr
<
Runtime
::
ImportObject
>>
ImpObjs
;
CostTable
CostTab
;
/// Identification
std
::
string
ServiceName
;
uint64_t
UUID
;
};
}
// namespace VM
...
...
lib/vm/vm.cpp
浏览文件 @
8aceedb3
...
...
@@ -23,25 +23,18 @@ VM::VM(const ProposalConfigure &PConf, const Configure &InputConfig,
void
VM
::
initVM
()
{
/// Set cost table and create import modules from configure.
CostTab
.
setCostTable
(
Configure
::
VMType
::
Wasm
);
Stat
.
setCostTable
(
CostTab
.
getCostTable
(
Configure
::
VMType
::
Wasm
));
Stat
.
setCostTable
(
CostTab
.
getCostTable
());
if
(
Config
.
hasVMType
(
Configure
::
VMType
::
Wasi
))
{
/// 2nd priority of cost table: Wasi
std
::
unique_ptr
<
Runtime
::
ImportObject
>
WasiMod
=
std
::
make_unique
<
Host
::
WasiModule
>
();
InterpreterEngine
.
registerModule
(
StoreRef
,
*
WasiMod
.
get
());
ImpObjs
.
insert
({
Configure
::
VMType
::
Wasi
,
std
::
move
(
WasiMod
)});
CostTab
.
setCostTable
(
Configure
::
VMType
::
Wasi
);
Stat
.
setCostTable
(
CostTab
.
getCostTable
(
Configure
::
VMType
::
Wasi
));
}
if
(
Config
.
hasVMType
(
Configure
::
VMType
::
SSVM_Process
))
{
/// 1st priority of cost table: SSVM_Process
std
::
unique_ptr
<
Runtime
::
ImportObject
>
ProcMod
=
std
::
make_unique
<
Host
::
SSVMProcessModule
>
();
InterpreterEngine
.
registerModule
(
StoreRef
,
*
ProcMod
.
get
());
ImpObjs
.
insert
({
Configure
::
VMType
::
SSVM_Process
,
std
::
move
(
ProcMod
)});
CostTab
.
setCostTable
(
Configure
::
VMType
::
SSVM_Process
);
Stat
.
setCostTable
(
CostTab
.
getCostTable
(
Configure
::
VMType
::
SSVM_Process
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录