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