-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (33 loc) · 1014 Bytes
/
main.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
#include "Platform.h"
#include <iostream>
#include <fstream>
#include "ParserArena.h"
#include "Nodes.h"
#include "BytecodeGenerator.h"
int main (int argc, char * const argv[])
{
RefPtr<GlobalData> globalData(AdoptRef(new GlobalData()));
assert(globalData->HasOneRef());
RefPtr<ArenaNode> result;
if (argc!=2)
{
printf("usage: mycompiler.exe filename\n");
exit(1);
}
std::ifstream inputFile(argv[1], std::ios::in | std::ios::binary);
if (!inputFile.is_open())
{
printf("file not found\n");
exit(1);
}
Arena parser (&inputFile);
result = parser.Parse();
if (result.Ptr() != 0)
{
BytecodeGenerator generator(globalData.Ptr(), static_cast<StatementList*> (result.Ptr()));
RefPtr<MethodEnv> methodEnv = generator.Generate();
methodEnv->SetSourceCode(parser.GetSourceCode());
methodEnv->Run( globalData->GetRegisterFile()->GetBlock() );
}
return 0;
}