RawFunctionType: use NamedTypedRegister for return

Use the `NamedTypedRegister` type for return values in
`RawFunctionType`. This allows return values to be renamed at the user's
discretion.
This commit is contained in:
Giacomo Vercesi
2023-12-11 12:03:45 +01:00
committed by Alessandro Di Federico
parent 37ef77933c
commit 8504a96020
9 changed files with 14 additions and 14 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ fields:
- name: ReturnValues
sequence:
type: SortedVector
elementType: TypedRegister
elementType: NamedTypedRegister
- name: ReturnValueComment
type: string
optional: true
+1 -1
View File
@@ -42,7 +42,7 @@ inline auto CABIArgument = defineRank<"cabi-argument", detail::CAK>(Type);
inline auto RawArgument = defineRank<"raw-argument", detail::RAK>(Type);
inline auto ReturnValue = defineRank<"return-value", model::Type::Key>(Binary);
inline auto ReturnRegister = defineRank<"return-register",
model::TypedRegister::Key>(Type);
model::NamedTypedRegister::Key>(Type);
inline auto RawByte = defineRank<"raw-byte", MetaAddress>(Binary);
inline auto RawByteRange = defineRank<"raw-byte-range", MetaAddress>(RawByte);
+1 -1
View File
@@ -35,7 +35,7 @@ static TypePath defaultPrototype(Binary &TheBinary, model::ABI::Values ABI) {
}
for (const auto &Register : Defined.GeneralPurposeReturnValueRegisters()) {
TypedRegister ReturnValue(Register);
NamedTypedRegister ReturnValue(Register);
ReturnValue.Type() = buildType(Register, TheBinary);
Prototype.ReturnValues().insert(ReturnValue);
}
+3 -3
View File
@@ -22,7 +22,7 @@ namespace abi::FunctionType {
class ToCABIConverter {
private:
using ArgumentRegisters = TrackingSortedVector<model::NamedTypedRegister>;
using ReturnValueRegisters = TrackingSortedVector<model::TypedRegister>;
using ReturnValueRegisters = TrackingSortedVector<model::NamedTypedRegister>;
public:
struct Converted {
@@ -161,7 +161,7 @@ tryConvertToCABI(const model::RawFunctionType &FunctionType,
// Since CABI-FT only have one field for return value comments - we have no
// choice but to resort to concatenation in order to preserve as much
// information as possible.
for (model::TypedRegister ReturnValue : FunctionType.ReturnValues()) {
for (model::NamedTypedRegister ReturnValue : FunctionType.ReturnValues()) {
if (!ReturnValue.Comment().empty()) {
if (!NewType.ReturnValueComment().empty())
NewType.ReturnValueComment() += '\n';
@@ -400,7 +400,7 @@ TCC::tryConvertingReturnValue(const ReturnValueRegisters &Registers) {
// but for now the dumb approach should suffice.
abi::RegisterState::Map Map(model::ABI::getArchitecture(ABI.ABI()));
for (const model::TypedRegister &Register : Registers)
for (const model::NamedTypedRegister &Register : Registers)
Map[Register.Location()].IsUsedForReturningValues = abi::RegisterState::Yes;
abi::RegisterState::Map DeductionResults = Map;
if (UseSoftRegisterStateDeductions) {
+3 -3
View File
@@ -196,7 +196,7 @@ ToRawConverter::convert(const model::CABIFunctionType &FunctionType,
// The return value uses registers: pass them through to the new type.
for (model::Register::Values Register : ReturnValue.Registers) {
model::TypedRegister Converted;
model::NamedTypedRegister Converted;
Converted.Location() = Register;
const model::QualifiedType &ReturnType = FunctionType.ReturnType();
@@ -249,7 +249,7 @@ ToRawConverter::convert(const model::CABIFunctionType &FunctionType,
revng_assert(!ABI.GeneralPurposeReturnValueRegisters().empty());
auto FirstRegister = ABI.GeneralPurposeReturnValueRegisters()[0];
model::TypedRegister OutputPointer(FirstRegister);
model::NamedTypedRegister OutputPointer(FirstRegister);
OutputPointer.Type() = std::move(ReturnType);
NewType.ReturnValues().emplace(std::move(OutputPointer));
} else {
@@ -822,7 +822,7 @@ Layout::Layout(const model::RawFunctionType &Function) {
}
// Lay the return value out.
for (const model::TypedRegister &Register : Function.ReturnValues()) {
for (const model::NamedTypedRegister &Register : Function.ReturnValues()) {
auto &ReturnValue = ReturnValues.emplace_back();
ReturnValue.Registers = { Register.Location() };
ReturnValue.Type = Register.Type();
+2 -2
View File
@@ -357,7 +357,7 @@ DetectABI::buildPrototypeForIndirectCall(const FunctionSummary &CallerSummary,
}
if (abi::RegisterState::shouldEmit(RSRV)) {
TypedRegister TR(RegisterID);
NamedTypedRegister TR(RegisterID);
TR.Type() = { GenericType, {} };
ReturnValuesInserter.insert(TR);
}
@@ -428,7 +428,7 @@ void DetectABI::finalizeModel() {
}
if (abi::RegisterState::shouldEmit(RSRV)) {
TypedRegister TR(RegisterID);
NamedTypedRegister TR(RegisterID);
TR.Type() = {
Binary->getPrimitiveType(PrimitiveTypeKind::Generic, CSVSize), {}
};
+1 -1
View File
@@ -1227,7 +1227,7 @@ static RecursiveCoroutine<bool> verifyImpl(VerifyHelper &VH,
}
}
for (const TypedRegister &Return : T->ReturnValues())
for (const NamedTypedRegister &Return : T->ReturnValues())
if (not rc_recur Return.verify(VH))
rc_return VH.fail();
+1 -1
View File
@@ -456,7 +456,7 @@ gatherReturnValueComments(const model::Binary &Binary,
ptml::actions::Comment);
}
for (const model::TypedRegister &ReturnValue : FT->ReturnValues()) {
for (const model::NamedTypedRegister &ReturnValue : FT->ReturnValues()) {
model::Register::Values Register = ReturnValue.Location();
if (!ReturnValue.Comment().empty()) {
+1 -1
View File
@@ -573,7 +573,7 @@ BOOST_AUTO_TEST_CASE(RawFunctionTypes) {
// Add a return value
{
model::TypedRegister RAXReturnValue(model::Register::rax_x86_64);
model::NamedTypedRegister RAXReturnValue(model::Register::rax_x86_64);
RAXReturnValue.Type() = Generic64;
revng_check(RAXReturnValue.verify(true));
RAF->ReturnValues().insert(RAXReturnValue);