forked from flavioc/meld
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeld.cpp
More file actions
216 lines (183 loc) · 5.15 KB
/
meld.cpp
File metadata and controls
216 lines (183 loc) · 5.15 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <iostream>
#include <vector>
#include "process/machine.hpp"
#include "utils/utils.hpp"
#include "utils/fs.hpp"
#include "vm/state.hpp"
#include "debug/debug_handler.hpp"
#include "debug/debug_prompt.hpp"
#include "interface.hpp"
#include "compileInfo.hpp"
using namespace utils;
using namespace process;
using namespace std;
using namespace sched;
static char *program = NULL;
static char *data_file = NULL;
static char *progname = NULL;
static char checkedApiTarget = 0; // if set to 1, can exit successfully with zero args
namespace xutils {
static char* compileInfo = NULL;
char*
addCompileInfo(char const* info)
{
static int ciLen = 0;
int iLen = strlen(info);
compileInfo = (char *)realloc(compileInfo, ciLen + 2 + iLen);
if (ciLen > 0) compileInfo[ciLen++] = ' ';
strcpy(compileInfo+ciLen, info);
ciLen += iLen;
return compileInfo;
}
}
static void
help(void)
{
cerr << "meld: execute meld program for " << (xutils::compileInfo?xutils::compileInfo:"??") << endl;
cerr << "meld -f <program file> -c <scheduler> [options] -- arg1 arg2 ... argN" << endl;
cerr << "\t-f <name>\tmeld program" << endl;
cerr << "\t-a\tprint on stdout the target api" << endl;
cerr << "\t-a <name>\tmake sure <name> is proper target" << endl;
cerr << "\t-r <data file>\tdata file for meld program" << endl;
help_schedulers();
cerr << "\t-t \t\ttime execution" << endl;
cerr << "\t-m \t\tmemory statistics" << endl;
cerr << "\t-i <file>\tdump time statistics" << endl;
cerr << "\t-s \t\tshows database" << endl;
cerr << "\t-d \t\tdump database (debug option)" << endl;
cerr << "\t-h \t\tshow this screen" << endl;
cerr << "\t-D MPI|SIM \t\tgo into debugging mode" << endl;
exit(EXIT_SUCCESS);
}
static vm::machine_arguments
read_arguments(int argc, char **argv)
{
vm::machine_arguments program_arguments;
progname = *argv++;
--argc;
while (argc > 0 && (argv[0][0] == '-')) {
switch(argv[0][1]) {
case 'f': {
if (program != NULL || argc < 2)
help();
program = argv[1];
argc--;
argv++;
}
break;
case 'a': {
if (argc > 1) {
// check that supplied arg matches apiTarget
if (strcmp(argv[1], api::apiTarget)) {
cerr << "Mismatch of request " << argv[1] << " and compiled for " << api::apiTarget << endl;
exit(EXIT_FAILURE);
} else {
// we are good, you can continue
argc--;
argv++;
checkedApiTarget = 1;
}
} else {
cout << api::apiTarget << endl;
exit(EXIT_SUCCESS);
}
}
break;
case 'r': {
if(data_file != NULL || argc < 2)
help();
data_file = argv[1];
argc--;
argv++;
}
break;
case 'c': {
if (sched_type != SCHED_UNKNOWN)
help();
parse_sched(argv[1]);
argc--;
argv++;
}
break;
case 's':
show_database = true;
break;
case 'd':
dump_database = true;
break;
case 't':
time_execution = true;
break;
case 'm':
memory_statistics = true;
break;
case 'i':
if(argc < 2)
help();
statistics::set_stat_file(string(argv[1]));
argc--;
argv++;
break;
case 'h':
help();
break;
case 'D':
if (string(argv[1]) == "VM"){
cout << "DEBUGGING MODE -- type 'help' for options" << endl;
debugger::setDebuggingMode(true);
} else if (string(argv[1]) == "MPI"){
debugger::setMpiDebuggingMode(true);
} else if (string(argv[1]) == "SIM"){
debugger::setSimDebuggingMode(true);
} else {
cout << "Unknow debug option" << endl;
exit(EXIT_FAILURE);
}
break;
case '-':
for(--argc, ++argv ; argc > 0; --argc, ++argv)
program_arguments.push_back(string(*argv));
break;
default:
help();
}
/* advance */
argc--; argv++;
}
return program_arguments;
}
int
main(int argc, char **argv)
{
vm::machine_arguments margs(read_arguments(argc, argv));
if(sched_type == SCHED_UNKNOWN) {
sched_type = SCHED_SERIAL;
num_threads = 1;
}
if ((program == NULL) && (sched_type != SCHED_UNKNOWN)) {
if (checkedApiTarget) return EXIT_SUCCESS;
cerr << "Error: please provide a program to run" << endl;
return EXIT_FAILURE;
}
if(!file_exists(program)) {
cerr << "Error: file " << program << " does not exist or is not readable" << endl;
return EXIT_FAILURE;
}
try {
run_program(argc, argv, program, margs, data_file);
} catch(vm::load_file_error& err) {
cerr << "File error: " << err.what() << endl;
exit(EXIT_FAILURE);
} catch(machine_error& err) {
cerr << "VM error: " << err.what() << endl;
exit(EXIT_FAILURE);
} catch(db::database_error& err) {
cerr << "Database error: " << err.what() << endl;
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
// Local Variables:
// mode: C++
// indent-tabs-mode: nil
// End: