From 698a43267a9cf697843417d6022a613d5fc00d7e Mon Sep 17 00:00:00 2001 From: LiXiaoQi Date: Sun, 30 Oct 2022 23:47:52 +0800 Subject: [PATCH] I got the result right! --- src/cminusfc/cminusf_builder.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/cminusfc/cminusf_builder.cpp b/src/cminusfc/cminusf_builder.cpp index ca18a5f..b6f45e5 100644 --- a/src/cminusfc/cminusf_builder.cpp +++ b/src/cminusfc/cminusf_builder.cpp @@ -182,8 +182,29 @@ void CminusfBuilder::visit(ASTVarDeclaration &node) { if (global) cur_value = GlobalVariable::create(node.id, builder->get_module(), FLOAT_T, false, FloatInitializer); - else - cur_value = builder->create_alloca(INT32_T); + else { + /* Beautiful is better than ugly. + * Explicit is better than implicit. + * Simple is better than complex. + * Complex is better than complicated. + * Flat is better than nested. + * Sparse is better than dense. + * Readability counts. + * Special cases aren't special enough to break the rules. + * Although practicality beats purity. + * Errors should never pass silently. + * Unless explicitly silenced. + * In the face of ambiguity, refuse the temptation to guess. + * There should be one-- and preferably only one --obvious way to do it. + * Although that way may not be obvious at first unless you're Dutch. + * Now is better than never. + * Although never is often better than *right* now. + * If the implementation is hard to explain, it's a bad idea. + * If the implementation is easy to explain, it may be a good idea. + * Namespaces are one honking great idea -- let's do more of those! */ + // cur_value = builder->create_alloca(INT32_T); + cur_value = builder->create_alloca(FLOAT_T); + } break; default: error_exit("Variable type(not array) is not int or float"); @@ -296,6 +317,7 @@ void CminusfBuilder::visit(ASTCompoundStmt &node) { * builder->create_br(bb); * builder->set_insert_point(bb); */ scope.enter(); + for (auto &decl : node.local_declarations) { decl->accept(*this); } @@ -305,6 +327,7 @@ void CminusfBuilder::visit(ASTCompoundStmt &node) { if (builder->get_insert_block()->get_terminator() != nullptr) break; } + scope.exit(); } -- GitLab