update plugins to read YAML file
This commit is contained in:
@ -33,18 +33,12 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "cycle_estimate.h"
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include <iss/arch_if.h>
|
||||
#include <util/logging.h>
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/istreamwrapper.h>
|
||||
#include <rapidjson/writer.h>
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
#include <rapidjson/ostreamwrapper.h>
|
||||
#include <rapidjson/error/en.h>
|
||||
#include <fstream>
|
||||
|
||||
using namespace rapidjson;
|
||||
using namespace std;
|
||||
|
||||
iss::plugin::cycle_estimate::cycle_estimate(string const& config_file_name)
|
||||
@ -61,40 +55,31 @@ bool iss::plugin::cycle_estimate::registration(const char* const version, vm_if&
|
||||
if(!instr_if) return false;
|
||||
const string core_name = instr_if->core_type_name();
|
||||
if (config_file_name.length() > 0) {
|
||||
ifstream is(config_file_name);
|
||||
std::ifstream is(config_file_name);
|
||||
if (is.is_open()) {
|
||||
try {
|
||||
IStreamWrapper isw(is);
|
||||
Document d;
|
||||
ParseResult ok = d.ParseStream(isw);
|
||||
if(ok) {
|
||||
Value& val = d[core_name.c_str()];
|
||||
if(val.IsArray()){
|
||||
delays.reserve(val.Size());
|
||||
for (auto it = val.Begin(); it != val.End(); ++it) {
|
||||
auto& name = (*it)["name"];
|
||||
auto& size = (*it)["size"];
|
||||
auto& delay = (*it)["delay"];
|
||||
auto& branch = (*it)["branch"];
|
||||
if(delay.IsArray()) {
|
||||
auto dt = delay[0].Get<unsigned>();
|
||||
auto dnt = delay[1].Get<unsigned>();
|
||||
delays.push_back(instr_desc{size.Get<unsigned>(), dt, dnt, branch.Get<bool>()});
|
||||
} else if(delay.Is<unsigned>()) {
|
||||
auto d = delay.Get<unsigned>();
|
||||
delays.push_back(instr_desc{size.Get<unsigned>(), d, d, branch.Get<bool>()});
|
||||
} else
|
||||
throw runtime_error("JSON parse error");
|
||||
}
|
||||
} else {
|
||||
LOG(ERR)<<"plugin cycle_estimate: could not find an entry for "<<core_name<<" in JSON file"<<endl;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
LOG(ERR)<<"plugin cycle_estimate: could not parse in JSON file at "<< ok.Offset()<<": "<<GetParseError_En(ok.Code())<<endl;
|
||||
return false;
|
||||
}
|
||||
} catch (runtime_error &e) {
|
||||
auto root = YAML::LoadAll(is);
|
||||
if(root.size()!=1) {
|
||||
LOG(ERR) << "Too many rro nodes in YAML file " << config_file_name;
|
||||
}
|
||||
for (auto p : root[0]) {
|
||||
auto isa_subset = p.first;
|
||||
auto instructions = p.second;
|
||||
for (auto const& instr : instructions) {
|
||||
instr_desc res;
|
||||
res.is_branch = instr.second["branch"].as<bool>();
|
||||
auto delay = instr.second["delay"];
|
||||
if(delay.IsSequence()) {
|
||||
res.not_taken = delay[0].as<uint64_t>();
|
||||
res.taken = delay[1].as<uint64_t>();
|
||||
} else {
|
||||
res.not_taken = delay.as<uint64_t>();
|
||||
res.taken = res.not_taken;
|
||||
}
|
||||
delays.push_back(std::move(res));
|
||||
}
|
||||
}
|
||||
} catch (YAML::ParserException &e) {
|
||||
LOG(ERR) << "Could not parse input file " << config_file_name << ", reason: " << e.what();
|
||||
return false;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
#include "instruction_count.h"
|
||||
#include <iss/instrumentation_if.h>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include <iss/arch_if.h>
|
||||
#include <util/logging.h>
|
||||
@ -44,8 +45,30 @@ iss::plugin::instruction_count::instruction_count(std::string config_file_name)
|
||||
std::ifstream is(config_file_name);
|
||||
if (is.is_open()) {
|
||||
try {
|
||||
is >> root;
|
||||
} catch (Json::RuntimeError &e) {
|
||||
auto root = YAML::LoadAll(is);
|
||||
if(root.size()!=1) {
|
||||
LOG(ERR) << "Too many rro nodes in YAML file " << config_file_name;
|
||||
}
|
||||
for (auto p : root[0]) {
|
||||
auto isa_subset = p.first;
|
||||
auto instructions = p.second;
|
||||
for (auto const& instr : instructions) {
|
||||
instr_delay res;
|
||||
res.instr_name = instr.first.as<std::string>();
|
||||
res.size = instr.second["encoding"].as<std::string>().size()-2; // not counting 0b
|
||||
auto delay = instr.second["delay"];
|
||||
if(delay.IsSequence()) {
|
||||
res.not_taken_delay = delay[0].as<uint64_t>();
|
||||
res.taken_delay = delay[1].as<uint64_t>();
|
||||
} else {
|
||||
res.not_taken_delay = delay.as<uint64_t>();
|
||||
res.taken_delay = res.not_taken_delay;
|
||||
}
|
||||
delays.push_back(std::move(res));
|
||||
}
|
||||
}
|
||||
rep_counts.resize(delays.size());
|
||||
} catch (YAML::ParserException &e) {
|
||||
LOG(ERR) << "Could not parse input file " << config_file_name << ", reason: " << e.what();
|
||||
}
|
||||
} else {
|
||||
@ -57,7 +80,7 @@ iss::plugin::instruction_count::instruction_count(std::string config_file_name)
|
||||
iss::plugin::instruction_count::~instruction_count() {
|
||||
size_t idx=0;
|
||||
for(auto it:delays){
|
||||
if(rep_counts[idx]>0)
|
||||
if(rep_counts[idx]>0 && it.instr_name.find("__"!=0))
|
||||
LOG(INFO)<<it.instr_name<<";"<<rep_counts[idx];
|
||||
idx++;
|
||||
}
|
||||
@ -66,27 +89,6 @@ iss::plugin::instruction_count::~instruction_count() {
|
||||
bool iss::plugin::instruction_count::registration(const char* const version, vm_if& vm) {
|
||||
auto instr_if = vm.get_arch()->get_instrumentation_if();
|
||||
if(!instr_if) return false;
|
||||
const std::string core_name = instr_if->core_type_name();
|
||||
Json::Value &val = root[core_name];
|
||||
if(!val.isNull() && val.isArray()){
|
||||
delays.reserve(val.size());
|
||||
for(auto it:val){
|
||||
auto name = it["name"];
|
||||
auto size = it["size"];
|
||||
auto delay = it["delay"];
|
||||
if(!name.isString() || !size.isUInt() || !(delay.isUInt() || delay.isArray())) throw std::runtime_error("JSON parse error");
|
||||
if(delay.isUInt()){
|
||||
const instr_delay entry{name.asCString(), size.asUInt(), delay.asUInt(), 0};
|
||||
delays.push_back(entry);
|
||||
} else {
|
||||
const instr_delay entry{name.asCString(), size.asUInt(), delay[0].asUInt(), delay[1].asUInt()};
|
||||
delays.push_back(entry);
|
||||
}
|
||||
}
|
||||
rep_counts.resize(delays.size());
|
||||
} else {
|
||||
LOG(ERR)<<"plugin instruction_count: could not find an entry for "<<core_name<<" in JSON file"<<std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,8 @@
|
||||
#define _ISS_PLUGIN_INSTRUCTION_COUNTER_H_
|
||||
|
||||
#include <iss/vm_plugin.h>
|
||||
#include <json/json.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace iss {
|
||||
namespace plugin {
|
||||
@ -72,7 +72,6 @@ public:
|
||||
void callback(instr_info_t) override;
|
||||
|
||||
private:
|
||||
Json::Value root;
|
||||
std::vector<instr_delay> delays;
|
||||
std::vector<uint64_t> rep_counts;
|
||||
};
|
||||
|
11
src/main.cpp
11
src/main.cpp
@ -73,7 +73,7 @@ int main(int argc, char *argv[]) {
|
||||
("mem,m", po::value<std::string>(), "the memory input file")
|
||||
("plugin,p", po::value<std::vector<std::string>>(), "plugin to activate")
|
||||
("backend", po::value<std::string>()->default_value("interp"), "the ISS backend to use, options are: interp, tcc")
|
||||
("isa", po::value<std::string>()->default_value("tgc5c"), "isa to use for simulation");
|
||||
("isa", po::value<std::string>()->default_value("tgc5c"), "core or isa name to use for simulation, use '?' to get list");
|
||||
// clang-format on
|
||||
auto parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
|
||||
try {
|
||||
@ -124,7 +124,7 @@ int main(int argc, char *argv[]) {
|
||||
std::tie(cpu, vm) = f.create(isa_opt+"|"+clim["backend"].as<std::string>(), clim["gdb-port"].as<unsigned>());
|
||||
} else {
|
||||
auto base_isa = isa_opt.substr(0, 5);
|
||||
if(base_isa=="tgc_d" || base_isa=="tgc_e") {
|
||||
if(base_isa=="tgc5d" || base_isa=="tgc5e") {
|
||||
isa_opt += "|mu_p_clic_pmp|"+clim["backend"].as<std::string>();
|
||||
} else {
|
||||
isa_opt += "|m_p|"+clim["backend"].as<std::string>();
|
||||
@ -148,6 +148,7 @@ int main(int argc, char *argv[]) {
|
||||
plugin_name = opt_val.substr(0, found);
|
||||
arg = opt_val.substr(found + 1, opt_val.size());
|
||||
}
|
||||
#if defined(WITH_PLUGINS)
|
||||
if (plugin_name == "ic") {
|
||||
auto *ic_plugin = new iss::plugin::instruction_count(arg);
|
||||
vm->register_plugin(*ic_plugin);
|
||||
@ -156,8 +157,10 @@ int main(int argc, char *argv[]) {
|
||||
auto *ce_plugin = new iss::plugin::cycle_estimate(arg);
|
||||
vm->register_plugin(*ce_plugin);
|
||||
plugin_list.push_back(ce_plugin);
|
||||
}else {
|
||||
#ifndef WIN32
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
#if !defined(WIN32)
|
||||
std::vector<char const*> a{};
|
||||
if(arg.length())
|
||||
a.push_back({arg.c_str()});
|
||||
|
Reference in New Issue
Block a user