Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce4f0fc
commit 82b4b5b
Showing
15 changed files
with
590 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
#include "../prilib/include/lightlist.h" | ||
#include "config.h" | ||
#include "typeinfo.h" | ||
|
||
namespace CVM | ||
{ | ||
struct FunctionInfo | ||
{ | ||
public: | ||
using ArgList = PriLib::lightlist<Config::RegisterIndexType>; | ||
using TypeList = PriLib::lightlist<TypeIndex>; | ||
|
||
public: | ||
FunctionInfo() = default; | ||
FunctionInfo(const FunctionInfo &info) = default; | ||
|
||
explicit FunctionInfo(Config::RegisterIndexType &&dysize, TypeList &&stvarb_typelist, ArgList &&arglist) : | ||
_dyvarb_count(std::move(dysize)), | ||
stvarb_typelist(std::move(stvarb_typelist)), | ||
arglist(std::move(arglist)) {} | ||
|
||
explicit FunctionInfo(FunctionInfo &&info) : | ||
_dyvarb_count(std::move(info._dyvarb_count)), | ||
stvarb_typelist(std::move(info.stvarb_typelist)), | ||
arglist(std::move(info.arglist)) {} | ||
|
||
public: | ||
Config::RegisterIndexType _dyvarb_count = 0; | ||
TypeList stvarb_typelist; | ||
ArgList arglist; | ||
|
||
public: | ||
bool is_dyvarb(Config::RegisterIndexType index) const { | ||
return Config::is_dynamic(index, dyvarb_count(), stvarb_count()); | ||
} | ||
bool is_stvarb(Config::RegisterIndexType index) const { | ||
return Config::is_static(index, dyvarb_count(), stvarb_count()); | ||
} | ||
TypeIndex get_stvarb_type(Config::RegisterIndexType index) const { | ||
return stvarb_typelist.at(Config::get_static_id(index, dyvarb_count(), stvarb_count())); | ||
} | ||
|
||
Config::RegisterIndexType dyvarb_count() const { | ||
return _dyvarb_count; | ||
} | ||
Config::RegisterIndexType stvarb_count() const { | ||
return Config::convertToRegisterIndexType(stvarb_typelist.size()); | ||
} | ||
Config::RegisterIndexType regsize() const { | ||
return dyvarb_count() + stvarb_count(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,33 @@ | ||
#pragma once | ||
#include "functioninfo.h" | ||
#include "funcinfo.h" | ||
#include "config.h" | ||
#include "instruction.h" | ||
|
||
namespace CVM | ||
{ | ||
namespace InstStruct | ||
{ | ||
class Function | ||
using InstList = std::vector<Instruction*>; // TODO | ||
|
||
struct Function : public FunctionInfo | ||
{ | ||
public: | ||
explicit Function(FunctionInfo &&info) | ||
: _info(std::move(info)) {} | ||
explicit Function() = default; | ||
explicit Function(const Function &info) = default; | ||
|
||
const InstList& instlist() const { | ||
return _info.instdata; | ||
} | ||
explicit Function(Function &&info) | ||
: instdata(info.instdata), FunctionInfo(std::move(info)) {} | ||
|
||
bool is_dyvarb(Config::RegisterIndexType index) const { | ||
return Config::is_dynamic(index, dyvarb_count(), stvarb_count()); | ||
} | ||
bool is_stvarb(Config::RegisterIndexType index) const { | ||
return Config::is_static(index, dyvarb_count(), stvarb_count()); | ||
} | ||
TypeIndex get_stvarb_type(Config::RegisterIndexType index) const { | ||
return _info.stvarb_typelist.at(Config::get_static_id(index, dyvarb_count(), stvarb_count())); | ||
} | ||
const TypeList& stvarb_typelist() const { | ||
return _info.stvarb_typelist; | ||
} | ||
const ArgList& arglist() const { | ||
return _info.arglist; | ||
} | ||
explicit Function(InstList &&il, Config::RegisterIndexType &&dysize, TypeList &&stvarb_typelist, ArgList &&arglist) : | ||
instdata(std::move(il)), | ||
FunctionInfo(std::move(dysize), std::move(stvarb_typelist), std::move(arglist)) {} | ||
|
||
Config::RegisterIndexType dyvarb_count() const { | ||
return _info.dyvarb_count; | ||
} | ||
Config::RegisterIndexType stvarb_count() const { | ||
return Config::convertToRegisterIndexType(_info.stvarb_typelist.size()); | ||
~Function() { | ||
for (auto &p : instdata) | ||
if (p) | ||
delete p; | ||
} | ||
|
||
private: | ||
FunctionInfo _info; | ||
InstList instdata; | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
#include "basic.h" | ||
#include "function.h" | ||
|
||
namespace CVM | ||
{ | ||
namespace InstStruct | ||
{ | ||
struct IdentKeyTable | ||
{ | ||
using FuncPtr = std::shared_ptr<InstStruct::Function>; | ||
|
||
bool hasKey(const std::string &key) { | ||
return keytable.find(key) != keytable.end(); | ||
} | ||
bool insert(const std::string &key) { | ||
if (!hasKey(key)) { | ||
_insert(key); | ||
return true; | ||
} | ||
return false; | ||
} | ||
size_t getID(const std::string &key) { | ||
auto iter = keytable.find(key); | ||
if (iter == keytable.end()) { | ||
return _insert(key); | ||
} | ||
return iter->second; | ||
} | ||
auto& getData(size_t id) { | ||
return functable.at(id); | ||
} | ||
auto& getData(const std::string &key) { | ||
return getData(getID(key)); | ||
} | ||
/*auto begin() const { | ||
return functable.begin(); | ||
} | ||
auto end() const { | ||
return functable.end(); | ||
}*/ | ||
|
||
template <typename _FTy> | ||
void each(_FTy f) { | ||
for (auto pair : keytable) { | ||
f(pair.second, functable.at(pair.second)); | ||
} | ||
} | ||
|
||
private: | ||
std::map<std::string, size_t> keytable; | ||
std::vector<FuncPtr> functable; | ||
|
||
size_t _insert(const std::string &key) { | ||
size_t id = keytable.size(); | ||
keytable.insert({ key, id }); | ||
while (functable.size() <= id) | ||
functable.push_back(nullptr); | ||
return id; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.