This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdalc.cpp
85 lines (57 loc) · 2.12 KB
/
mdalc.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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "libmdal/mdal.h"
using namespace std;
int main(int argc, char *argv[]) {
cout << "MDAL COMPILER v0.0.2\n\n";
bool verbose = false;
string infile = "";
string outfile = "music.asm";
for (int i = 1; i < argc; i++) {
string arg = argv[i];
if (arg == "-v") verbose = true;
if (arg == "-i" && i < argc-1) infile = argv[i+1];
if (arg == "-o" && i < argc-1) outfile = argv[i+1];
}
if (infile == "") {
cout << "Usage: mdalc -i <infile> [-o <outfile> -v]\n";
return -1;
}
try {
ifstream MDFILE(infile.data());
if (!MDFILE.is_open()) throw (infile + " not found.");
ofstream ASM(outfile.data());
if (!ASM.is_open()) throw ("Could not open " + outfile + ".");
string tempstr;
vector<string> moduleLines;
bool blockComment = false;
while (getline(MDFILE, tempstr)) {
string remains = "";
if (tempstr.find("/*", 0, 2) != string::npos) { //detect and strip block comments
remains = tempstr.erase(tempstr.find("/*", 0, 2), tempstr.find("*/", 0, 2));
blockComment = true;
}
if (tempstr.find("*/", 0, 2) != string::npos) {
blockComment = false;
tempstr.erase(0, tempstr.find("*/", 0, 2) + 2);
}
if (blockComment) tempstr = "" + remains;
else {
size_t commentPos = tempstr.find("//", 0, 2); //strip regular comments
if (commentPos != string::npos) tempstr.erase(commentPos);
}
moduleLines.push_back(tempstr);
}
string configname = "config/" + getArgument(string("CONFIG"), moduleLines) + ".mdconf";
mdConfig config;
config.init(configname, verbose);
mdModule mdf(moduleLines, config, verbose);
ASM << mdf;
} catch(string &e) {
cout << "In " << infile << endl << "ERROR: " << e << "\nCompilation terminated." << endl;
return -1;
}
return 0;
}