Skip to content

Commit 28953a8

Browse files
committed
Added compile mode
1 parent 09f492c commit 28953a8

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

main.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#define TEST 0
2+
#define CMD_COMPILER 1
23

34
#include <iostream>
45
#include <fstream>
@@ -9,10 +10,13 @@
910
#include "Instr.hpp"
1011
#include "Func.hpp"
1112
#else
13+
#if CMD_COMPILER
14+
#include <sstream>
15+
#endif
1216
#include "Parser.hpp"
1317
#endif
1418

15-
int main() {
19+
int main(int argc, const char* argv[]) {
1620
#if TEST
1721
Func* func = new Func("_alpha_main", new Scope(nullptr));
1822

@@ -49,6 +53,26 @@ int main() {
4953
std::cout << "\t.ascii\t\"" << str << "\\0\"" << std::endl;
5054

5155
delete func;
56+
#elif CMD_COMPILER
57+
if (argc >= 2) {
58+
std::string filename(argv[1]);
59+
if (filename.length() > 5) {
60+
std::stringstream buf(filename);
61+
std::string basename;
62+
std::getline(buf, basename, '.');
63+
64+
std::ofstream output(basename + ".s");
65+
66+
Parser p;
67+
Env* env = p.parse(filename);
68+
if (env)
69+
env->eval(output);
70+
} else {
71+
std::cerr << "Invalid input file" << std::endl;
72+
}
73+
} else {
74+
std::cerr << "No input file" << std::endl;
75+
}
5276
#else
5377
std::ofstream output("test.s");
5478

0 commit comments

Comments
 (0)