-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
203 lines (177 loc) · 5.06 KB
/
main.cpp
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//Copyright 2019 Hust.
//Author: HYL
//Descriptor:
/*main fun. The begin of the program.
*/
#include <iostream>
#include <map>
#include <cstring>
#include <assert.h>
#include <regex>
#include "analysis_IR.h"
#include "out_put_fun.h"
#include "trance_fun.h"
#include "debug_info.h"
using namespace::std;
int main(int argv, char **argc){
vector<string> input_file_name;
//string input_file_name;
//ram info file name
//core name
//special reg name
string output_file_name, ram_info_file_name,\
core_name, special_reg_name;
//identifiy '-' in -F -f or -o
regex reg("-.+");
//processing the para
for(int i = 0; i < argv; i++){
//whether is valid para
if(regex_match(argc[i], reg)){
//it is about input file
if(strcmp(argc[i],"-f") == 0 || \
strcmp(argc[i],"-F") == 0){
for(int j = i+1; j < argv; j++){
if(regex_match(argc[j], reg))
break;
input_file_name.push_back(argc[j]);
++i;
}
}
//it is about outout file
else if(strcmp(argc[i], "-o") == 0 || \
strcmp(argc[i], "-O") == 0){
for(int j = i+1; j < argv; j++){
if(regex_match(argc[j], reg))
break;
output_file_name = argc[j];
++i;
}
}
//it is ram addr file
else if(strcmp(argc[i], "-i") == 0 || \
strcmp(argc[i], "-I") == 0){
for(int j = i + 1; j < argv; j++){
if(regex_match(argc[j], reg)) break;
ram_info_file_name = argc[j];
++i;
}
}
//it is core name
else if(strcmp(argc[i], "-c") == 0 || \
strcmp(argc[i], "-C") == 0){
core_name = argc[++i];
}
//it is for special reg
else if(strcmp(argc[i], "-s") == 0 || \
strcmp(argc[i], "-S") == 0){
special_reg_name = argc[++i];
}
//it is invalid paremeter
else {
cout << "Not valid parameter: " << argc[i] << endl;
return 0;
} //end else
} //end if(regex_match(argc[i], reg))
} //for
//judge whether the command have enough parameter
if(input_file_name.size() == 0 || \
ram_info_file_name.empty() || \
core_name.empty() || \
special_reg_name.empty()){
cout << "Error: main() No enough command parameter! " << endl;
return 0;
}
vector<string> ram_range_vec, rom_range_vec;
try {
//deal with ram file
GetRamAndRomInfo(ram_info_file_name, \
ram_range_vec, rom_range_vec,\
core_name);
}
catch (const char*msg) {
cerr << msg << endl;
return 0;
}
//deal with ram info include ram and rom
DealWithRamAndRomInfo(ram_range_vec, \
rom_range_vec, \
core_name);
try {
//deal with special register in ram
DealWithSpecialRegInfo(special_reg_vec, \
special_reg_name, \
core_name);
}
catch (const char*msg) {
cerr << msg << endl;
return 0;
}
try {
//open outputFile
OpenOutPutFile(output_file_name);
}
catch (const char*msg) {
cerr << msg << endl;
return 0;
}
//get the parent file path of ram_info_file_name
//if the run environment is linux
#if defined(__linux__)
int path_name_index = ram_info_file_name.rfind("/");
//if the run environment is windos
#elif defined(_WIN32)
int path_name_index = ram_info_file_name.rfind("\\");
#endif
string path_name = ram_info_file_name.substr(0, path_name_index + 1);
//include some head file, core_name GeneralReg
OutPutPure("#include \"" + core_name + ".INC\"");
OutPutPure("#include \"" + core_name + "_GeneralReg.inc\"");
OutPutPure("#include \"" + path_name + "SubProgram.inc\"");
//precedure section of the program
//the beginning of program
ProgramBegin();
//deal with mutifiles
for(int i = 0; i < input_file_name.size(); i++){
try {
DebugInfo debug_info_object = DebugInfo();
debug_info_object.CreateAInstrDebugRecord("@SourceFile:" + \
input_file_name[i].substr(0, input_file_name[i].size() - 2) + \
"c", " ");
//open inputFile and get dbg info that used in tranfrom instr
//FirstOpenFileAndProcessGdbInfo(input_file_name[i]);
//open inputFile
OpenFileAndDeal(input_file_name[i]);
} catch (const char*msg){
cerr << msg << endl;
return 0;
}
if(i != input_file_name.size() - 1){
OutPutOrg("\n;;; Another file", " ");
}
}
OutPutPure("#include \"" + path_name + "SubProgram.asm\"");
//the interrupt of the program
ProgramHint();
//debug info file name
string debug_file_name = output_file_name;
DebugInfo debug_info_obj = DebugInfo();
//if output file name is NULL
if(debug_file_name.empty()){
debug_file_name = "output";
}
//if a . carater in the debug_file_name, remove
string::size_type idex;
idex = debug_file_name.rfind('.');//yzk 修改 解决路径中包含'.'的问题
if(idex != string::npos){
debug_file_name = debug_file_name.substr(0, idex);
}
//output the addr debug info to debug_file_name
debug_info_obj.PrintAddrDebugInfo(debug_file_name + \
"_addr_debug_info.txt");
//output the instr debug info to debug_file_name
debug_info_obj.PrintInstrDebugInfo(debug_file_name + \
"_instr_debug_info.txt");
//close outputFile
CloseOutPutFile();
return 0;
}