cleanup
This commit is contained in:
parent
2b79d9bdb2
commit
577581f2ce
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
namespace xlang {
|
namespace xlang {
|
||||||
|
|
||||||
class EmitFunctionVisitor : public xlangBaseVisitor {};
|
|
||||||
|
|
||||||
EmitVisitor::EmitVisitor(std::string_view outputfile) : output{outputfile} {}
|
EmitVisitor::EmitVisitor(std::string_view outputfile) : output{outputfile} {}
|
||||||
|
|
||||||
std::any EmitVisitor::visitFile(xlangParser::FileContext *ctx) {
|
std::any EmitVisitor::visitFile(xlangParser::FileContext *ctx) {
|
||||||
|
@ -33,7 +31,7 @@ std::any EmitVisitor::visitFunction(xlangParser::FunctionContext *ctx) {
|
||||||
std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) {
|
std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) {
|
||||||
if (auto identifier = ctx->Identifier()) {
|
if (auto identifier = ctx->Identifier()) {
|
||||||
tmpcount = 0;
|
tmpcount = 0;
|
||||||
visitChildren(ctx);
|
visitExpr(ctx->expr());
|
||||||
output << " %_" << identifier->getSymbol()->getText() << " = w copy %t"
|
output << " %_" << identifier->getSymbol()->getText() << " = w copy %t"
|
||||||
<< tmpcount - 1 << std::endl;
|
<< tmpcount - 1 << std::endl;
|
||||||
return {};
|
return {};
|
||||||
|
@ -70,14 +68,14 @@ std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) {
|
||||||
}
|
}
|
||||||
if (ctx->Return()) {
|
if (ctx->Return()) {
|
||||||
tmpcount = 0;
|
tmpcount = 0;
|
||||||
visitChildren(ctx);
|
visitExpr(ctx->expr());
|
||||||
output << " ret %t" << tmpcount - 1 << std::endl;
|
output << " ret %t" << tmpcount - 1 << std::endl;
|
||||||
output << "@dead" << blockcount++ << std::endl;
|
output << "@dead" << blockcount++ << std::endl;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (ctx->Print()) {
|
if (ctx->Print()) {
|
||||||
tmpcount = 0;
|
tmpcount = 0;
|
||||||
visitChildren(ctx);
|
visitExpr(ctx->expr());
|
||||||
output << " call $printf(l $printformat, ..., w %t" << tmpcount - 1 << ")"
|
output << " call $printf(l $printformat, ..., w %t" << tmpcount - 1 << ")"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -9,7 +9,6 @@ statement : Identifier Assign expr Semicolon
|
||||||
| While expr block
|
| While expr block
|
||||||
| Return expr Semicolon
|
| Return expr Semicolon
|
||||||
| Print expr Semicolon
|
| Print expr Semicolon
|
||||||
| expr Semicolon
|
|
||||||
;
|
;
|
||||||
expr : sum ((Less|LessEqual|Greater|GreaterEqual|Equal|NotEqual) sum)
|
expr : sum ((Less|LessEqual|Greater|GreaterEqual|Equal|NotEqual) sum)
|
||||||
| sum
|
| sum
|
||||||
|
|
Loading…
Reference in a new issue