-
Notifications
You must be signed in to change notification settings - Fork 9
/
warning.h
132 lines (109 loc) · 3.17 KB
/
warning.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
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef __WARNING_H__
#define __WARNING_H__
extern addr_t current_instruction;
addr_t last_program_instruction();
void __enter_function(addr_t caller, const std::string);
void __exit_function();
void __warning(addr_t, addr_t);
#define WARNING(msg, ...) { \
if (current_instruction != 0) { \
fprintf(DEBUG_FILE, "%s ### %.8x ### %.8x\n", msg, \
current_instruction, last_program_instruction()); \
if (strstr(msg, "Write out of bounds")) { \
__warning(current_instruction, last_program_instruction()); \
} \
} \
}
#include "types.h"
#include <iostream>
#include <fstream>
#include <map>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/set.hpp>
#include <boost/serialization/map.hpp>
class Warning {
private:
std::set<addr_t> slice;
addr_t addr;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & slice;
ar & addr;
(void)version;
}
public:
Warning() {};
Warning(addr_t a) {
addr = a;
}
void addToSlice(addr_t b) {
slice.insert(b);
}
addr_t getAddress() const {
return addr;
}
typedef std::set<addr_t>::const_iterator slice_iterator;
slice_iterator slice_begin() const {
return slice.begin();
}
slice_iterator slice_end() const {
return slice.end();
}
bool slice_find(addr_t b) const {
return slice.find(b) != slice.end();
}
size_t getSliceSize() const {
return slice.size();
}
};
struct warningcmp {
bool operator()(const Warning *w1, const Warning *w2) const {
return w1->getAddress() < w2->getAddress();
}
};
typedef std::set<Warning *, warningcmp> warnings_t;
#include <errno.h>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
inline void serialize(const char *f, const warnings_t &ww) {
std::ofstream ofs(f,
std::ios::out|std::ios::binary|std::ios::trunc);
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
out.push(boost::iostreams::bzip2_compressor());
out.push(ofs);
boost::archive::binary_oarchive oa(out);
oa << ww;
}
inline void unserialize(const char *f, warnings_t &ww) {
try {
std::ifstream ifs(f, std::ios::in|std::ios::binary);
if (!ifs.is_open()) {
fprintf(stderr, "Failed to open %s: %s\n", f,
strerror(errno));
exit(1);
}
boost::iostreams::filtering_streambuf<boost::iostreams::input>
in;
in.push(boost::iostreams::bzip2_decompressor());
in.push(ifs);
boost::archive::binary_iarchive ia(in);
ia >> ww;
} catch (boost::iostreams::bzip2_error) {
std::ifstream ifs(f, std::ios::in|std::ios::binary);
if (!ifs.is_open()) {
fprintf(stderr, "Failed to open %s: %s\n", f,
strerror(errno));
exit(1);
}
boost::archive::binary_iarchive ia(ifs);
ia >> ww;
}
}
#endif
// Local Variables:
// mode: c++
// c-basic-offset: 4
// compile-command: "dchroot -c typeinfer -d make"
// End: