Code Snippet
unsafe static string GetStringFromOperand(Phx.IR.Operand operand)
{
// Only variable operands with non local variable symbols will represent initialized strings.
if (!operand.IsVariableOperand)
{
return null;
}
Phx.Symbols.Symbol symbol = operand.Symbol;
if (symbol == null || !symbol.IsNonLocalVariableSymbol)
{
return null;
}
Phx.Symbols.GlobalVariableSymbol globalSymbol = symbol.AsNonLocalVariableSymbol.GlobalSymbol;
if (globalSymbol.Location == null)
{
return null;
}
Phx.IR.DataInstruction dataInstruction = globalSymbol.Location.AsDataLocation.DataInstruction;
// Now see if we have an initialized string, or a pointer to an initialized string. The latter
// will be represented via a fixup.
Phx.Targets.Architectures.Fixup fixupList = dataInstruction.FixupList;
if (fixupList != null)
{
if (fixupList.TargetSymbol != null)
{
Phx.Symbols.Symbol fixupSymbol = fixupList.TargetSymbol;
if (fixupSymbol.Location != null && fixupSymbol.Location.IsDataLocation)
{
Phx.IR.DataInstruction fixupInstruction = dataInstruction.FixupList.TargetSymbol.Location.AsDataLocation.DataInstruction;
return Phx.Utility.Utf8Decode(fixupInstruction.GetDataPointer(0), (int)fixupInstruction.ByteSize);
}
}
}
else
{
return Phx.Utility.Utf8Decode(dataInstruction.GetDataPointer(0), (int)dataInstruction.ByteSize);
}
return null;
}