Commit 9e13604b authored by 李晓奇's avatar 李晓奇

88 points, wow hahaha!

parent b8f14d6d
...@@ -110,6 +110,10 @@ PB20111654 李晓奇 ...@@ -110,6 +110,10 @@ PB20111654 李晓奇
- 发现ifelse语句忘了无条件跳转了…… - 发现ifelse语句忘了无条件跳转了……
- 返现布尔表达式必须使用i1类型,类型要求真的太严格了!! - 返现布尔表达式必须使用i1类型,类型要求真的太严格了!!
- 知道了为什么clang生成的中间代码,会把实参声明一遍再拷贝了。
在我看来方便编译器代码的生成,因为重新声明,push给scope的值是指针类型而不是纯值,这在后边访问Var中有用。
## 实验设计 ## 实验设计
......
...@@ -262,18 +262,21 @@ void CminusfBuilder::visit(ASTFunDeclaration &node) { ...@@ -262,18 +262,21 @@ void CminusfBuilder::visit(ASTFunDeclaration &node) {
void CminusfBuilder::visit(ASTParam &node) { void CminusfBuilder::visit(ASTParam &node) {
//!TODO: This function is empty now. //!TODO: This function is empty now.
// If the parameter is int|float, copy and store them // If the parameter is int|float, copy and store them
auto param_value = cur_value;
switch (node.type) { switch (node.type) {
case TYPE_INT: { case TYPE_INT: {
scope.push(node.id, cur_value); cur_value = builder->create_alloca(INT32_T);
break; break;
} }
case TYPE_FLOAT: { case TYPE_FLOAT: {
scope.push(node.id, cur_value); cur_value = builder->create_alloca(FLOAT_T);
break; break;
} }
case TYPE_VOID: case TYPE_VOID:
break; return;
} }
scope.push(node.id, cur_value);
builder->create_store(param_value, cur_value);
} }
// Done? // Done?
...@@ -314,17 +317,30 @@ void CminusfBuilder::visit(ASTSelectionStmt &node) { ...@@ -314,17 +317,30 @@ void CminusfBuilder::visit(ASTSelectionStmt &node) {
node.expression->accept(*this); node.expression->accept(*this);
auto cond = cur_value; auto cond = cur_value;
cast_to_i1(cond); cast_to_i1(cond);
auto TBB = BasicBlock::create(builder->get_module(), "", cur_fun);
auto FBB = BasicBlock::create(builder->get_module(), "", cur_fun);
builder->create_cond_br(cond, TBB, FBB);
builder->set_insert_point(TBB);
node.if_statement->accept(*this);
builder->create_br(FBB);
builder->set_insert_point(FBB); auto ifBB = BasicBlock::create(builder->get_module(), "", cur_fun);
auto endBB = BasicBlock::create(builder->get_module(), "", cur_fun);
if (node.else_statement) { if (node.else_statement) {
auto elseBB = BasicBlock::create(builder->get_module(), "", cur_fun);
builder->create_cond_br(cond, ifBB, elseBB);
builder->set_insert_point(ifBB);
node.if_statement->accept(*this);
builder->create_br(endBB);
builder->set_insert_point(elseBB);
node.else_statement->accept(*this); node.else_statement->accept(*this);
builder->create_br(endBB);
builder->set_insert_point(endBB);
} else {
builder->create_cond_br(cond, ifBB, endBB);
builder->set_insert_point(ifBB);
node.if_statement->accept(*this);
builder->create_br(endBB);
builder->set_insert_point(endBB);
} }
scope.exit(); 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