Commit e985c27e authored by Julien Balette-Pape's avatar Julien Balette-Pape

create class for matching

parent c4febd7d
#include "InstMatching.h"
using namespace otawa;
namespace lrusecurity
{
void InstMatcher::setupColl(CFGCollection *collection)
{
CFGCollection::BlockRange range = collection->blocks();
CFGCollection::BlockIter iter_block;
for (iter_block = range.begin(); iter_block != range.end(); iter_block++){
Block *b = *iter_block;
if (b->isBasic()){
BasicBlock *bb = b->toBasic();
BasicBlock::InstIter iter_inst;
for (iter_inst = bb->begin(); iter_inst != bb->end(); iter_inst++){
insert(*iter_inst, bb);
}
}
}
_setup = true;
}
otawa::BasicBlock* InstMatcher::match_instruction(otawa::Inst *instruction)
{
auto search = this->_match.find(instruction);
if (search != _match.end())
return search->second;
else
exit(EXIT_FAILURE);
}
} // namespace lrusecurity
#ifndef LRUSECURITY_INST_MATCHING_H
#define LRUSECURITY_INST_MATCHING_H
#include <otawa/cfg/features.h>
#include <otawa/cfg/CFG.h>
#include <otawa/prog/Inst.h>
#include <otawa/icache/features.h>
#include <map>
namespace lrusecurity
{
class InstMatcher
{
public:
InstMatcher(void){_setup = false;};
inline void insert(otawa::Inst *inst, otawa::BasicBlock *bb){_match.insert({inst, bb});};
void setupColl(otawa::CFGCollection *collection);
otawa::BasicBlock *match_instruction(otawa::Inst *instruction);
inline otawa::BasicBlock *match_access(otawa::icache::Access *access){return match_instruction(access->instruction());};
inline void manual_setup(void){_setup = true;};
private:
bool _setup;
std::map<otawa::Inst *, otawa::BasicBlock *> _match;
};
} // namespace lrusecurity
#endif /* ifndef LRUSECURITY_INST_MATCHING_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment