基本实现后端,生成的汇编代码可以得到能正确执行的程序。

main
wqz 3 years ago
parent 5ef648e9fa
commit c6e8ff282e

@ -48,6 +48,7 @@ namespace backend
{
string code;
code += space + ".global " + func->getName() + endl;
code += space + ".arm" + endl;
code += space + ".p2align " + std::to_string(int_p2align) + endl;
code += space + ".type " + func->getName() + ", %function" + endl;
code += func->getName() + ":" + endl;
@ -242,12 +243,12 @@ namespace backend
string lname, rname;
auto lhs = bInst->getLhs();
if (isa<ConstantValue>(lhs))
lname = to_string(dynamic_cast<ConstantValue *>(lhs)->getInt());
lname = "#" + to_string(dynamic_cast<ConstantValue *>(lhs)->getInt());
else
lname = "r" + lhs->getName();
auto rhs = bInst->getRhs();
if (isa<ConstantValue>(rhs))
rname = to_string(dynamic_cast<ConstantValue *>(rhs)->getInt());
rname = "#" + to_string(dynamic_cast<ConstantValue *>(rhs)->getInt());
else
rname = "r" + rhs->getName();
auto res = stoi(bInst->getName());
@ -296,6 +297,10 @@ namespace backend
code += space + "mov\tr3, #" + to_string(constant_value) + endl;
code += space + "str\tr3, [fp, #" + to_string(offset) + "]" + endl;
}
else if (isa<CallInst>(value))
{
code += space + "str\tr0, [fp, #" + to_string(offset) + "]" + endl;
}
else
{
code += space + "str\tr" + value->getName() + ", [fp, #" + to_string(offset) + "]" + endl;

@ -55,7 +55,7 @@ using std::vector;
namespace backend
{
static const string space = string(4, ' ');
static const string space = "\t";
static const string endl = "\n";
// only for armv7
static const int int_align = 4;

Loading…
Cancel
Save