-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.cpp
78 lines (64 loc) · 2.32 KB
/
compile.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
#ifndef LANG_GEN_COMPILE_CPP
#define LANG_GEN_COMPILE_CPP
// Internal includes
#include <stdio.h>
#include <bits/stdc++.h>
#include <string.h>
#include <string>
#include <filesystem>
#include <fstream>
#include <regex>
#include <stdexcept>
#include "lang_compile.h"
#include "src/step_gen.cpp"
#include "src/regex_perm.cpp"
int find_argv(int argc, const char * argv[], const char * search)
__attribute__((always_inline));
/*
inline void generate_step_char(std::fstream& out,
const std::string & from_lang_name,
const std::string & to_lang_name,
const std::vector<std::string>& from_filenames = {{LANG_GEN_RENAME_FROM}},
const std::vector<std::string>& to_filenames = {{LANG_GEN_RENAME_TO}},
const std::string& tag_path="Reserved-regex_Tag",
const std::string& trans_access="Reserved-regex_Line-Attribute-Access");
*/
int main(int argc, const char * argv[]){
int errors = 0;
std::string from, to;
if(argc < 5){
/*
printf("Minimal usage: %s -from <language> -to <language>\n", argv[0]);
return 1;
*/
from = "aucpp";
to = "mips";
} else {
printf("Setting up preparations:\n\n");
from = std::string(argv[find_argv(argc, argv, "-from") + 1]);
to = std::string(argv[find_argv(argc, argv, "-to") + 1]);
}
printf(" %s -> %s\n\n", from.c_str(), to.c_str());
generate_step_char(from, to);
printf("Starting the compilation of the language...\n");
// Compile the files (unnecessary if not testing)
errors += system("./builder2.sh");
// Run the binary of the compiler builder
errors += system("./builder");
printf("Language compilated.\n");
printf("Generating the compiler...\n");
// Compile3 will load the mreg and start
// passing values to
errors += system("./generator3.sh");
return errors;
}
// Returns n if found, 0 otherwise.
// It is meant to take argc and argv as arguments.
// As so, the first argument will always be the name of the program.
int find_argv(int argc, const char * argv[], const char * search){
for(int flag = 1; flag != argc; ++flag)
if(strcmp(argv[flag], search) == 0)
return flag;
return 0;
}
#endif