-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
97 lines (76 loc) · 1.75 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <valgrind/memcheck.h>
#include "util.hpp"
#include "object.hpp"
#include "parser.hpp"
#include "codegen2.hpp"
#include "runtime.hpp"
// Global flags
struct Flags {
bool kTailCallOpt;
};
Flags flag;
extern "C" {
extern Object *Scheme_asmEntry(
Object *, void *, intptr_t, intptr_t, ThreadState *);
}
Object *callScheme_0(Object *clo) {
assert(clo->isClosure());
auto info = clo->raw()->cloInfo();
assert(info->funcArity() == 0);
auto entry = info->funcCodeAs<void *>();
ThreadState *ts = &ThreadState::global();
if (Option::global().kLogInfo) {
Util::logObj("CallScheme", clo);
}
return Scheme_asmEntry(clo, entry, ts->heapPtr(), ts->heapLimit(), ts);
}
void readAll(FILE *f, std::string *xs) {
int c;
while ((c = fgetc(f)) != EOF) {
char realC = c;
(*xs) += realC;
}
}
Object *getMainClo(int argc, char **argv) {
FILE *fin;
CGModule cg;
Handle ast;
{
std::string input;
if (argc == 2) {
fin = fopen(argv[1], "r");
if (!fin) {
perror(argv[1]);
exit(1);
}
}
else {
fin = stdin;
}
readAll(fin, &input);
if (fin != stdin) {
fclose(fin);
}
Parser parser(input);
bool parseOk;
ast = parser.parseProg(&parseOk);
assert(parseOk);
}
//ast->displayDetail(2);
Object *mainClo = cg.genModule(ast);
return mainClo;
//ThreadState::global().display(2);
//callScheme_0(mainClo)->displayDetail(1);
//Runtime::printNewLine(1);
}
int main(int argc, char **argv) {
//VALGRIND_MAKE_MEM_NOACCESS(0x7fefff700UL, 8);
//ThreadState::global().display(2);
Option::init();
callScheme_0(getMainClo(argc, argv));
ThreadState::global().destroy();
return 0;
}