This commit is contained in:
Thomas Lindner 2023-01-05 19:37:22 +01:00
parent 2b79d9bdb2
commit 577581f2ce
2 changed files with 3 additions and 6 deletions

View file

@ -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 {};

View file

@ -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