2021SC@SDUSC
本次博客的内容为MIRFunction类。
MIRFunction类定义在src/maple_ir/include/mir_function.h和src/maple_ir/src/mir_function.cpp之中。MIRFunction类对应的是MIR中的function,是module的下一层结构,所以function层面的信息和操作都在该类定义。
GStrIdx GetBaseClassNameStrIdx() const {
return baseClassStrIdx;
}
GStrIdx GetBaseFuncNameStrIdx() const {
return baseFuncStrIdx;
}
GStrIdx GetBaseFuncNameWithTypeStrIdx() const {
return baseFuncWithTypeStrIdx;
}
GStrIdx GetBaseFuncSigStrIdx() const {
return baseFuncSigStrIdx;
}
void SetBaseClassNameStrIdx(GStrIdx id) {
baseClassStrIdx = id;
}
void SetBaseFuncNameStrIdx(GStrIdx id) {
baseFuncStrIdx = id;
}
void SetBaseFuncNameWithTypeStrIdx(GStrIdx id) {
baseFuncWithTypeStrIdx = id;
}
使用类型strIdx更新签名 strIdx、basefunc, strIdx、baseclass,strIdx、basefunc\u
在不考虑baseclass_strIdx的情况下,basefunc_strIdx的原始非零值
参数strIdx新函数名的全名strIdx
bool IsJava() const {
return classTyIdx != 0u;
}
说明此函数是否为Java方法
void MIRFunction::UpdateFuncTypeAndFormals(const std::vector<MIRSymbol*> &symbols, bool clearOldArgs) {
auto newFuncType = ReconstructFormals(symbols, clearOldArgs);
auto newFuncTypeIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(newFuncType);
funcType = static_cast<MIRFuncType>(GlobalTables::GetTypeTable().GetTypeFromTyIdx(newFuncTypeIdx));
delete newFuncType;
}
更新函数类型和形式
void MIRFunction::UpdateFuncTypeAndFormalsAndReturnType(const std::vector<MIRSymbol*> &symbols, const TyIdx &retTyIdx,
bool clearOldArgs) {
auto newFuncType = ReconstructFormals(symbols, clearOldArgs);
newFuncType->SetRetTyIdx(retTyIdx);
auto newFuncTypeIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(newFuncType);
funcType = static_cast<MIRFuncType>(GlobalTables::GetTypeTable().GetTypeFromTyIdx(newFuncTypeIdx));
delete newFuncType;
}
更新函数类型和形式并返回类型
LabelIdx MIRFunction::GetOrCreateLableIdxFromName(const std::string &name) {
GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name);
LabelIdx labelIdx = GetLabelTab()->GetLabelIdxFromStrIdx(strIdx);
if (labelIdx == 0) {
labelIdx = GetLabelTab()->CreateLabel();
GetLabelTab()->SetSymbolFromStIdx(labelIdx, strIdx);
GetLabelTab()->AddToStringLabelMap(labelIdx);
}
return labelIdx;
}
从名称获取或创建标签Idx