Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

DotModificator.cpp 2.02 KB
Newer Older
1
2
#include <iostream>
#include <fstream>
3
#include <string>
4
5
6
7
8
9

#include "DotModificator.h"

namespace lrusecurity
{

Julien Balette-Pape's avatar
Julien Balette-Pape committed
10
void DotModificator::modify(otawa::CFG *cfg, const otawa::icache::Access *access, otawa::Address address)
11
{
12
    std::ofstream flux(_filename, std::ios::app);
13
14
15

    if (flux){
        // Permet de mettre des nodes au même niveau
16
        if (isFirst()) {
17
18
19
            flux << "rankdir = TB;" << io::endl;
        }

Julien Balette-Pape's avatar
Julien Balette-Pape committed
20
        //Copie de l'addresse pour affichage
21
        int addr = address.offset();
22

Julien Balette-Pape's avatar
Julien Balette-Pape committed
23
        if (access){
24
25
26
            // On récupère le bloc correspondant à l'accès grâce à l'InstMatcher
            otawa::BasicBlock *bb_match = _intM->match_access(access);

Julien Balette-Pape's avatar
Julien Balette-Pape committed
27
            // Copie de l'adresse de l'accès pour affichage
28
29
            int acc_addr;
            acc_addr = access->address().offset();
Julien Balette-Pape's avatar
Julien Balette-Pape committed
30
31

            // Creation du node UNSAFE
32
33
            flux << "Unsafe_" << _count << " [label=\"{UNSAFE 0x" << std::hex << acc_addr
                <<"| lead to a hit @ 0x" << addr <<"}\", color = red];" << std::dec << io::endl;
34

Julien Balette-Pape's avatar
Julien Balette-Pape committed
35
            // On met au même niveau le node Unsafe et le BB auquel il correspond
36
37
38
39
40
41
            string name = cfg->name();
            flux << "{rank = same; Unsafe_" << _count << "; ";
            for (String::Iter i = name.begin(); i!=name.end(); i++){
                flux << *i;
            }
            flux << "_" << cfg->index() << "_" << bb_match->index() <<";}" << io::endl;   //TODO: à optimisé (1 par BB)
Julien Balette-Pape's avatar
Julien Balette-Pape committed
42

43
44
45
        } else { // Debut du de la modification du CFG
            flux << "Unsafe_" << _count << " [label=\"{UNSAFE at the ENTRY|Can lead to a hit @ 0x"
                << std::hex << addr <<"}\", color = red];" << std::dec << io::endl;
Julien Balette-Pape's avatar
Julien Balette-Pape committed
46
        }
47

Julien Balette-Pape's avatar
Julien Balette-Pape committed
48
        // On incrémente le compteur
49
50
        _count++;
    } else {
51
        cerr << "ERROR: Unable to open the file" << io::endl;
52
53
54
55
56
57
58
59
60
61
    }
}

void DotModificator::finish(void)
{
    std::ofstream flux(_filename);

    if (flux){
        flux << "}" << io::endl;
    } else {
62
        cerr << "ERROR: Unable to open the file" << io::endl;
63
64
65
66
    }
}

}