提交 8aceedb3 编写于 作者: Y YiYing He 提交者: Yi-Ying He

[VM] Simplify the cost table class.

上级 ae768d2b
......@@ -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
......
......@@ -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
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册