diff --git a/Reports/3-ir-gen/report.md b/Reports/3-ir-gen/report.md index e68bd7df033e5164485185d1f1e555a296b19c60..e84fed427cbd1f89777b472f3bd193fff83d34e2 100644 --- a/Reports/3-ir-gen/report.md +++ b/Reports/3-ir-gen/report.md @@ -63,6 +63,12 @@ PB20111654 鏉庢檽濂� - 鍦ㄤ紶閫掔粰鍑芥暟鏃讹紝鍙兘浼犻€掓暟缁勶紝浣嗘槸浼犻€掍负鎸囬拡銆� +6. 璁板綍閬囧埌鐨勫潙 + + - 褰㈠杩欑浜х敓寮忓瓙`term鈫抰erm聽mulop聽factor聽鈭B爁actor`锛屾垜涓轰簡鍥炬柟渚垮厛姹備簡`factor`锛屽湪鏍规嵁`term`鐨勬湁璋冪敤`accept()`锛屼絾鏄繖鏍蜂細瀵艰嚧宸﹀彸鎿嶄綔鏁伴鍊掋€� + - 鎴戝浜庣被鍨嬭浆鎹㈢殑鎺у埗姣旇緝涓ユ牸锛屾病鑰冭檻鍒扮殑涓€鐜嘺bort锛屽洜姝ゅ緢蹇彂鐜颁簡婕忔帀浜哹ool绫诲瀷鐨勮浆鎹€€� + - 鎺ヤ笂鏉★紝涓€浜涚被鍨嬭浆鎹㈢殑bug锛歚i32`鍒癭i1`涔熸槸闇€瑕佽浆鎹㈢殑锛屽紑濮嬪仛鐨勬椂鍊欒繕娌℃剰璇嗗埌杩欎簺锛堜富瑕佹槸娌℃剰璇嗗埌`i1`鐨勫瓨鍦級銆� + ## 瀹為獙璁捐 璇峰啓鏄庝负浜嗛『鍒╁畬鎴愭湰娆″疄楠岋紝鍔犲叆浜嗗摢浜涗寒鐐硅璁★紝骞跺杩欎簺璁捐杩涜瑙i噴銆� diff --git a/src/cminusfc/cminusf_builder.cpp b/src/cminusfc/cminusf_builder.cpp index f7e1a6ea712381b78b29c0249a7ad2057f256ae1..15e5e7fe9bc728f1745923b04a31965a102fa579 100644 --- a/src/cminusfc/cminusf_builder.cpp +++ b/src/cminusfc/cminusf_builder.cpp @@ -48,13 +48,20 @@ void CminusfBuilder::type_cast(Value *&lvalue, Value *&rvalue, std::string util) assert(not Type::is_eq_type(lvalue->get_type(), rvalue->get_type())); // only support cast between int and float - if (Type::is_eq_type(lvalue->get_type(), INT32_T) and Type::is_eq_type(rvalue->get_type(), FLOAT_T)) + if (lvalue->get_type()->is_integer_type() and rvalue->get_type()->is_float_type()) lvalue = builder->create_sitofp(lvalue, FLOAT_T); - else if (Type::is_eq_type(lvalue->get_type(), FLOAT_T) and Type::is_eq_type(rvalue->get_type(), INT32_T)) + else if (lvalue->get_type()->is_float_type() and rvalue->get_type()->is_integer_type()) rvalue = builder->create_sitofp(rvalue, FLOAT_T); else { // but we only support computing between int and float error_exit("not supported type cast for " + util); } + /* if (Type::is_eq_type(lvalue->get_type(), INT32_T) and Type::is_eq_type(rvalue->get_type(), FLOAT_T)) + * lvalue = builder->create_sitofp(lvalue, FLOAT_T); + * else if (Type::is_eq_type(lvalue->get_type(), FLOAT_T) and Type::is_eq_type(rvalue->get_type(), INT32_T)) + * rvalue = builder->create_sitofp(rvalue, FLOAT_T); + * else { // but we only support computing between int and float + * error_exit("not supported type cast for " + util); + * } */ } void CminusfBuilder::visit(ASTProgram &node) { @@ -302,7 +309,7 @@ void CminusfBuilder::visit(ASTReturnStmt &node) { // type cast // return type can only be int, float or void if (not Type::is_eq_type(cur_fun->get_return_type(), cur_value->get_type())) { - if (not cur_value->get_type()->is_integer_type() or not cur_value->get_type()->is_float_type()) + if (not cur_value->get_type()->is_integer_type() and not cur_value->get_type()->is_float_type()) error_exit("unsupported return type"); if (cur_value->get_type()->is_integer_type()) cur_value = builder->create_sitofp(cur_value, FLOAT_T); @@ -524,15 +531,18 @@ void CminusfBuilder::visit(ASTCall &node) { cur_value = builder->create_gep(cur_value, {0, 0}); } else if (param_type->is_integer_type() or param_type->is_float_type()) { // need type cast between int and float - if (Type::is_eq_type(cur_value->get_type(), INT32_T)) + if (not cur_value->get_type()->is_integer_type() and not cur_value->get_type()->is_float_type()) + error_exit("unexpected type cast!"); + + if (param_type->is_float_type()) cur_value = builder->create_sitofp(cur_value, FLOAT_T); - else if (Type::is_eq_type(cur_value->get_type(), FLOAT_T)) + else if (param_type->is_integer_type()) cur_value = builder->create_fptosi(cur_value, INT32_T); else error_exit("unexpected type cast!"); } else - error_exit("unexpected case when casting arguments for function call" + node.id); + error_exit("unexpected case when casting arguments for function call " + node.id); } // now cur_value fits the param type