AccMatching.cpp 972 Bytes
Newer Older
Julien Balette-Pape's avatar
Julien Balette-Pape committed
1
#include "AccMatching.h"
2 3 4 5 6 7

using namespace otawa;

namespace lrusecurity
{

Julien Balette-Pape's avatar
Julien Balette-Pape committed
8
void AccMatcher::setupCFG(CFG *cfg)
9 10 11 12
{
    CFG::BlockIter iter_block;

    for (iter_block = cfg->blocks(); iter_block; iter_block++){
13 14 15
        Block *b = *iter_block;
        if (b->isBasic()){
            BasicBlock *bb = b->toBasic();
Julien Balette-Pape's avatar
Julien Balette-Pape committed
16 17 18
            const Bag<icache::Access>& bag = otawa::icache::ACCESSES(bb);
            for (int i = 0; i < bag.size(); i++){
                insert(&bag[i], bb);
19
            }
20 21 22 23
        }
    }
}

Julien Balette-Pape's avatar
Julien Balette-Pape committed
24
void AccMatcher::setupColl(CFGCollection *collection)
Julien Balette-Pape's avatar
Julien Balette-Pape committed
25 26
{
    for(int i = 0; i < collection->count(); i++) {
Julien Balette-Pape's avatar
Julien Balette-Pape committed
27
        AccMatcher::setupCFG(*collection[i]);
Julien Balette-Pape's avatar
Julien Balette-Pape committed
28 29 30
    }
}

Julien Balette-Pape's avatar
Julien Balette-Pape committed
31
otawa::BasicBlock* AccMatcher::match_access(const otawa::icache::Access *access)
32
{
Julien Balette-Pape's avatar
Julien Balette-Pape committed
33
    auto search = this->_match.find(access);
34 35 36 37

    if (search != _match.end())
        return search->second;
    else
38
        cerr << "Unable to find instruction";
39 40 41 42
        exit(EXIT_FAILURE);
}

} // namespace lrusecurity