-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
58 lines (53 loc) · 1.29 KB
/
Copy pathmain.cc
File metadata and controls
58 lines (53 loc) · 1.29 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
#include <cstdio> // fopen, fprintf
#include <cstdlib> // exit
#include <exception>
#include "Absyn.H"
#include "Parser.H"
#include "codegen.h"
#include "pstcode.h"
using namespace std;
int main(int argc, char ** argv)
{
FILE *input, *output;
bool binmode = false; // Output in binary mode?
if (argc > 1)
{
input = fopen(argv[1], "r");
if (!input)
{
fprintf(stderr, "Error opening input file.\n");
return 1;
}
}
else input = stdin;
if (argc > 2)
{
output = fopen(argv[2], "wb");
binmode = true;
if (!output)
{
fprintf(stderr, "Error opening output file.\n");
return 1;
}
}
else output = stdout;
/* The default entry point is used. For other options see Parser.H */
Program *parse_tree = pProgram(input);
if (parse_tree)
{
fprintf(stderr, "\nParse Succesful!\n");
try
{
CodeGen cg;
PstackCode code = cg.generate(parse_tree);
code.write(output, binmode);
return 0;
}
catch (exception &e)
{
fprintf(stderr, "Code-generation error: %s\n", e.what());
// ... and fall through to return 1
}
}
return 1;
}