globalvalue汇编代码生成,但是还不完整

main
wqz 3 years ago
parent faf16ff4bd
commit 601c2e8264

@ -18,11 +18,16 @@ namespace backend
string textCode;
// clear last module's label record
clearModuleRecord(module);
// generate asmcode for all global values
dataCode += globaldata_gen();
code += space + ".arch armv7ve " + endl;
code += space + ".text " + endl;
// generate asmcode for all global values
auto global_values = module->getGlobalValues();
for (auto iter = global_values->begin(); iter != global_values->end(); ++iter)
{
GlobalValue *glbvl = iter->second;
dataCode += globaldata_gen(glbvl);
}
// generate asmcode for all functions
auto functions = module->getFunctions();
for (auto iter = functions->begin(); iter != functions->end(); ++iter)
@ -310,12 +315,44 @@ namespace backend
return code;
}
//
string CodeGen::globaldata_gen()
string CodeGen::globaldata_gen(GlobalValue *glbvl)
{
string asmCode;
/**
*code in here
*/
string name = glbvl->getName();
asmCode += space + ".global\t" + name + endl;
auto type = static_cast<const PointerType *>(glbvl->getType())->getBaseType();
// has init
if (glbvl->init())
{
asmCode += space + ".data" + endl;
{
asmCode += space + ".align\t2" + endl;
}
asmCode += space + ".type\t" + name + ", " + "%" + "object" + endl;
asmCode += space + ".size\t" + name + ", 4" + endl;
asmCode += name + ":\n";
auto value = dyncast<ConstantValue>(glbvl->getOperand(0));
std::stringstream ss;
if (type->isInt())
ss << value->getInt();
else if (type->isFloat())
ss << value->getFloat();
asmCode += space + ".word\t" + ss.str() + endl;
}
// no init
else
{
asmCode += space + ".bss" + endl;
{
asmCode += space + ".align\t2" + endl;
}
asmCode += space + ".type\t" + name + ", %object" + endl;
asmCode += space + ".size\t" + name + ", 4" + endl;
asmCode += name + ":\n";
asmCode += space + ".space\t4" + endl;
}
return asmCode;
}

@ -26,6 +26,7 @@
#include <algorithm>
#include <IR.h>
#include <vector>
#include <sstream>
using namespace sysy;
using std::find;
@ -190,7 +191,7 @@ namespace backend
string function_gen(Function *func);
string basicBlock_gen(BasicBlock *bb);
string instruction_gen(Instruction *instr);
string globaldata_gen();
string globaldata_gen(GlobalValue *glbvl);
string prologueCode_gen(Function *func);
string epilogueCode_gen(Function *func);
string literalPoolsCode_gen(Function *func);

Loading…
Cancel
Save