Commit 698a4326 authored by 李晓奇's avatar 李晓奇

I got the result right!

parent 78e208f5
......@@ -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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment