mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
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:
committed by
Alessandro Di Federico
parent
37ef77933c
commit
8504a96020
@@ -21,7 +21,7 @@ fields:
|
||||
- name: ReturnValues
|
||||
sequence:
|
||||
type: SortedVector
|
||||
elementType: TypedRegister
|
||||
elementType: NamedTypedRegister
|
||||
- name: ReturnValueComment
|
||||
type: string
|
||||
optional: true
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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
@@ -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();
|
||||
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user