Skip to content
Snippets Groups Projects
Commit 13843198 authored by Bouquillon Fabien's avatar Bouquillon Fabien
Browse files

exploration

parent 2c3c1cc9
No related branches found
No related tags found
No related merge requests found
#cflags pour tout compiler
CXXFLAGS=`otawa-config otawa/display --cflags`
#ldlibs pour compiler le plugin
LDLIBS=`otawa-config otawa/display --libs`
#ldlibs pour compiler la application
LDLIBS2=`otawa-config otawa/display otawa/explo --libs`
ARMCC=arm-none-eabi-gcc
CXXFLAGS += -std=c++11 -O0 -g -I ../otawa-core2-build/otawa/include/ -I ../otawa-core2-build/elm/include/
all: clean explo.so install application binaire one_function
binaire: binaire.c
$(ARMCC) -nostdlib -nostdinc -static -o binaire binaire.c
one_function: one_function.c
$(ARMCC) -nostdlib -nostdinc -static -o one_function one_function.c
##debut
application: application.o
$(CXX) -o application application.o $(LDLIBS2)
application.o: application.cpp
explo.so: explo.cpp include/explo.h
$(CXX) -fPIC -shared $(CXXFLAGS) -o explo.so explo.cpp $(LDLIBS)
##fin
clean:
rm -f *.o application binaire one_function *~ *.dot *.ps *.so
install: explo.so
mkdir -p $(HOME)/.otawa/proc/otawa
cp explo.eld $(HOME)/.otawa/proc/otawa/
cp explo.so $(HOME)/.otawa/proc/otawa/
.PHONY: all test clean graph
File added
#include <otawa/app/Application.h>
#include <otawa/cfg/features.h>
#include <otawa/script/Script.h>
#include <otawa/prog/WorkSpace.h>
#include <otawa/proc/DynProcessor.h>
#include <otawa/cfg/Dominance.h>
#include <otawa/proc/DynFeature.h>
//includes pour l'affichage du CFG
#include <otawa/display/CFGOutput.h>
#include <elm/io/OutFileStream.h>
#include "include/explo.h"
using namespace otawa; //comme import
using namespace otawa::explo;
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "usage: %s <binary> ", argv[0]);
exit(1);
}
WorkSpace *ws = NULL;
PropList conf;
Manager manager;
NO_SYSTEM(conf) = true;
TASK_ENTRY(conf) = "main";
VERBOSE(conf) = true;
CACHE_CONFIG_PATH(conf) = "./cache.xml";
StringBuffer buf;
buf << argv[1] << "-decomp.c";
elm::io::OutFileStream s(buf.toString());
elm::io::Output out(s);
conf.print(out);
ws = manager.load(argv[1], conf);
ws->require(DynFeature("otawa::explo::EXPLO_FEATURE"), conf);
}
\ No newline at end of file
File added
File added
{ ID(otawa::CACHE_CONFIG_PATH) = ./cache.xml, ID(otawa::VERBOSE) = true, ID(otawa::TASK_ENTRY) = main, ID(otawa::NO_SYSTEM) = true }
\ No newline at end of file
void foo() {
}
int main(void) {
int i = 0;
foo();
foo();
int j = 0;
}
{ ID(otawa::CACHE_CONFIG_PATH) = ./cache.xml, ID(otawa::VERBOSE) = true, ID(otawa::TASK_ENTRY) = main, ID(otawa::NO_SYSTEM) = true }
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<cache-config>
<icache>
<block_bits>8</block_bits>
<way_bits>4</way_bits>
<row_bits>6</row_bits>
<miss_penalty>70</miss_penalty>
</icache>
</cache-config>
\ No newline at end of file
#include "include/explo.h"
namespace otawa {
namespace explo {
// Declaration du plugin
class Plugin : public ProcessorPlugin {
public:
Plugin() : ProcessorPlugin("otawa::explo", Version(1, 0, 0), OTAWA_PROC_VERSION) {}
};
otawa::explo::Plugin explo_plugin;
ELM_PLUGIN(explo_plugin, OTAWA_PROC_HOOK);
p::declare ExploProcessor::reg = p::init("otawa::explo::ExploProcessor", Version(1, 0, 0))
.require(COLLECTED_CFG_FEATURE)
.require(LOOP_INFO_FEATURE)
.provide(EXPLO_FEATURE);
// definition feature
p::feature EXPLO_FEATURE("otawa::explo::EXPLO_FEATURE", new Maker<ExploProcessor>());
ExploProcessor::ExploProcessor(p::declare &r) : Processor(r) {}
void ExploProcessor::configure(const PropList &props) {
Processor::configure(props);
}
int get_exit_id_of_cfg(CFG *cfg) {
for(CFG::BlockIter block_iter = cfg->blocks(); block_iter(); block_iter++) {
Block * b = *block_iter;
bool found = true;
for(
Block::EdgeIter iter_suc(b->outs());
iter_suc();
iter_suc++) {
found = false;
break;
}
if(found) {
return b->id();
}
}
return -1;
}
std::vector<Block*> get_last_blocks(CFG *cfg) {
std::vector<Block*> tmp_v;
int id_last = get_exit_id_of_cfg(cfg);
if(id_last == -1) {
return tmp_v;
}
for(CFG::BlockIter block_iter = cfg->blocks(); block_iter(); block_iter++) {
Block * b = *block_iter;
for(
Block::EdgeIter iter_suc(b->outs());
iter_suc();
iter_suc++) {
Edge *edge = *iter_suc;
Block *target = edge->target();
if(target->id() == id_last) {
tmp_v.push_back(b);
break;
}
}
}
return tmp_v;
}
void explo_by_block(Block *b) {
std::cout << "-------------------" << std::endl;
std::cout << "Block: " << b->id() << " ";
if(b->isBasic()) {
std::cout << "Basic ";
}
if(b->isSynth()) {
std::cout << "Synth ";
}
std::cout << std::endl;
for(Block::EdgeIter iter_suc(b->outs());
iter_suc();
iter_suc++) {
Edge *edge = *iter_suc;
Block *target = edge->target();
std::cout << "B" << target->id() << " ";
}
std::cout << std::endl;
std::cout << "-------------------" << std::endl;
}
void explo_cfg(CFG *cfg) {
std::cout << "#############################################" << std::endl;
for(CFG::BlockIter bi = cfg->blocks(); bi(); bi++) {
Block *tmp = *bi;
explo_by_block(tmp);
}
std::cout << "#############################################" << std::endl;
}
void ExploProcessor::processWorkSpace(WorkSpace *ws) {
const CFGCollection *coll = INVOLVED_CFGS(ws);
for(CFGCollection::Iter cfg_iter(*coll); cfg_iter(); cfg_iter++) {
CFG* tmp = *cfg_iter;
explo_cfg(tmp);
std::cout << "EXIT: ";
std::vector<Block*> vector_blocks = get_last_blocks(tmp);
for(int i = 0; i < vector_blocks.size(); i++) {
std::cout << vector_blocks[i]->id() << " ";
}
std::cout << std::endl;
}
}
// definition propriete
/*
Identifier<DAGHNode*> DAG_HNODE("otawa::explo::DAG_HNODE");
*/
}
}
[elm-plugin]
name = explo
author = Fabien Bouquillon <fabien.bouquillon@univ-lille.fr>
description = plugin vide
\ No newline at end of file
File added
#ifndef EXPLO_H
#define EXPLO_H
#include <typeinfo>
#include <vector>
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <functional>
#include <otawa/cfg.h>
#include <otawa/cfg/features.h>
#include <otawa/proc/ProcessorPlugin.h>
#include <otawa/cfg/Dominance.h>
#include <otawa/otawa.h>
namespace otawa { namespace explo {
class ExploProcessor : public Processor {
public:
static p::declare reg;
explicit ExploProcessor(p::declare &r = reg);
protected:
void processWorkSpace(WorkSpace * /*ws*/) override;
void configure(const PropList &props) override;
};
// declaration feature
extern p::feature EXPLO_FEATURE;
//declaration propriete
/*
extern Identifier<DAGHNode*> DAG_HNODE;
*/
} }
#endif
\ No newline at end of file
File added
{ ID(otawa::CACHE_CONFIG_PATH) = ./cache.xml, ID(otawa::VERBOSE) = true, ID(otawa::TASK_ENTRY) = main, ID(otawa::NO_SYSTEM) = true }
\ No newline at end of file
int main(void) {
int i = 0;
if(i == 1) {
i = i + 1;
} else {
i = i + 2;
}
i = i + 3;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment