lrusecurity_ExistHitPrevUAnalysis.cpp 2.71 KB
Newer Older
1
#include "ExistHitPrevUAnalysis.h"
2 3 4 5 6 7 8 9 10 11

#include <chrono>

#include <otawa/ai/ArrayStore.h>
#include <otawa/ai/SimpleAI.h>
#include <otawa/icache/features.h>
#include <otawa/icat3/features.h>

#include <lrusecurity/features.h>

12 13
#include "ExistHitPrevUAdapter.h"
#include "ExistHitPrevUDomain.h"
14

15 16 17 18 19
using namespace otawa;

namespace lrusecurity
{

20
ExistHitPrevUAnalysis::ExistHitPrevUAnalysis(p::declare& r) :
21
		Processor(r),
22
		_initExistHitPrevU(nullptr),
23 24 25 26
		_coll(nullptr),
		_cfgs(nullptr)
{
}
27

28
void ExistHitPrevUAnalysis::configure(const PropList& props)
29 30 31
{
	Processor::configure(props);
	if(props.hasProp(EXIST_HIT_PREV_INIT))
32
		_initExistHitPrevU = &EXIST_HIT_PREV_INIT(props);
33 34
}

35
void ExistHitPrevUAnalysis::setup(WorkSpace* ws)
36 37 38 39 40 41 42
{
	_coll = icat3::LBLOCKS(ws);
	ASSERT(_coll != nullptr);
	_cfgs = INVOLVED_CFGS(ws);
	ASSERT(_cfgs != nullptr);
}

43
  void ExistHitPrevUAnalysis::processWorkSpace(WorkSpace* ws) //changer les ACS en ACSSecurity
44
{
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
	auto start = std::chrono::system_clock::now();

	// prepare containers
	for(CFGCollection::BlockIter b(_cfgs); b; b++)
		(*EXIST_HIT_PREV_IN(b)).configure(*_coll);

	// compute ACS
	for(int i = 0; i < _coll->cache()->setCount(); i++) {
		if((*_coll)[i].count()) {
			if(logFor(LOG_FUN))
				log << "\tanalyzing set " << i << io::endl;
			processSet(i, ws);
		}
	}

	auto end = std::chrono::system_clock::now();
	auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(end - start);
	if(logFor(LOG_FUN))
		log << "\tExist Hit Prev Analysis running time: " << elapsed.count() << " s" << io::endl;
}
65

66
void ExistHitPrevUAnalysis::destroy(WorkSpace*)
67 68 69 70 71
{
	for(CFGCollection::BlockIter b(_cfgs); b; b++)
		EXIST_HIT_PREV_IN(b).remove();
}

72
void ExistHitPrevUAnalysis::processSet(int set, WorkSpace* ws)
73 74
{
	// perform the analysis
75 76
	ExistHitPrevUAdapter ada(set, _initExistHitPrevU ? &_initExistHitPrevU->get(set) : nullptr, *_coll, *_cfgs, ws);
	ai::SimpleAI<ExistHitPrevUAdapter> ana(ada);
77 78 79 80 81 82 83 84 85 86
	ana.run();
	// store the results
	for(CFGCollection::BlockIter b(_cfgs); b; b++)
		if(b->isBasic()) {
		  ada.domain().copy((*EXIST_HIT_PREV_IN(b))[set], ada.store().get(b));
			if(logFor(LOG_BLOCK))
				log << "\t\t\t" << *b << ": " << ada.domain().print(ada.store().get(b)) << io::endl;
		}
}

87
p::declare ExistHitPrevUAnalysis::reg = p::init("lrusecurity::ExistHitPrevUAnalysis", Version(1, 0, 0))
88 89 90 91
	.require(icat3::LBLOCKS_FEATURE)
	.require(COLLECTED_CFG_FEATURE)
	.require(icat3::MUST_PERS_ANALYSIS_FEATURE)
	.require(icat3::CATEGORY_FEATURE)
Valentin Touzeau's avatar
Valentin Touzeau committed
92
	.require(lrupreanalysis::eh_em::EXIST_HIT_ANALYSIS_FEATURE)
93 94
	.provide(EXIST_HIT_PREV_U_ANALYSIS_FEATURE)
	.make<ExistHitPrevUAnalysis>();
95

96
p::feature EXIST_HIT_PREV_U_ANALYSIS_FEATURE("lrusecurity::EXIST_HIT_PREV_ANALYSIS_U_FEATURE", p::make<ExistHitPrevUAnalysis>());
97
}; // namespace lrusecurity