-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.cc
executable file
·119 lines (95 loc) · 4 KB
/
main.cc
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
///////////////////////////////////////////////////////////////////////
// Copyright 2015 Samsung Austin Semiconductor, LLC. //
///////////////////////////////////////////////////////////////////////
//Description : Main file for CBP2016
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
#include "utils.h"
//#include "bt9.h"
#include "bt9_reader.h"
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("usage: %s <trace> <out>\n", argv[0]);
exit(-1);
}
////////////////////////////
// read each trace record
////////////////////////////
std::string trace_path;
trace_path = argv[1];
bt9::BT9Reader bt9_reader(trace_path);
ofstream myfile;
myfile.open(argv[2]);
UINT64 PC;
bool branchTaken;
UINT64 branchTarget;
for (auto it = bt9_reader.begin(); it != bt9_reader.end(); ++it) {
PC = it->getSrcNode()->brVirtualAddr();
branchTaken = it->getEdge()->isTakenPath();
branchTarget = it->getEdge()->brVirtualTarget();
OpType opType;
bt9::BrClass br_class = it->getSrcNode()->brClass();
opType = OPTYPE_ERROR;
if ((br_class.type == bt9::BrClass::Type::UNKNOWN) && (it->getSrcNode()->brNodeIndex())) {
opType = OPTYPE_ERROR; //sanity check
} else if (br_class.type == bt9::BrClass::Type::RET) {
if (br_class.conditionality == bt9::BrClass::Conditionality::CONDITIONAL)
opType = OPTYPE_RET_COND;
else if (br_class.conditionality == bt9::BrClass::Conditionality::UNCONDITIONAL)
opType = OPTYPE_RET_UNCOND;
else {
opType = OPTYPE_ERROR;
}
} else if (br_class.directness == bt9::BrClass::Directness::INDIRECT) {
if (br_class.type == bt9::BrClass::Type::CALL) {
if (br_class.conditionality == bt9::BrClass::Conditionality::CONDITIONAL)
opType = OPTYPE_CALL_INDIRECT_COND;
else if (br_class.conditionality == bt9::BrClass::Conditionality::UNCONDITIONAL)
opType = OPTYPE_CALL_INDIRECT_UNCOND;
else {
opType = OPTYPE_ERROR;
}
} else if (br_class.type == bt9::BrClass::Type::JMP) {
if (br_class.conditionality == bt9::BrClass::Conditionality::CONDITIONAL)
opType = OPTYPE_JMP_INDIRECT_COND;
else if (br_class.conditionality == bt9::BrClass::Conditionality::UNCONDITIONAL)
opType = OPTYPE_JMP_INDIRECT_UNCOND;
else {
opType = OPTYPE_ERROR;
}
} else {
opType = OPTYPE_ERROR;
}
} else if (br_class.directness == bt9::BrClass::Directness::DIRECT) {
if (br_class.type == bt9::BrClass::Type::CALL) {
if (br_class.conditionality == bt9::BrClass::Conditionality::CONDITIONAL) {
opType = OPTYPE_CALL_DIRECT_COND;
} else if (br_class.conditionality == bt9::BrClass::Conditionality::UNCONDITIONAL) {
opType = OPTYPE_CALL_DIRECT_UNCOND;
} else {
opType = OPTYPE_ERROR;
}
} else if (br_class.type == bt9::BrClass::Type::JMP) {
if (br_class.conditionality == bt9::BrClass::Conditionality::CONDITIONAL) {
opType = OPTYPE_JMP_DIRECT_COND;
} else if (br_class.conditionality == bt9::BrClass::Conditionality::UNCONDITIONAL) {
opType = OPTYPE_JMP_DIRECT_UNCOND;
} else {
opType = OPTYPE_ERROR;
}
} else {
opType = OPTYPE_ERROR;
}
} else {
opType = OPTYPE_ERROR;
}
printf("%llx %d\n", PC, branchTaken);
myfile << PC << " " << branchTaken << "\n";
}
myfile.close();
}