Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Second State
SSVM
提交
ccd18560
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 搜索 >>
提交
ccd18560
编写于
12月 24, 2020
作者:
Y
YiYing He
提交者:
hydai
2月 04, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Runtime] Refactor push functions in store manager.
上级
31d2be18
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
94 addition
and
97 deletion
+94
-97
include/runtime/instance/type.h
include/runtime/instance/type.h
+0
-2
include/runtime/storemgr.h
include/runtime/storemgr.h
+47
-36
lib/interpreter/instantiate/data.cpp
lib/interpreter/instantiate/data.cpp
+2
-6
lib/interpreter/instantiate/elem.cpp
lib/interpreter/instantiate/elem.cpp
+4
-6
lib/interpreter/instantiate/function.cpp
lib/interpreter/instantiate/function.cpp
+17
-12
lib/interpreter/instantiate/global.cpp
lib/interpreter/instantiate/global.cpp
+11
-12
lib/interpreter/instantiate/memory.cpp
lib/interpreter/instantiate/memory.cpp
+2
-6
lib/interpreter/instantiate/module.cpp
lib/interpreter/instantiate/module.cpp
+6
-7
lib/interpreter/instantiate/table.cpp
lib/interpreter/instantiate/table.cpp
+4
-6
lib/interpreter/interpreter.cpp
lib/interpreter/interpreter.cpp
+1
-4
未找到文件。
include/runtime/instance/type.h
浏览文件 @
ccd18560
...
@@ -41,8 +41,6 @@ struct FType {
...
@@ -41,8 +41,6 @@ struct FType {
/// Getter of symbol
/// Getter of symbol
const
auto
&
getSymbol
()
const
noexcept
{
return
Symbol
;
}
const
auto
&
getSymbol
()
const
noexcept
{
return
Symbol
;
}
/// Setter of symbol
void
setSymbol
(
Loader
::
Symbol
<
Wrapper
>
S
)
{
Symbol
=
std
::
move
(
S
);
}
std
::
vector
<
ValType
>
Params
;
std
::
vector
<
ValType
>
Params
;
std
::
vector
<
ValType
>
Returns
;
std
::
vector
<
ValType
>
Returns
;
...
...
include/runtime/storemgr.h
浏览文件 @
ccd18560
...
@@ -55,27 +55,33 @@ public:
...
@@ -55,27 +55,33 @@ public:
~
StoreManager
()
=
default
;
~
StoreManager
()
=
default
;
/// Import instances and move owner to store manager.
/// Import instances and move owner to store manager.
uint32_t
importModule
(
std
::
unique_ptr
<
Instance
::
ModuleInstance
>
Mod
)
{
template
<
typename
...
Args
>
uint32_t
importModule
(
Args
&&
...
Values
)
{
Mod
->
Addr
=
ModInsts
.
size
();
uint32_t
ModAddr
=
return
importInstance
(
std
::
move
(
Mod
),
ImpModInsts
,
ModInsts
);
importInstance
(
ImpModInsts
,
ModInsts
,
std
::
forward
<
Args
>
(
Values
)...);
ModInsts
.
back
()
->
Addr
=
ModAddr
;
return
ModAddr
;
}
}
uint32_t
importFunction
(
std
::
unique_ptr
<
Instance
::
FunctionInstance
>
Func
)
{
template
<
typename
...
Args
>
uint32_t
importFunction
(
Args
&&
...
Values
)
{
return
importInstance
(
std
::
move
(
Func
),
ImpFuncInsts
,
FuncInsts
);
return
importInstance
(
ImpFuncInsts
,
FuncInsts
,
std
::
forward
<
Args
>
(
Values
)...);
}
}
uint32_t
importTable
(
std
::
unique_ptr
<
Instance
::
TableInstance
>
Tab
)
{
template
<
typename
...
Args
>
uint32_t
importTable
(
Args
&&
...
Values
)
{
return
importInstance
(
std
::
move
(
Tab
),
ImpTabInsts
,
TabInsts
);
return
importInstance
(
ImpTabInsts
,
TabInsts
,
std
::
forward
<
Args
>
(
Values
)...
);
}
}
uint32_t
importMemory
(
std
::
unique_ptr
<
Instance
::
MemoryInstance
>
Mem
)
{
template
<
typename
...
Args
>
uint32_t
importMemory
(
Args
&&
...
Values
)
{
return
importInstance
(
std
::
move
(
Mem
),
ImpMemInsts
,
MemInsts
);
return
importInstance
(
ImpMemInsts
,
MemInsts
,
std
::
forward
<
Args
>
(
Values
)...
);
}
}
uint32_t
importGlobal
(
std
::
unique_ptr
<
Instance
::
GlobalInstance
>
Glob
)
{
template
<
typename
...
Args
>
uint32_t
importGlobal
(
Args
&&
...
Values
)
{
return
importInstance
(
std
::
move
(
Glob
),
ImpGlobInsts
,
GlobInsts
);
return
importInstance
(
ImpGlobInsts
,
GlobInsts
,
std
::
forward
<
Args
>
(
Values
)...);
}
}
uint32_t
importElement
(
std
::
unique_ptr
<
Instance
::
ElementInstance
>
Elem
)
{
template
<
typename
...
Args
>
uint32_t
importElement
(
Args
&&
...
Values
)
{
return
importInstance
(
std
::
move
(
Elem
),
ImpElemInsts
,
ElemInsts
);
return
importInstance
(
ImpElemInsts
,
ElemInsts
,
std
::
forward
<
Args
>
(
Values
)...);
}
}
uint32_t
importData
(
std
::
unique_ptr
<
Instance
::
DataInstance
>
Data
)
{
template
<
typename
...
Args
>
uint32_t
importData
(
Args
&&
...
Values
)
{
return
importInstance
(
std
::
move
(
Data
),
ImpDataInsts
,
DataInsts
);
return
importInstance
(
ImpDataInsts
,
DataInsts
,
std
::
forward
<
Args
>
(
Values
)...);
}
}
/// Import host instances but not move ownership.
/// Import host instances but not move ownership.
...
@@ -93,34 +99,40 @@ public:
...
@@ -93,34 +99,40 @@ public:
}
}
/// Insert instances for instantiation and move ownership to store manager.
/// Insert instances for instantiation and move ownership to store manager.
uint32_t
pushModule
(
std
::
unique_ptr
<
Instance
::
ModuleInstance
>
Mod
)
{
template
<
typename
...
Args
>
uint32_t
pushModule
(
Args
&&
...
Values
)
{
++
NumMod
;
++
NumMod
;
Mod
->
Addr
=
ModInsts
.
size
();
uint32_t
ModAddr
=
return
importInstance
(
std
::
move
(
Mod
),
ImpModInsts
,
ModInsts
);
importInstance
(
ImpModInsts
,
ModInsts
,
std
::
forward
<
Args
>
(
Values
)...);
ModInsts
.
back
()
->
Addr
=
ModAddr
;
return
ModAddr
;
}
}
uint32_t
pushFunction
(
std
::
unique_ptr
<
Instance
::
FunctionInstance
>
Func
)
{
template
<
typename
...
Args
>
uint32_t
pushFunction
(
Args
&&
...
Values
)
{
++
NumFunc
;
++
NumFunc
;
return
importInstance
(
std
::
move
(
Func
),
ImpFuncInsts
,
FuncInsts
);
return
importInstance
(
ImpFuncInsts
,
FuncInsts
,
std
::
forward
<
Args
>
(
Values
)...);
}
}
uint32_t
pushTable
(
std
::
unique_ptr
<
Instance
::
TableInstance
>
Tab
)
{
template
<
typename
...
Args
>
uint32_t
pushTable
(
Args
&&
...
Values
)
{
++
NumTab
;
++
NumTab
;
return
importInstance
(
std
::
move
(
Tab
),
ImpTabInsts
,
TabInsts
);
return
importInstance
(
ImpTabInsts
,
TabInsts
,
std
::
forward
<
Args
>
(
Values
)...
);
}
}
uint32_t
pushMemory
(
std
::
unique_ptr
<
Instance
::
MemoryInstance
>
Mem
)
{
template
<
typename
...
Args
>
uint32_t
pushMemory
(
Args
&&
...
Values
)
{
++
NumMem
;
++
NumMem
;
return
importInstance
(
std
::
move
(
Mem
),
ImpMemInsts
,
MemInsts
);
return
importInstance
(
ImpMemInsts
,
MemInsts
,
std
::
forward
<
Args
>
(
Values
)...
);
}
}
uint32_t
pushGlobal
(
std
::
unique_ptr
<
Instance
::
GlobalInstance
>
Glob
)
{
template
<
typename
...
Args
>
uint32_t
pushGlobal
(
Args
&&
...
Values
)
{
++
NumGlob
;
++
NumGlob
;
return
importInstance
(
std
::
move
(
Glob
),
ImpGlobInsts
,
GlobInsts
);
return
importInstance
(
ImpGlobInsts
,
GlobInsts
,
std
::
forward
<
Args
>
(
Values
)...);
}
}
uint32_t
pushElement
(
std
::
unique_ptr
<
Instance
::
ElementInstance
>
Elem
)
{
template
<
typename
...
Args
>
uint32_t
pushElement
(
Args
&&
...
Values
)
{
++
NumElem
;
++
NumElem
;
return
importInstance
(
std
::
move
(
Elem
),
ImpElemInsts
,
ElemInsts
);
return
importInstance
(
ImpElemInsts
,
ElemInsts
,
std
::
forward
<
Args
>
(
Values
)...);
}
}
uint32_t
pushData
(
std
::
unique_ptr
<
Instance
::
DataInstance
>
Data
)
{
template
<
typename
...
Args
>
uint32_t
pushData
(
Args
&&
...
Values
)
{
++
NumData
;
++
NumData
;
return
importInstance
(
std
::
move
(
Data
),
ImpDataInsts
,
DataInsts
);
return
importInstance
(
ImpDataInsts
,
DataInsts
,
std
::
forward
<
Args
>
(
Values
)...);
}
}
/// Pop temp. module. Dangerous function for used when instantiating only.
/// Pop temp. module. Dangerous function for used when instantiating only.
...
@@ -266,14 +278,13 @@ public:
...
@@ -266,14 +278,13 @@ public:
private:
private:
/// Helper function for importing instances and move ownership.
/// Helper function for importing instances and move ownership.
template
<
typename
T
>
template
<
typename
T
,
typename
...
Args
>
std
::
enable_if_t
<
IsInstanceV
<
T
>
,
uint32_t
>
std
::
enable_if_t
<
IsInstanceV
<
T
>
,
uint32_t
>
importInstance
(
std
::
unique_ptr
<
T
>
Inst
,
importInstance
(
std
::
vector
<
std
::
unique_ptr
<
T
>>
&
ImpInstsVec
,
std
::
vector
<
std
::
unique_ptr
<
T
>>
&
ImpInstsVec
,
std
::
vector
<
T
*>
&
InstsVec
,
Args
&&
...
Values
)
{
std
::
vector
<
T
*>
&
InstsVec
)
{
uint32_t
Addr
=
InstsVec
.
size
();
uint32_t
Addr
=
InstsVec
.
size
();
I
nstsVec
.
push_back
(
Inst
.
get
(
));
I
mpInstsVec
.
push_back
(
std
::
make_unique
<
T
>
(
std
::
forward
<
Args
>
(
Values
)...
));
I
mpInstsVec
.
push_back
(
std
::
move
(
Inst
));
I
nstsVec
.
push_back
(
ImpInstsVec
.
back
().
get
(
));
return
Addr
;
return
Addr
;
}
}
...
...
lib/interpreter/instantiate/data.cpp
浏览文件 @
ccd18560
...
@@ -42,16 +42,12 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
...
@@ -42,16 +42,12 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
}
}
}
}
/// Make a new data instance.
auto
NewDataInst
=
std
::
make_unique
<
Runtime
::
Instance
::
DataInstance
>
(
Offset
,
DataSeg
.
getData
());
/// Insert data instance to store manager.
/// Insert data instance to store manager.
uint32_t
NewDataInstAddr
;
uint32_t
NewDataInstAddr
;
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
NewDataInstAddr
=
StoreMgr
.
pushData
(
std
::
move
(
NewDataInst
));
NewDataInstAddr
=
StoreMgr
.
pushData
(
Offset
,
DataSeg
.
getData
(
));
}
else
{
}
else
{
NewDataInstAddr
=
StoreMgr
.
importData
(
std
::
move
(
NewDataInst
));
NewDataInstAddr
=
StoreMgr
.
importData
(
Offset
,
DataSeg
.
getData
(
));
}
}
ModInst
.
addDataAddr
(
NewDataInstAddr
);
ModInst
.
addDataAddr
(
NewDataInstAddr
);
}
}
...
...
lib/interpreter/instantiate/elem.cpp
浏览文件 @
ccd18560
...
@@ -53,16 +53,14 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
...
@@ -53,16 +53,14 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
}
}
}
}
/// Make a new element instance.
auto
NewElemInst
=
std
::
make_unique
<
Runtime
::
Instance
::
ElementInstance
>
(
Offset
,
ElemSeg
.
getRefType
(),
InitVals
);
/// Insert element instance to store manager.
/// Insert element instance to store manager.
uint32_t
NewElemInstAddr
;
uint32_t
NewElemInstAddr
;
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
NewElemInstAddr
=
StoreMgr
.
pushElement
(
std
::
move
(
NewElemInst
));
NewElemInstAddr
=
StoreMgr
.
pushElement
(
Offset
,
ElemSeg
.
getRefType
(),
InitVals
);
}
else
{
}
else
{
NewElemInstAddr
=
StoreMgr
.
importElement
(
std
::
move
(
NewElemInst
));
NewElemInstAddr
=
StoreMgr
.
importElement
(
Offset
,
ElemSeg
.
getRefType
(),
InitVals
);
}
}
ModInst
.
addElemAddr
(
NewElemInstAddr
);
ModInst
.
addElemAddr
(
NewElemInstAddr
);
}
}
...
...
lib/interpreter/instantiate/function.cpp
浏览文件 @
ccd18560
...
@@ -18,22 +18,27 @@ Expect<void> Interpreter::instantiate(
...
@@ -18,22 +18,27 @@ Expect<void> Interpreter::instantiate(
/// Iterate through code segments to make function instances.
/// Iterate through code segments to make function instances.
for
(
uint32_t
I
=
0
;
I
<
CodeSegs
.
size
();
++
I
)
{
for
(
uint32_t
I
=
0
;
I
<
CodeSegs
.
size
();
++
I
)
{
/// Make a new function instance.
auto
*
FuncType
=
*
ModInst
.
getFuncType
(
TypeIdxs
[
I
]);
auto
NewFuncInst
=
std
::
make_unique
<
Runtime
::
Instance
::
FunctionInstance
>
(
ModInst
.
Addr
,
*
FuncType
,
CodeSegs
[
I
].
getLocals
(),
CodeSegs
[
I
].
getInstrs
());
if
(
auto
Symbol
=
CodeSegs
[
I
].
getSymbol
())
{
NewFuncInst
->
setSymbol
(
std
::
move
(
Symbol
));
}
/// Insert function instance to store manager.
/// Insert function instance to store manager.
uint32_t
NewFuncInstAddr
;
uint32_t
NewFuncInstAddr
;
auto
*
FuncType
=
*
ModInst
.
getFuncType
(
TypeIdxs
[
I
]);
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
NewFuncInstAddr
=
StoreMgr
.
pushFunction
(
std
::
move
(
NewFuncInst
));
if
(
auto
Symbol
=
CodeSegs
[
I
].
getSymbol
())
{
NewFuncInstAddr
=
StoreMgr
.
pushFunction
(
ModInst
.
Addr
,
*
FuncType
,
std
::
move
(
Symbol
));
}
else
{
NewFuncInstAddr
=
StoreMgr
.
pushFunction
(
ModInst
.
Addr
,
*
FuncType
,
CodeSegs
[
I
].
getLocals
(),
CodeSegs
[
I
].
getInstrs
());
}
}
else
{
}
else
{
NewFuncInstAddr
=
StoreMgr
.
importFunction
(
std
::
move
(
NewFuncInst
));
if
(
auto
Symbol
=
CodeSegs
[
I
].
getSymbol
())
{
NewFuncInstAddr
=
StoreMgr
.
importFunction
(
ModInst
.
Addr
,
*
FuncType
,
std
::
move
(
Symbol
));
}
else
{
NewFuncInstAddr
=
StoreMgr
.
importFunction
(
ModInst
.
Addr
,
*
FuncType
,
CodeSegs
[
I
].
getLocals
(),
CodeSegs
[
I
].
getInstrs
());
}
}
}
ModInst
.
addFuncAddr
(
NewFuncInstAddr
);
ModInst
.
addFuncAddr
(
NewFuncInstAddr
);
}
}
...
...
lib/interpreter/instantiate/global.cpp
浏览文件 @
ccd18560
...
@@ -15,10 +15,17 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
...
@@ -15,10 +15,17 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
/// A frame with temp. module is pushed into stack outside.
/// A frame with temp. module is pushed into stack outside.
/// Instantiate and initialize globals.
/// Instantiate and initialize globals.
for
(
const
auto
&
GlobSeg
:
GlobSec
.
getContent
())
{
for
(
const
auto
&
GlobSeg
:
GlobSec
.
getContent
())
{
///
Make a new global instance
.
///
Insert global instance to store manager
.
const
auto
&
GlobType
=
GlobSeg
.
getGlobalType
();
const
auto
&
GlobType
=
GlobSeg
.
getGlobalType
();
auto
NewGlobInst
=
std
::
make_unique
<
Runtime
::
Instance
::
GlobalInstance
>
(
uint32_t
NewGlobInstAddr
;
GlobType
.
getValueType
(),
GlobType
.
getValueMutation
());
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
NewGlobInstAddr
=
StoreMgr
.
pushGlobal
(
GlobType
.
getValueType
(),
GlobType
.
getValueMutation
());
}
else
{
NewGlobInstAddr
=
StoreMgr
.
importGlobal
(
GlobType
.
getValueType
(),
GlobType
.
getValueMutation
());
}
ModInst
.
addGlobalAddr
(
NewGlobInstAddr
);
/// Run initialize expression.
/// Run initialize expression.
if
(
auto
Res
=
runExpression
(
StoreMgr
,
GlobSeg
.
getInstrs
());
!
Res
)
{
if
(
auto
Res
=
runExpression
(
StoreMgr
,
GlobSeg
.
getInstrs
());
!
Res
)
{
...
@@ -27,16 +34,8 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
...
@@ -27,16 +34,8 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
}
}
/// Pop result from stack.
/// Pop result from stack.
auto
*
NewGlobInst
=
*
StoreMgr
.
getGlobal
(
NewGlobInstAddr
);
NewGlobInst
->
getValue
()
=
StackMgr
.
pop
();
NewGlobInst
->
getValue
()
=
StackMgr
.
pop
();
/// Insert global instance to store manager.
uint32_t
NewGlobInstAddr
;
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
NewGlobInstAddr
=
StoreMgr
.
pushGlobal
(
std
::
move
(
NewGlobInst
));
}
else
{
NewGlobInstAddr
=
StoreMgr
.
importGlobal
(
std
::
move
(
NewGlobInst
));
}
ModInst
.
addGlobalAddr
(
NewGlobInstAddr
);
}
}
return
{};
return
{};
}
}
...
...
lib/interpreter/instantiate/memory.cpp
浏览文件 @
ccd18560
...
@@ -14,16 +14,12 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
...
@@ -14,16 +14,12 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
const
AST
::
MemorySection
&
MemSec
)
{
const
AST
::
MemorySection
&
MemSec
)
{
/// Iterate and istantiate memory types.
/// Iterate and istantiate memory types.
for
(
const
auto
&
MemType
:
MemSec
.
getContent
())
{
for
(
const
auto
&
MemType
:
MemSec
.
getContent
())
{
/// Make a new memory instance.
auto
NewMemInst
=
std
::
make_unique
<
Runtime
::
Instance
::
MemoryInstance
>
(
MemType
.
getLimit
());
/// Insert memory instance to store manager.
/// Insert memory instance to store manager.
uint32_t
NewMemInstAddr
;
uint32_t
NewMemInstAddr
;
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
NewMemInstAddr
=
StoreMgr
.
pushMemory
(
std
::
move
(
NewMemInst
));
NewMemInstAddr
=
StoreMgr
.
pushMemory
(
MemType
.
getLimit
(
));
}
else
{
}
else
{
NewMemInstAddr
=
StoreMgr
.
importMemory
(
std
::
move
(
NewMemInst
));
NewMemInstAddr
=
StoreMgr
.
importMemory
(
MemType
.
getLimit
(
));
}
}
ModInst
.
addMemAddr
(
NewMemInstAddr
);
ModInst
.
addMemAddr
(
NewMemInstAddr
);
}
}
...
...
lib/interpreter/instantiate/module.cpp
浏览文件 @
ccd18560
...
@@ -22,14 +22,13 @@ Expect<void> Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
...
@@ -22,14 +22,13 @@ Expect<void> Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
LOG
(
ERROR
)
<<
ErrInfo
::
InfoAST
(
Mod
.
NodeAttr
);
LOG
(
ERROR
)
<<
ErrInfo
::
InfoAST
(
Mod
.
NodeAttr
);
return
Unexpect
(
ErrCode
::
ModuleNameConflict
);
return
Unexpect
(
ErrCode
::
ModuleNameConflict
);
}
}
auto
NewModInst
=
std
::
make_unique
<
Runtime
::
Instance
::
ModuleInstance
>
(
Name
);
/// Insert the module instance to store manager and retrieve instance.
/// Insert the module instance to store manager and retrieve instance.
uint32_t
ModInstAddr
;
uint32_t
ModInstAddr
;
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
ModInstAddr
=
StoreMgr
.
pushModule
(
std
::
move
(
NewModInst
)
);
ModInstAddr
=
StoreMgr
.
pushModule
(
Name
);
}
else
{
}
else
{
ModInstAddr
=
StoreMgr
.
importModule
(
std
::
move
(
NewModInst
)
);
ModInstAddr
=
StoreMgr
.
importModule
(
Name
);
}
}
auto
*
ModInst
=
*
StoreMgr
.
getModule
(
ModInstAddr
);
auto
*
ModInst
=
*
StoreMgr
.
getModule
(
ModInstAddr
);
...
@@ -74,14 +73,14 @@ Expect<void> Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
...
@@ -74,14 +73,14 @@ Expect<void> Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
}
}
/// Add a temp module to Store with only imported globals for initialization.
/// Add a temp module to Store with only imported globals for initialization.
auto
TmpMod
=
std
::
make_unique
<
Runtime
::
Instance
::
ModuleInstance
>
(
""
);
uint32_t
TmpModInstAddr
=
StoreMgr
.
pushModule
(
""
);
auto
*
TmpModInst
=
*
StoreMgr
.
getModule
(
TmpModInstAddr
);
for
(
uint32_t
I
=
0
;
I
<
ModInst
->
getGlobalImportNum
();
++
I
)
{
for
(
uint32_t
I
=
0
;
I
<
ModInst
->
getGlobalImportNum
();
++
I
)
{
TmpMod
->
importGlobal
(
*
(
ModInst
->
getGlobalAddr
(
I
)));
TmpMod
Inst
->
importGlobal
(
*
(
ModInst
->
getGlobalAddr
(
I
)));
}
}
for
(
uint32_t
I
=
0
;
I
<
ModInst
->
getFuncNum
();
++
I
)
{
for
(
uint32_t
I
=
0
;
I
<
ModInst
->
getFuncNum
();
++
I
)
{
TmpMod
->
importFunction
(
*
(
ModInst
->
getFuncAddr
(
I
)));
TmpMod
Inst
->
importFunction
(
*
(
ModInst
->
getFuncAddr
(
I
)));
}
}
uint32_t
TmpModInstAddr
=
StoreMgr
.
pushModule
(
std
::
move
(
TmpMod
));
/// Push a new frame {TmpModInst:{globaddrs}, locals:none}
/// Push a new frame {TmpModInst:{globaddrs}, locals:none}
StackMgr
.
pushFrame
(
TmpModInstAddr
,
0
,
0
);
StackMgr
.
pushFrame
(
TmpModInstAddr
,
0
,
0
);
...
...
lib/interpreter/instantiate/table.cpp
浏览文件 @
ccd18560
...
@@ -14,16 +14,14 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
...
@@ -14,16 +14,14 @@ Interpreter::instantiate(Runtime::StoreManager &StoreMgr,
const
AST
::
TableSection
&
TabSec
)
{
const
AST
::
TableSection
&
TabSec
)
{
/// Iterate and instantiate table types.
/// Iterate and instantiate table types.
for
(
const
auto
&
TabType
:
TabSec
.
getContent
())
{
for
(
const
auto
&
TabType
:
TabSec
.
getContent
())
{
/// Make a new table instance.
auto
NewTabInst
=
std
::
make_unique
<
Runtime
::
Instance
::
TableInstance
>
(
TabType
.
getReferenceType
(),
TabType
.
getLimit
());
/// Insert table instance to store manager.
/// Insert table instance to store manager.
uint32_t
NewTabInstAddr
;
uint32_t
NewTabInstAddr
;
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
if
(
InsMode
==
InstantiateMode
::
Instantiate
)
{
NewTabInstAddr
=
StoreMgr
.
pushTable
(
std
::
move
(
NewTabInst
));
NewTabInstAddr
=
StoreMgr
.
pushTable
(
TabType
.
getReferenceType
(),
TabType
.
getLimit
());
}
else
{
}
else
{
NewTabInstAddr
=
StoreMgr
.
importTable
(
std
::
move
(
NewTabInst
));
NewTabInstAddr
=
StoreMgr
.
importTable
(
TabType
.
getReferenceType
(),
TabType
.
getLimit
());
}
}
ModInst
.
addTableAddr
(
NewTabInstAddr
);
ModInst
.
addTableAddr
(
NewTabInstAddr
);
}
}
...
...
lib/interpreter/interpreter.cpp
浏览文件 @
ccd18560
...
@@ -32,13 +32,10 @@ Expect<void> Interpreter::registerModule(Runtime::StoreManager &StoreMgr,
...
@@ -32,13 +32,10 @@ Expect<void> Interpreter::registerModule(Runtime::StoreManager &StoreMgr,
LOG
(
ERROR
)
<<
ErrInfo
::
InfoRegistering
(
Obj
.
getModuleName
());
LOG
(
ERROR
)
<<
ErrInfo
::
InfoRegistering
(
Obj
.
getModuleName
());
return
Unexpect
(
ErrCode
::
ModuleNameConflict
);
return
Unexpect
(
ErrCode
::
ModuleNameConflict
);
}
}
auto
NewModInst
=
auto
ModInstAddr
=
StoreMgr
.
importModule
(
Obj
.
getModuleName
());
std
::
make_unique
<
Runtime
::
Instance
::
ModuleInstance
>
(
Obj
.
getModuleName
());
auto
ModInstAddr
=
StoreMgr
.
importModule
(
std
::
move
(
NewModInst
));
auto
*
ModInst
=
*
StoreMgr
.
getModule
(
ModInstAddr
);
auto
*
ModInst
=
*
StoreMgr
.
getModule
(
ModInstAddr
);
for
(
auto
&
Func
:
Obj
.
getFuncs
())
{
for
(
auto
&
Func
:
Obj
.
getFuncs
())
{
Func
.
second
->
setModuleAddr
(
ModInstAddr
);
uint32_t
Addr
=
StoreMgr
.
importHostFunction
(
*
Func
.
second
.
get
());
uint32_t
Addr
=
StoreMgr
.
importHostFunction
(
*
Func
.
second
.
get
());
ModInst
->
addFuncAddr
(
Addr
);
ModInst
->
addFuncAddr
(
Addr
);
ModInst
->
exportFunction
(
Func
.
first
,
ModInst
->
getFuncNum
()
-
1
);
ModInst
->
exportFunction
(
Func
.
first
,
ModInst
->
getFuncNum
()
-
1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录