-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstr.h
executable file
·120 lines (96 loc) · 3.19 KB
/
instr.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef __INSTR_H__
#define __INSTR_H__
#include <cassert>
#include <vector>
#include <ostream>
#include <boost/serialization/vector.hpp>
#include "debug.h"
#include "types.h"
/* There's something a bit ugly going on with the "namespace vine"
below. Putting all of the Vine/LibASMIR stuff in its own namespace
is a reasonable complexity management idea, since there isn't any
other naming convention used to make the LibASMIR code distinct,
and it defines lots of common-sounding types. However the LibASMIR
code was not designed to live in its own namespace, and putting a
namespace declaration around a random include file doesn't
necessarily do the right thing. In particular the C++ parts of
LibASMIR use a lot of STL include files, but if those inclusions
are inside a "namespace vine" the compiler will get confused, for
instance thinking that std::cout is really vine::std::cout, so that
then other uses will be wrong. The ugly thing that makes it work is
include guards: each STL header file is designed to be empty if it
has already been included. So as long as all of the STL headers
that LibASMIR uses are actually included here before the "namespace
vine" code tries to include them, everything will get into the
right namespace. This is what the extensive list of STL includes
below is for. -- SMcC */
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
namespace vine {
#include "irtoir.h"
}
#define BASICBLOCK_MIDDLE 0
#define BASICBLOCK_HEAD 1
#define BASICBLOCK_TAIL 2
class Instruction;
class BasicBlock;
typedef std::vector<vine::Stmt *> statements_t;
#define MAX_INSTR_LEN 16
class Instruction {
friend class Cfg;
friend class BasicBlock;
private:
addr_t address;
byte_t rawbytes[MAX_INSTR_LEN];
size_t size;
statements_t statements;
bool decoded;
BasicBlock *basicblock;
uint32_t cksum;
bool executed;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & address;
ar & size;
ar & rawbytes;
ar & cksum;
ar & basicblock;
ar & executed;
(void)version;
}
public:
Instruction(); // for serialization
Instruction(addr_t, byte_t *b, size_t l);
~Instruction();
void decode();
size_t getSize();
addr_t getAddress() const;
byte_t *getRawBytes();
BasicBlock *getBasicBlock();
uint32_t computeCksum();
uint32_t getCksum();
void setAddress(addr_t a) { address = a; }
bool isCall();
bool isReturn();
void setExecuted();
bool isExecuted();
void setRawBytes(const byte_t *, size_t);
functions_t::const_iterator call_targets_begin() const;
functions_t::const_iterator call_targets_end() const;
statements_t::const_iterator stmt_begin() const;
statements_t::const_iterator stmt_end() const;
statements_t::const_reverse_iterator stmt_rbegin() const;
statements_t::const_reverse_iterator stmt_rend() const;
};
std::ostream& operator<<(std::ostream&, const Instruction&);
#endif
// Local Variables:
// mode: c++
// c-basic-offset: 4
// compile-command: "dchroot -c typeinfer -d make"
// End: