adds functionality to reduce the output

This commit is contained in:
Eyck-Alexander Jentzsch 2022-02-16 10:12:45 +01:00
parent b37ef973de
commit 2bba5645c3
2 changed files with 45 additions and 8 deletions

View File

@ -90,6 +90,7 @@ private:
std::ofstream output; std::ofstream output;
std::string filename; std::string filename;
std::vector<instr_desc> delays; std::vector<instr_desc> delays;
bool jumped, first;
}; };
} }

View File

@ -20,6 +20,8 @@ iss::plugin::cov::cov(std::string const &filename)
, filename(filename) , filename(filename)
{ {
output.open("output.trc"); output.open("output.trc");
jumped = false;
first = true;
} }
iss::plugin::cov::~cov() { iss::plugin::cov::~cov() {
@ -79,19 +81,53 @@ bool iss::plugin::cov::registration(const char *const version, vm_if& vm) {
} }
inline string formatPC(uint64_t pc) {
stringstream stream;
stream << "0x" << std::hex << pc;
return stream.str();
}
void iss::plugin::cov::callback(instr_info_t iinfo, const exec_info& einfo) { void iss::plugin::cov::callback(instr_info_t iinfo, const exec_info& einfo) {
// if((instr_if->get_next_pc() - instr_if->get_pc() != 4) ||( instr_if->get_next_pc() - instr_if->get_pc() != 2)){
// std::cout << "jump from " << std::hex << instr_if->get_pc() << " to " << instr_if->get_next_pc()<< " after " << std::dec << counter <<" linear instructions" <<std::endl;
// counter = 0;
// }else {
// counter++;
// }
auto delay = 0; auto delay = 0;
auto entry = delays[iinfo.instr_id]; auto entry = delays[iinfo.instr_id];
bool taken = einfo.branch_taken; bool taken = einfo.branch_taken;
if (einfo.branch_taken) if (einfo.branch_taken)
delay = entry.taken; delay = entry.taken;
else else
delay = entry.not_taken; delay = entry.not_taken;
output<<std::hex <<"0x" << instr_if->get_pc() <<"," << delay << "\n";
if (first){
output << formatPC(instr_if->get_pc()) << "," << delay;
first = false;
}
if(instr_if->get_next_pc()-instr_if->get_pc() != delays[iinfo.instr_id].size/8){
//The goal is to keep the output in start-target pairs, so after a jump the target address needs to get written
//to the output. If the target happens to also be a start, we keep the pairing by adding a 0-delay entry.
if (jumped)
output <<"\n" <<formatPC(instr_if->get_pc()) << "," << 0;
output <<"\n" << formatPC(instr_if->get_pc()) << "," << delay;
jumped = true;
}
else{
if (jumped){
output <<"\n" << formatPC(instr_if->get_pc()) << "," << delay;
jumped = false;
}
else if(delay!=1){
output <<"\n" << formatPC(instr_if->get_pc()) << "," << delay;
output <<"\n" << formatPC(instr_if->get_pc()) << "," << 0;
}
}
//source code for the full output
// auto delay = 0;
// auto entry = delays[iinfo.instr_id];
// bool taken = einfo.branch_taken;
// if (einfo.branch_taken)
// delay = entry.taken;
// else
// delay = entry.not_taken;
// output<<std::hex <<"0x" << instr_if->get_pc() <<"," << delay << "\n";
} }