mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
Replace existing globals if a new name is given
This commit is contained in:
+15
-5
@@ -349,18 +349,21 @@ bool VariableManager::isEnv(Value *TheValue) {
|
||||
return TheValue == Env;
|
||||
}
|
||||
|
||||
// TODO: document that it can return nullptr
|
||||
GlobalVariable* VariableManager::getByCPUStateOffset(intptr_t Offset,
|
||||
std::string Name) {
|
||||
|
||||
GlobalsMap::iterator it = CPUStateGlobals.find(Offset);
|
||||
if (it != CPUStateGlobals.end()) {
|
||||
// TODO: handle renaming
|
||||
return it->second;
|
||||
} else {
|
||||
if (it == CPUStateGlobals.end() ||
|
||||
(Name.size() != 0 && !it->second->getName().equals_lower(Name))) {
|
||||
Type *VariableType = getTypeAtOffset(HelpersModuleLayout,
|
||||
CPUStateType,
|
||||
Offset);
|
||||
|
||||
// Unsupported type, let the caller handle the situation
|
||||
if (VariableType == nullptr)
|
||||
return nullptr;
|
||||
|
||||
if (Name.size() == 0) {
|
||||
std::stringstream NameStream;
|
||||
NameStream << "state_0x" << std::hex << Offset;
|
||||
@@ -374,11 +377,18 @@ GlobalVariable* VariableManager::getByCPUStateOffset(intptr_t Offset,
|
||||
ConstantInt::get(VariableType, 0),
|
||||
Name);
|
||||
assert(NewVariable != nullptr);
|
||||
|
||||
if (it != CPUStateGlobals.end()) {
|
||||
it->second->replaceAllUsesWith(NewVariable);
|
||||
it->second->eraseFromParent();
|
||||
}
|
||||
|
||||
CPUStateGlobals[Offset] = NewVariable;
|
||||
|
||||
return NewVariable;
|
||||
} else {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Value* VariableManager::getOrCreate(unsigned int TemporaryId) {
|
||||
|
||||
Reference in New Issue
Block a user