-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
50 lines (42 loc) · 1.2 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
#include <iostream>
#include <string>
#include "value/value.cpp"
#include "pair/pair.cpp"
#include "stack/stack.cpp"
#include "program/program.cpp"
#include "utils/string.hpp"
#include "assembler/assembler.cpp"
#include "machine/machine.cpp"
#include <tuple>
#include <list>
#include <string>
int main(int argc, char *argv[]) {
if (argc < 3)
{
std::cout << "Usage: " << argv[0] << " <assemble|run|rund> <input file>" << std::endl;
return 1;
}
std::string command = argv[1];
std::string inputFile = argv[2];
if (command != "assemble" && command != "run" && command != "rund")
{
std::cout << "Usage: " << argv[0] << " <assemble|run|rund> <input file>" << std::endl;
return 1;
}
if (command == "assemble")
{
Assembler assembler(inputFile);
Program program = assembler.assemble();
program.save(removeExtension(inputFile) + "_out.bin");
return 0;
}
if (command == "run" || command == "rund")
{
Program program = Program();
program.load(inputFile);
Machine machine = Machine(program);
machine.run(command == "rund");
std::cout << machine.getOutput();
}
return 0;
}