Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Copyright (c) 2014-2015 - Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
*/
#ifndef color_map_hpp
#define color_map_hpp
#include <libIRDB-core.hpp>
#include <stdint.h>
typedef int64_t NonceValueType_t;
class ColoredSlotValue_t
{
public:
ColoredSlotValue_t(int np, NonceValueType_t nv) : position(np), nonce_value(nv), valid(true) { };
ColoredSlotValue_t() : valid(false) {}
// void SetPosition(int pos) { slot_position=pos; }
int GetPosition() const { return position;}
// void SetNonceValue(NonceValueType_t p_nv) { nonce_value=p_nv; }
NonceValueType_t const GetNonceValue() { return nonce_value; }
bool IsValid() const { return valid; }
private:
int position;
NonceValueType_t nonce_value;
bool valid;
};
class ColoredSlotAllocator_t
{
public:
ColoredSlotAllocator_t(int sn, int mv) : slot_number(sn), used(1), max_value(mv) { }
bool CanReserve() const { return used < max_value; }
ColoredSlotValue_t Reserve()
{
assert(CanReserve());
return ColoredSlotValue_t(slot_number, used++);
}
int SlotsUsed() const { return used ; }
private:
int slot_number;
int used;
int max_value;
};
typedef std::map<int,ColoredSlotValue_t> ColoredSlotValues_t;
class ColoredInstructionNonces_t
{
public:
ColoredInstructionNonces_t(libIRDB::FileIR_t *the_firp)
: firp(the_firp), slot_size(1), slot_values(255) { }
ColoredSlotValues_t GetColorsOfIBT (libIRDB::Instruction_t* i)
{ return color_assignments[i]; }
ColoredSlotValue_t GetColorOfIB (libIRDB::Instruction_t* i)
{ assert(i->GetIBTargets()); return slot_assignments[*i->GetIBTargets()]; }
int NumberSlotsUsed() { return slots_used.size(); }
bool build() { return create(); }
private:
// helper to assign colors to slots.
bool create();
// the IR we're working on.
libIRDB::FileIR_t* firp;
// used to describe how big a nonce slot is. for now, 1 byte.
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// information for each slot we've used.
std::vector<ColoredSlotAllocator_t> slots_used;
// information for each IBT.
// a map for each instruction, which contains a ColorSlotValue_t for each slot used.
// instruction -> ( int-> slot_value )
std::map<libIRDB::Instruction_t*, ColoredSlotValues_t> color_assignments;
// information for each IB (as indexed by the IBs ICFS).
// the slot that each IB uses. ICFS_t -> slot_value
std::map<libIRDB::ICFS_t, ColoredSlotValue_t> slot_assignments;
};
// a simple way to sort ICFS.
class UniqueICFSSetSorter_t;
typedef std::set<libIRDB::ICFS_t, UniqueICFSSetSorter_t> UniqueICFSSet_t;
class UniqueICFSSetSorter_t
{
public:
bool operator() (const libIRDB::ICFS_t& a, const libIRDB::ICFS_t& b) const
{
if(a.size() == b.size()) return a<b;
return a.size() < b.size() ;
}
};
#endif