-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxrun.cpp
More file actions
60 lines (56 loc) · 1.99 KB
/
xrun.cpp
File metadata and controls
60 lines (56 loc) · 1.99 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
#include <iostream>
#include "hexasm.hpp"
#include "xcmp.hpp"
#include "hexsim.hpp"
#include "hexsimio.hpp"
//===---------------------------------------------------------------------===//
// Driver
//===---------------------------------------------------------------------===//
static void help(char *argv[]) {
std::cout << "X run\n\n";
std::cout << "Usage: " << argv[0] << " file\n\n";
std::cout << "Positional arguments:\n";
std::cout << " file A source file to run\n\n";
std::cout << "Optional arguments:\n";
std::cout << " -h,--help Display this message\n";
std::cout << " -t,--trace Enable instruction tracing\n";
std::cout << " --max-cycles N Limit the number of simulation cycles (default: 0)\n";
}
int main(int argc, char *argv[]) {
char *inputFilename = nullptr;
bool trace = false;
size_t maxCycles = 0;
xcmp::Driver driver(std::cout);
try {
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "-h") == 0 ||
std::strcmp(argv[i], "--help") == 0) {
help(argv);
std::exit(1);
} else if (std::strcmp(argv[i], "-t") == 0 ||
std::strcmp(argv[i], "--trace") == 0) {
trace = true;
} else if (std::strcmp(argv[i], "--max-cycles") == 0) {
maxCycles = std::stoull(argv[++i]);
} else if (argv[i][0] == '-') {
throw std::runtime_error(std::string("unrecognised argument: ")+argv[i]);
} else {
if (!inputFilename) {
inputFilename = argv[i];
} else {
throw std::runtime_error("cannot specify more than one file");
}
}
}
if (driver.runCatchExceptions(xcmp::DriverAction::EMIT_BINARY, inputFilename, true, "a.bin", false) == 0) {
hexsim::Processor processor(std::cin, std::cout, maxCycles);
processor.setTracing(trace);
processor.load("a.bin");
processor.run();
}
} catch (const std::exception &e) {
std::cerr << boost::format("Error: %s\n") % e.what();
return 1;
}
return 0;
}