update plugins to read YAML file

This commit is contained in:
2023-09-30 22:10:24 +02:00
parent b7f023756e
commit b97853ff5a
7 changed files with 171 additions and 175 deletions

View File

@ -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;
}