better process CRLF

This commit is contained in:
2024-10-10 15:53:16 +00:00
parent 0ddad5682a
commit cafd3ccdac
4 changed files with 37 additions and 24 deletions

View File

@ -76,5 +76,5 @@ fragment ESC : '\\n'| '\\"' | '\\\\';
// Whitespace and comments // Whitespace and comments
WS: [ \t\r\n]+ -> skip; WS: [ \t\r\n]+ -> skip;
LINE_COMMENT : '//' .*? '\r'? ('\n'|EOF) -> skip; LINE_COMMENT : '//' .*? ('\r\n'|'\r'|'\n'|EOF) -> skip;
BLOCK_COMMENT: '/*' .*? '*/' -> skip; BLOCK_COMMENT: '/*' .*? '*/' -> skip;

View File

@ -12,6 +12,11 @@ int main(int argc, char **argv) {
program.add_argument("-o", "--output").help("output file path").nargs(1).required(); program.add_argument("-o", "--output").help("output file path").nargs(1).required();
program.add_argument("--naive-IR")
.help("output unoptimized LLVM IR code")
.default_value(false)
.implicit_value(true);
try { try {
program.parse_args(argc, argv); program.parse_args(argc, argv);
} catch (const std::runtime_error &err) { } catch (const std::runtime_error &err) {
@ -22,13 +27,21 @@ int main(int argc, char **argv) {
auto input_file = program.get<std::string>("input"); auto input_file = program.get<std::string>("input");
auto output_file = program.get<std::string>("output"); auto output_file = program.get<std::string>("output");
bool output_naive_ir = program.get<bool>("--naive-IR");
std::ifstream fin(input_file); std::ifstream fin(input_file);
std::ofstream fout(output_file); std::ofstream fout(output_file);
std::shared_ptr<Program_ASTNode> ast; std::shared_ptr<Program_ASTNode> ast;
try { try {
SemanticCheck(fin, ast); SemanticCheck(fin, ast);
auto IR = BuildIR(ast); auto IR = BuildIR(ast);
// IR->RecursivePrint(fout); return 0;
if (output_naive_ir) {
IR->RecursivePrint(fout);
return 0;
}
IR->RecursivePrint(std::cerr); IR->RecursivePrint(std::cerr);
GenerateNaiveASM(fout, IR); GenerateNaiveASM(fout, IR);
} catch (const SemanticError &err) { } catch (const SemanticError &err) {

View File

@ -97,7 +97,7 @@ void mxlexerLexerInitialize() {
} }
); );
static const int32_t serializedATNSegment[] = { static const int32_t serializedATNSegment[] = {
4,0,61,411,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, 4,0,61,410,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,
7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21, 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,
7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28, 7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,27,7,27,2,28,
@ -124,17 +124,17 @@ void mxlexerLexerInitialize() {
346,8,60,10,60,12,60,349,9,60,1,61,4,61,352,8,61,11,61,12,61,353,1,62, 346,8,60,10,60,12,60,349,9,60,1,61,4,61,352,8,61,11,61,12,61,353,1,62,
1,62,1,62,5,62,359,8,62,10,62,12,62,362,9,62,1,62,1,62,1,63,1,63,1,63, 1,62,1,62,5,62,359,8,62,10,62,12,62,362,9,62,1,62,1,62,1,63,1,63,1,63,
1,63,1,63,1,63,3,63,372,8,63,1,64,4,64,375,8,64,11,64,12,64,376,1,64, 1,63,1,63,1,63,3,63,372,8,63,1,64,4,64,375,8,64,11,64,12,64,376,1,64,
1,64,1,65,1,65,1,65,1,65,5,65,385,8,65,10,65,12,65,388,9,65,1,65,3,65, 1,64,1,65,1,65,1,65,1,65,5,65,385,8,65,10,65,12,65,388,9,65,1,65,1,65,
391,8,65,1,65,3,65,394,8,65,1,65,1,65,1,66,1,66,1,66,1,66,5,66,402,8, 1,65,3,65,393,8,65,1,65,1,65,1,66,1,66,1,66,1,66,5,66,401,8,66,10,66,
66,10,66,12,66,405,9,66,1,66,1,66,1,66,1,66,1,66,3,360,386,403,0,67,1, 12,66,404,9,66,1,66,1,66,1,66,1,66,1,66,3,360,386,402,0,67,1,1,3,2,5,
1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29, 3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,
15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26, 16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26,53,27,
53,27,55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75, 55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75,38,77,
38,77,39,79,40,81,41,83,42,85,43,87,44,89,45,91,46,93,47,95,48,97,49, 39,79,40,81,41,83,42,85,43,87,44,89,45,91,46,93,47,95,48,97,49,99,50,
99,50,101,51,103,52,105,53,107,54,109,55,111,0,113,0,115,0,117,0,119, 101,51,103,52,105,53,107,54,109,55,111,0,113,0,115,0,117,0,119,0,121,
0,121,56,123,57,125,58,127,0,129,59,131,60,133,61,1,0,7,3,0,34,34,36, 56,123,57,125,58,127,0,129,59,131,60,133,61,1,0,7,3,0,34,34,36,36,92,
36,92,92,2,0,65,90,97,122,4,0,48,57,65,90,95,95,97,122,1,0,48,57,2,0, 92,2,0,65,90,97,122,4,0,48,57,65,90,95,95,97,122,1,0,48,57,2,0,34,34,
34,34,92,92,3,0,9,10,13,13,32,32,1,1,10,10,417,0,1,1,0,0,0,0,3,1,0,0, 92,92,3,0,9,10,13,13,32,32,2,1,10,10,13,13,416,0,1,1,0,0,0,0,3,1,0,0,
0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15, 0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,
1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0, 1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,
0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0, 0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,
@ -160,7 +160,7 @@ void mxlexerLexerInitialize() {
0,0,103,305,1,0,0,0,105,311,1,0,0,0,107,317,1,0,0,0,109,321,1,0,0,0,111, 0,0,103,305,1,0,0,0,105,311,1,0,0,0,107,317,1,0,0,0,109,321,1,0,0,0,111,
330,1,0,0,0,113,333,1,0,0,0,115,336,1,0,0,0,117,338,1,0,0,0,119,341,1, 330,1,0,0,0,113,333,1,0,0,0,115,336,1,0,0,0,117,338,1,0,0,0,119,341,1,
0,0,0,121,343,1,0,0,0,123,351,1,0,0,0,125,355,1,0,0,0,127,371,1,0,0,0, 0,0,0,121,343,1,0,0,0,123,351,1,0,0,0,125,355,1,0,0,0,127,371,1,0,0,0,
129,374,1,0,0,0,131,380,1,0,0,0,133,397,1,0,0,0,135,136,5,118,0,0,136, 129,374,1,0,0,0,131,380,1,0,0,0,133,396,1,0,0,0,135,136,5,118,0,0,136,
137,5,111,0,0,137,138,5,105,0,0,138,139,5,100,0,0,139,2,1,0,0,0,140,141, 137,5,111,0,0,137,138,5,105,0,0,138,139,5,100,0,0,139,2,1,0,0,0,140,141,
5,98,0,0,141,142,5,111,0,0,142,143,5,111,0,0,143,144,5,108,0,0,144,4, 5,98,0,0,141,142,5,111,0,0,142,143,5,111,0,0,143,144,5,108,0,0,144,4,
1,0,0,0,145,146,5,105,0,0,146,147,5,110,0,0,147,148,5,116,0,0,148,6,1, 1,0,0,0,145,146,5,105,0,0,146,147,5,110,0,0,147,148,5,116,0,0,148,6,1,
@ -223,14 +223,14 @@ void mxlexerLexerInitialize() {
375,7,5,0,0,374,373,1,0,0,0,375,376,1,0,0,0,376,374,1,0,0,0,376,377,1, 375,7,5,0,0,374,373,1,0,0,0,375,376,1,0,0,0,376,374,1,0,0,0,376,377,1,
0,0,0,377,378,1,0,0,0,378,379,6,64,0,0,379,130,1,0,0,0,380,381,5,47,0, 0,0,0,377,378,1,0,0,0,378,379,6,64,0,0,379,130,1,0,0,0,380,381,5,47,0,
0,381,382,5,47,0,0,382,386,1,0,0,0,383,385,9,0,0,0,384,383,1,0,0,0,385, 0,381,382,5,47,0,0,382,386,1,0,0,0,383,385,9,0,0,0,384,383,1,0,0,0,385,
388,1,0,0,0,386,387,1,0,0,0,386,384,1,0,0,0,387,390,1,0,0,0,388,386,1, 388,1,0,0,0,386,387,1,0,0,0,386,384,1,0,0,0,387,392,1,0,0,0,388,386,1,
0,0,0,389,391,5,13,0,0,390,389,1,0,0,0,390,391,1,0,0,0,391,393,1,0,0, 0,0,0,389,390,5,13,0,0,390,393,5,10,0,0,391,393,7,6,0,0,392,389,1,0,0,
0,392,394,7,6,0,0,393,392,1,0,0,0,394,395,1,0,0,0,395,396,6,65,0,0,396, 0,392,391,1,0,0,0,393,394,1,0,0,0,394,395,6,65,0,0,395,132,1,0,0,0,396,
132,1,0,0,0,397,398,5,47,0,0,398,399,5,42,0,0,399,403,1,0,0,0,400,402, 397,5,47,0,0,397,398,5,42,0,0,398,402,1,0,0,0,399,401,9,0,0,0,400,399,
9,0,0,0,401,400,1,0,0,0,402,405,1,0,0,0,403,404,1,0,0,0,403,401,1,0,0, 1,0,0,0,401,404,1,0,0,0,402,403,1,0,0,0,402,400,1,0,0,0,403,405,1,0,0,
0,404,406,1,0,0,0,405,403,1,0,0,0,406,407,5,42,0,0,407,408,5,47,0,0,408, 0,404,402,1,0,0,0,405,406,5,42,0,0,406,407,5,47,0,0,407,408,1,0,0,0,408,
409,1,0,0,0,409,410,6,66,0,0,410,134,1,0,0,0,13,0,328,330,347,353,358, 409,6,66,0,0,409,134,1,0,0,0,12,0,328,330,347,353,358,360,371,376,386,
360,371,376,386,390,393,403,1,6,0,0 392,402,1,6,0,0
}; };
staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0]));

File diff suppressed because one or more lines are too long