增加了全局变量的定义

main
wqz 3 years ago
parent a8e11e8e97
commit d2e2830f06

@ -505,6 +505,18 @@ namespace sysy
printOperand(os, getPointer()) << " : " << *getValue()->getType();
}
void GlobalValue::print(std::ostream &os) const
{
auto type = getType();
printVarName(os, this) << ' ';
if (isConst)
os << " const ";
os << *static_cast<const PointerType *>(getType())->getBaseType()
<< " : " << *type << ' ';
if (init())
os << *init();
}
void Function::print(std::ostream &os) const
{
auto returnType = getReturnType();

2000
src/IR.h

File diff suppressed because it is too large Load Diff

@ -35,7 +35,7 @@ namespace sysy
// error(ctx, "not implemented yet");
std::vector<Value *> values;
bool isConst = ctx->CONST();
auto type = any_cast<Type *>(visitBtype(ctx->btype()));
auto type = Type::getPointerType(any_cast<Type *>(visitBtype(ctx->btype())));
for (auto varDef : ctx->varDef())
{
auto name = varDef->lValue()->ID()->getText();
@ -45,7 +45,9 @@ namespace sysy
auto init = varDef->ASSIGN()
? any_cast<Value *>(visitInitValue(varDef->initValue()))
: nullptr;
values.push_back(module->createGlobalValue(name, type, dims, init));
auto global_value = module->createGlobalValue(name, type, dims, init);
symbols.insert(name, global_value);
values.push_back(global_value);
}
// FIXME const
return values;

Loading…
Cancel
Save