-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.cpp
46 lines (38 loc) · 1 KB
/
print.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
#include <cstdlib>
#include <iostream>
#include "vm/program.hpp"
using namespace vm;
using namespace process;
using namespace std;
int
main(int argc, char **argv)
{
if(argc < 2) {
fprintf(stderr, "usage: print <bytecode file> [code | rules | info | prog]\n");
return EXIT_FAILURE;
}
const string file(argv[1]);
try {
program prog(file);
if(argc == 2)
prog.print_bytecode(cout);
if(argc == 3) {
const string arg(argv[2]);
if(arg == "code") {
prog.print_bytecode(cout);
} else if(arg == "rules") {
prog.print_rules(cout);
} else if(arg == "info") {
prog.print_predicates(cout);
} else if(arg == "prog") {
prog.print_program(cout);
} else {
cerr << "Don't know what to do" << endl;
}
}
} catch(vm::load_file_error& err) {
cerr << "File error: " << err.what() << endl;
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}