-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprint.cpp
54 lines (43 loc) · 1.14 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
47
48
49
50
51
52
53
#include <cstdlib>
#include <iostream>
#include "vm/program.hpp"
#include "mem/thread.hpp"
#include "vm/instr.hpp"
#include "vm/all.hpp"
using namespace vm;
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 {
mem::ensure_pool();
program prog(file);
theProgram = &prog;
vm::USING_MEM_ADDRESSES = false;
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;
}