diff --git a/include/revng/ABI/CType.h b/include/revng/ABI/CType.h new file mode 100644 index 000000000..c07a5ee29 --- /dev/null +++ b/include/revng/ABI/CType.h @@ -0,0 +1,9 @@ +#pragma once + +// +// This file is distributed under the MIT License. See LICENSE.md for details. +// + +#include "revng/ABI/Generated/Early/CType.h" + +#include "revng/ABI/Generated/Late/CType.h" diff --git a/include/revng/ABI/Definition.h b/include/revng/ABI/Definition.h index f16851666..ca53eb6b0 100644 --- a/include/revng/ABI/Definition.h +++ b/include/revng/ABI/Definition.h @@ -12,6 +12,7 @@ #include "revng/Model/ABI.h" #include "revng/Model/RawFunctionDefinition.h" #include "revng/Model/Register.h" +#include "revng/Support/CDataModel.h" #include "revng/Support/Debug.h" #include "revng/TupleTree/TupleTree.h" #include "revng/TupleTree/TupleTreeDiff.h" @@ -34,6 +35,11 @@ public: return model::ABI::getArchitecture(ABI()); } + [[nodiscard]] const ScalarType *findIntegerType(uint64_t Size) const; + [[nodiscard]] const ScalarType *findFloatingPointType(uint64_t Size) const; + + const ScalarType &getWidestIntegerType() const; + /// Make sure current definition is valid. bool verify() const debug_function; @@ -108,6 +114,8 @@ public: return alignedOffset(Offset, *alignment(Type)); } + [[nodiscard]] CDataModel getDataModel() const; + public: using RegisterSet = std::set; diff --git a/include/revng/ABI/ScalarKind.h b/include/revng/ABI/ScalarKind.h new file mode 100644 index 000000000..3dfa67de5 --- /dev/null +++ b/include/revng/ABI/ScalarKind.h @@ -0,0 +1,9 @@ +#pragma once + +// +// This file is distributed under the MIT License. See LICENSE.md for details. +// + +#include "revng/ABI/Generated/Early/ScalarKind.h" + +#include "revng/ABI/Generated/Late/ScalarKind.h" diff --git a/include/revng/ABI/ScalarType.h b/include/revng/ABI/ScalarType.h index c5368982f..a53c038ea 100644 --- a/include/revng/ABI/ScalarType.h +++ b/include/revng/ABI/ScalarType.h @@ -6,6 +6,9 @@ #include +#include "revng/ABI/CType.h" +#include "revng/ABI/ScalarKind.h" + #include "revng/ABI/Generated/Early/ScalarType.h" namespace abi { diff --git a/include/revng/ABI/abi-internal-schema.yml b/include/revng/ABI/abi-internal-schema.yml index a1f23208a..acad79f87 100644 --- a/include/revng/ABI/abi-internal-schema.yml +++ b/include/revng/ABI/abi-internal-schema.yml @@ -102,11 +102,6 @@ definitions: type: SortedVector elementType: ScalarType - - name: FloatingPointScalarTypes - sequence: - type: SortedVector - elementType: ScalarType - key: - ABI @@ -116,15 +111,47 @@ definitions: Represents type specific information ABI needs to be aware of, for example, alignment. fields: + - name: Kind + type: ScalarKind + - name: Size type: uint64_t default: -1 + # TODO: For MS x86 ABIs, alignment of 4 is incorrectly used for long + # long. The reason being that the MS ABI seems to align all stack + # arguments to 4 bytes. To fix this, a separate stack alignment + # field is probably needed (single per-ABI value may be enough). + - name: AlignedAt doc: | When set to `0`, the alignment of this type matches its size. type: uint64_t default: 0 + - name: CTypes + sequence: + type: SortedVector + elementType: CType + key: + - Kind - Size + + - name: ScalarKind + type: enum + members: + - name: Integer + - name: FloatingPoint + + - name: CType + type: enum + members: + - name: Char + - name: Short + - name: Int + - name: Long + - name: LongLong + - name: Float + - name: Double + - name: LongDouble diff --git a/lib/ABI/Definition.cpp b/lib/ABI/Definition.cpp index 5541595ce..80f3f19b3 100644 --- a/lib/ABI/Definition.cpp +++ b/lib/ABI/Definition.cpp @@ -13,6 +13,8 @@ #include "revng/Support/ResourceFinder.h" #include "revng/Support/YAMLTraits.h" +namespace { + template bool verifyRegisters(const RegisterContainer &Registers, model::Architecture::Values Architecture) { @@ -29,7 +31,7 @@ bool verifyRegisters(const RegisterContainer &Registers, return true; } -static bool isVectorRegister(model::Register::Values Register) { +bool isVectorRegister(model::Register::Values Register) { using model::Register::primitiveKind; return primitiveKind(Register) == model::PrimitiveKind::Float; } @@ -41,7 +43,7 @@ static bool isVectorRegister(model::Register::Values Register) { /// see the `static_assert` that invokes it in \ref distributeArguments /// /// \return `true` if the ABI is valid, `false` otherwise. -static bool verifyReturnValueLocation(const abi::Definition &D) { +bool verifyReturnValueLocation(const abi::Definition &D) { if (not model::Register::isValid(D.ReturnValueLocationRegister())) { // Skip ABIs that do not allow returning big values. // They do not benefit from this check. @@ -74,8 +76,42 @@ static bool verifyReturnValueLocation(const abi::Definition &D) { return true; } +abi::ScalarKind::Values getScalarKind(abi::CType::Values Type) { + if (abi::CType::Char <= Type and Type <= abi::CType::LongLong) + return abi::ScalarKind::Integer; + + if (abi::CType::Float <= Type and Type <= abi::CType::LongDouble) + return abi::ScalarKind::FloatingPoint; + + return abi::ScalarKind::Invalid; +} + +} // namespace + namespace abi { +const ScalarType *Definition::findIntegerType(uint64_t Size) const { + // TODO: If and when invalidation tracking is introduced for ABI definitions, + // this function should be changed to use tryGet in place of find. + auto I = ScalarTypes().find({ ScalarKind::Integer, Size }); + return I != ScalarTypes().end() ? &*I : nullptr; +} + +const ScalarType *Definition::findFloatingPointType(uint64_t Size) const { + // TODO: If and when invalidation tracking is introduced for ABI definitions, + // this function should be changed to use tryGet in place of find. + auto I = ScalarTypes().find({ ScalarKind::FloatingPoint, Size }); + return I != ScalarTypes().end() ? &*I : nullptr; +} + +const ScalarType &Definition::getWidestIntegerType() const { + for (const ScalarType &Type : llvm::reverse(ScalarTypes())) { + if (Type.Kind() == ScalarKind::Integer) + return Type; + } + revng_abort("Invalid ABI definition."); +} + bool Definition::verify() const { if (not model::ABI::isValid(ABI())) return false; @@ -104,16 +140,39 @@ bool Definition::verify() const { if (ScalarTypes().empty()) return false; - for (const abi::ScalarType &Type : ScalarTypes()) + bool CTypes[CType::Count] = {}; + bool HasIntegerScalar = false; + + for (const abi::ScalarType &Type : ScalarTypes()) { + if (Type.Kind() == ScalarKind::Invalid) + return false; + + if (Type.Kind() == ScalarKind::Integer) + HasIntegerScalar = true; + if (Type.Size() == 0) return false; - if (FloatingPointScalarTypes().empty()) + for (auto CT : Type.CTypes()) { + if (CT == CType::Invalid) + return false; + + // The C type kind must match the scalar kind. + if (getScalarKind(CT) != Type.Kind()) + return false; + + // The ABI may not associate the same C type with multiple scalars. + if (std::exchange(CTypes[CT], true)) + return false; + } + } + + // The ABI must define at least one integer scalar. + if (not HasIntegerScalar) return false; - for (const abi::ScalarType &Type : FloatingPointScalarTypes()) - if (Type.Size() == 0) - return false; + if (not getDataModel().verify()) + return false; return true; } @@ -337,7 +396,7 @@ naturalAlignment(const abi::Definition &ABI, } else if (const auto *P = llvm::dyn_cast(&Type)) { // Doesn't matter what the type is, use alignment of the pointer. - rc_return AlignmentInfo{ ABI.ScalarTypes().at(P->PointerSize()).alignedAt(), + rc_return AlignmentInfo{ ABI.findIntegerType(P->PointerSize())->alignedAt(), true }; } else if (const auto *P = llvm::dyn_cast(&Type)) { @@ -348,17 +407,15 @@ naturalAlignment(const abi::Definition &ABI, rc_return AlignmentInfo{ 0, false }; } else if (P->PrimitiveKind() == model::PrimitiveKind::Float) { - auto Iterator = ABI.FloatingPointScalarTypes().find(P->Size()); - if (Iterator == ABI.FloatingPointScalarTypes().end()) - rc_return std::nullopt; + if (auto ABIType = ABI.findFloatingPointType(P->Size())) + rc_return AlignmentInfo{ ABIType->alignedAt(), true }; - rc_return AlignmentInfo{ Iterator->alignedAt(), true }; + rc_return std::nullopt; } else { - auto Iterator = ABI.ScalarTypes().find(P->Size()); - if (Iterator == ABI.ScalarTypes().end()) - rc_return std::nullopt; + if (auto ABIType = ABI.findIntegerType(P->Size())) + rc_return AlignmentInfo{ ABIType->alignedAt(), true }; - rc_return AlignmentInfo{ Iterator->alignedAt(), true }; + rc_return std::nullopt; } } else { revng_abort("Unsupported type."); @@ -418,4 +475,44 @@ Definition::hasNaturalAlignment(const model::TypeDefinition &Type, return Result->IsNatural; } +CDataModel Definition::getDataModel() const { + CDataModel DM = CDataModel::getDefaultDataModel(getPointerSize()); + + for (const ScalarType &Type : ScalarTypes()) { + for (auto CT : Type.CTypes()) { + switch (CT) { + case CType::Char: + DM.getStandardTypeSize(CStandardType::Char) = Type.Size(); + break; + case CType::Short: + DM.getStandardTypeSize(CStandardType::Short) = Type.Size(); + break; + case CType::Int: + DM.getStandardTypeSize(CStandardType::Int) = Type.Size(); + break; + case CType::Long: + DM.getStandardTypeSize(CStandardType::Long) = Type.Size(); + break; + case CType::LongLong: + DM.getStandardTypeSize(CStandardType::LongLong) = Type.Size(); + break; + case CType::Float: + DM.getStandardTypeSize(CStandardType::Float) = Type.Size(); + break; + case CType::Double: + DM.getStandardTypeSize(CStandardType::Double) = Type.Size(); + break; + case CType::LongDouble: + DM.getStandardTypeSize(CStandardType::LongDouble) = Type.Size(); + break; + case CType::Invalid: + case CType::Count: + revng_abort("Invalid C type in ABI definition."); + } + } + } + + return DM; +} + } // namespace abi diff --git a/lib/ABI/FunctionType/Conversion.cpp b/lib/ABI/FunctionType/Conversion.cpp index 9e6f1bce0..77a54b6f1 100644 --- a/lib/ABI/FunctionType/Conversion.cpp +++ b/lib/ABI/FunctionType/Conversion.cpp @@ -698,7 +698,7 @@ TCC::tryConvertingReturnValue(RFTReturnValues Registers) { // into preserving it at least partially. uint64_t PointerSize = model::ABI::getPointerSize(ABI.ABI()); uint64_t PrimitiveSize = Ordered.size() * PointerSize; - if (ABI.ScalarTypes().contains(PrimitiveSize)) { + if (ABI.findIntegerType(PrimitiveSize) != nullptr) { return model::PrimitiveType::makeGeneric(PrimitiveSize); } else { revng_log(Log, diff --git a/share/revng/abi/AAPCS.yml b/share/revng/abi/AAPCS.yml index 3cb4921e4..086a1b88a 100644 --- a/share/revng/abi/AAPCS.yml +++ b/share/revng/abi/AAPCS.yml @@ -61,12 +61,17 @@ ReturnValueLocationRegister: r0_arm ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - -FloatingPointScalarTypes: - - Size: 2 - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/AAPCS64.yml b/share/revng/abi/AAPCS64.yml index d8c5b28df..3dd039fba 100644 --- a/share/revng/abi/AAPCS64.yml +++ b/share/revng/abi/AAPCS64.yml @@ -87,14 +87,23 @@ ReturnValueLocationRegister: x8_aarch64 ReturnValueLocationIsReturned: false ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 - -FloatingPointScalarTypes: - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: Integer + Size: 16 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 + - Kind: FloatingPoint + Size: 16 # IEEE Binary128 + CTypes: + - LongDouble diff --git a/share/revng/abi/Apple_AAPCS64.yml b/share/revng/abi/Apple_AAPCS64.yml index 23639996d..86965f78a 100644 --- a/share/revng/abi/Apple_AAPCS64.yml +++ b/share/revng/abi/Apple_AAPCS64.yml @@ -87,14 +87,23 @@ ReturnValueLocationRegister: x8_aarch64 ReturnValueLocationIsReturned: false ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 - -FloatingPointScalarTypes: - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: Integer + Size: 16 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 + - Kind: FloatingPoint + Size: 16 # IEEE Binary128 + CTypes: + - LongDouble diff --git a/share/revng/abi/Microsoft_AAPCS64.yml b/share/revng/abi/Microsoft_AAPCS64.yml index 9a52c82d5..9502dd4d8 100644 --- a/share/revng/abi/Microsoft_AAPCS64.yml +++ b/share/revng/abi/Microsoft_AAPCS64.yml @@ -87,14 +87,23 @@ ReturnValueLocationRegister: x8_aarch64 ReturnValueLocationIsReturned: false ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 - -FloatingPointScalarTypes: - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + CTypes: + - Long + - Kind: Integer + Size: 8 + - Kind: Integer + Size: 16 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 + - Kind: FloatingPoint + Size: 16 # IEEE Binary128 diff --git a/share/revng/abi/Microsoft_x86_64.yml b/share/revng/abi/Microsoft_x86_64.yml index ba867cda9..67671bffb 100644 --- a/share/revng/abi/Microsoft_x86_64.yml +++ b/share/revng/abi/Microsoft_x86_64.yml @@ -54,12 +54,21 @@ ReturnValueLocationRegister: rcx_x86_64 ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + CTypes: + - Long + - Kind: Integer + Size: 8 + - Kind: Integer + Size: 16 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/Microsoft_x86_64_vectorcall.yml b/share/revng/abi/Microsoft_x86_64_vectorcall.yml index 47c0ce407..5d92cd42b 100644 --- a/share/revng/abi/Microsoft_x86_64_vectorcall.yml +++ b/share/revng/abi/Microsoft_x86_64_vectorcall.yml @@ -56,12 +56,21 @@ ReturnValueLocationRegister: rcx_x86_64 ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + CTypes: + - Long + - Kind: Integer + Size: 8 + - Kind: Integer + Size: 16 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/Microsoft_x86_cdecl.yml b/share/revng/abi/Microsoft_x86_cdecl.yml index f68ac1db9..24b0311e7 100644 --- a/share/revng/abi/Microsoft_x86_cdecl.yml +++ b/share/revng/abi/Microsoft_x86_cdecl.yml @@ -36,13 +36,18 @@ ReturnValueLocationOnStack: true ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 - AlignedAt: 4 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + AlignedAt: 4 # TODO: The correct value is 8, but stack arguments align to 4. + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/Microsoft_x86_cdecl_gcc.yml b/share/revng/abi/Microsoft_x86_cdecl_gcc.yml index bcc3b884d..e619b9131 100644 --- a/share/revng/abi/Microsoft_x86_cdecl_gcc.yml +++ b/share/revng/abi/Microsoft_x86_cdecl_gcc.yml @@ -36,13 +36,22 @@ ReturnValueLocationOnStack: true ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 + - Kind: FloatingPoint + Size: 12 # x87 Extended AlignedAt: 4 + CTypes: + - LongDouble diff --git a/share/revng/abi/Microsoft_x86_fastcall.yml b/share/revng/abi/Microsoft_x86_fastcall.yml index 1ff1609ec..0cc7a5391 100644 --- a/share/revng/abi/Microsoft_x86_fastcall.yml +++ b/share/revng/abi/Microsoft_x86_fastcall.yml @@ -39,13 +39,18 @@ ReturnValueLocationOnStack: true ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 - AlignedAt: 4 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + AlignedAt: 4 # TODO: The correct value is 8, but stack arguments align to 4. + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/Microsoft_x86_fastcall_gcc.yml b/share/revng/abi/Microsoft_x86_fastcall_gcc.yml index 63db72131..65b122930 100644 --- a/share/revng/abi/Microsoft_x86_fastcall_gcc.yml +++ b/share/revng/abi/Microsoft_x86_fastcall_gcc.yml @@ -39,13 +39,22 @@ ReturnValueLocationRegister: ecx_x86 ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 + - Kind: FloatingPoint + Size: 12 # x87 Extended AlignedAt: 4 + CTypes: + - LongDouble diff --git a/share/revng/abi/Microsoft_x86_stdcall.yml b/share/revng/abi/Microsoft_x86_stdcall.yml index 31a5bf2a1..b4e3beab2 100644 --- a/share/revng/abi/Microsoft_x86_stdcall.yml +++ b/share/revng/abi/Microsoft_x86_stdcall.yml @@ -36,13 +36,18 @@ ReturnValueLocationOnStack: true ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 - AlignedAt: 4 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + AlignedAt: 4 # TODO: The correct value is 8, but stack arguments align to 4. + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/Microsoft_x86_stdcall_gcc.yml b/share/revng/abi/Microsoft_x86_stdcall_gcc.yml index e43ae61fd..02c7e1e8e 100644 --- a/share/revng/abi/Microsoft_x86_stdcall_gcc.yml +++ b/share/revng/abi/Microsoft_x86_stdcall_gcc.yml @@ -36,13 +36,22 @@ ReturnValueLocationOnStack: true ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 + - Kind: FloatingPoint + Size: 12 # x87 Extended AlignedAt: 4 + CTypes: + - LongDouble diff --git a/share/revng/abi/Microsoft_x86_thiscall.yml b/share/revng/abi/Microsoft_x86_thiscall.yml index 3b9ee23e8..17df9bdfc 100644 --- a/share/revng/abi/Microsoft_x86_thiscall.yml +++ b/share/revng/abi/Microsoft_x86_thiscall.yml @@ -38,13 +38,18 @@ ReturnValueLocationOnStack: true ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 - AlignedAt: 4 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + AlignedAt: 4 # TODO: The correct value is 8, but stack arguments align to 4. + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/Microsoft_x86_vectorcall.yml b/share/revng/abi/Microsoft_x86_vectorcall.yml index 074f77f8e..4127da071 100644 --- a/share/revng/abi/Microsoft_x86_vectorcall.yml +++ b/share/revng/abi/Microsoft_x86_vectorcall.yml @@ -50,13 +50,18 @@ ReturnValueLocationOnStack: true ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 - AlignedAt: 4 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + AlignedAt: 4 # TODO: The correct value is 8, but stack arguments align to 4. + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/SystemV_MIPSEL_o32.yml b/share/revng/abi/SystemV_MIPSEL_o32.yml index cd13883a2..e5313c8de 100644 --- a/share/revng/abi/SystemV_MIPSEL_o32.yml +++ b/share/revng/abi/SystemV_MIPSEL_o32.yml @@ -70,11 +70,15 @@ ReturnValueLocationRegister: v0_mips ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/SystemV_MIPS_o32.yml b/share/revng/abi/SystemV_MIPS_o32.yml index 882bb2744..273d86060 100644 --- a/share/revng/abi/SystemV_MIPS_o32.yml +++ b/share/revng/abi/SystemV_MIPS_o32.yml @@ -70,11 +70,15 @@ ReturnValueLocationRegister: v0_mips ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 diff --git a/share/revng/abi/SystemV_x86.yml b/share/revng/abi/SystemV_x86.yml index fd1618b71..b5b1c4fcb 100644 --- a/share/revng/abi/SystemV_x86.yml +++ b/share/revng/abi/SystemV_x86.yml @@ -38,16 +38,26 @@ ReturnValueLocationOnStack: true ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 AlignedAt: 4 - - Size: 12 + - Kind: FloatingPoint + Size: 12 # x87 Extended AlignedAt: 4 - - Size: 16 + CTypes: + - LongDouble + - Kind: FloatingPoint + Size: 16 # IEEE Binary128 diff --git a/share/revng/abi/SystemV_x86_64.yml b/share/revng/abi/SystemV_x86_64.yml index c3ba95547..1012b645d 100644 --- a/share/revng/abi/SystemV_x86_64.yml +++ b/share/revng/abi/SystemV_x86_64.yml @@ -58,14 +58,23 @@ ReturnValueLocationRegister: rdi_x86_64 ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 - -FloatingPointScalarTypes: - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: Integer + Size: 16 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 + - Kind: FloatingPoint + Size: 16 # x87 Extended + CTypes: + - LongDouble diff --git a/share/revng/abi/SystemV_x86_regparm_1.yml b/share/revng/abi/SystemV_x86_regparm_1.yml index c9f36ad9a..f8517feeb 100644 --- a/share/revng/abi/SystemV_x86_regparm_1.yml +++ b/share/revng/abi/SystemV_x86_regparm_1.yml @@ -42,16 +42,26 @@ ReturnValueLocationRegister: eax_x86 ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 AlignedAt: 4 - - Size: 12 + - Kind: FloatingPoint + Size: 12 # x87 Extended AlignedAt: 4 - - Size: 16 + CTypes: + - LongDouble + - Kind: FloatingPoint + Size: 16 # IEEE Binary128 diff --git a/share/revng/abi/SystemV_x86_regparm_2.yml b/share/revng/abi/SystemV_x86_regparm_2.yml index 8b395fc61..3fc4e0e6a 100644 --- a/share/revng/abi/SystemV_x86_regparm_2.yml +++ b/share/revng/abi/SystemV_x86_regparm_2.yml @@ -43,16 +43,26 @@ ReturnValueLocationRegister: eax_x86 ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 AlignedAt: 4 - - Size: 12 + - Kind: FloatingPoint + Size: 12 # x87 Extended AlignedAt: 4 - - Size: 16 + CTypes: + - LongDouble + - Kind: FloatingPoint + Size: 16 # IEEE Binary128 diff --git a/share/revng/abi/SystemV_x86_regparm_3.yml b/share/revng/abi/SystemV_x86_regparm_3.yml index dc1c87185..b6a9cf0a8 100644 --- a/share/revng/abi/SystemV_x86_regparm_3.yml +++ b/share/revng/abi/SystemV_x86_regparm_3.yml @@ -44,16 +44,26 @@ ReturnValueLocationRegister: eax_x86 ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 AlignedAt: 4 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 + - Kind: FloatingPoint + Size: 2 # IEEE Binary16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary64 AlignedAt: 4 - - Size: 12 + - Kind: FloatingPoint + Size: 12 # x87 Extended AlignedAt: 4 - - Size: 16 + CTypes: + - LongDouble + - Kind: FloatingPoint + Size: 16 # IEEE Binary128 diff --git a/share/revng/abi/SystemZ_s390x.yml b/share/revng/abi/SystemZ_s390x.yml index 84bd4e768..cd228466a 100644 --- a/share/revng/abi/SystemZ_s390x.yml +++ b/share/revng/abi/SystemZ_s390x.yml @@ -72,15 +72,23 @@ ReturnValueLocationRegister: r2_systemz ReturnValueLocationIsReturned: true ScalarTypes: - - Size: 1 - - Size: 2 - - Size: 4 - - Size: 8 - - Size: 16 + - Kind: Integer + Size: 1 + - Kind: Integer + Size: 2 + - Kind: Integer + Size: 4 + - Kind: Integer + Size: 8 + - Kind: Integer + Size: 16 AlignedAt: 8 - -FloatingPointScalarTypes: - - Size: 4 - - Size: 8 - - Size: 16 + - Kind: FloatingPoint + Size: 4 # IEEE Binary32 + - Kind: FloatingPoint + Size: 8 # IEEE Binary16 + - Kind: FloatingPoint + Size: 16 # IEEE Binary128 AlignedAt: 8 + CTypes: + - LongDouble diff --git a/tests/abi/tools/check-compatibility-with-abi/Verify.cpp b/tests/abi/tools/check-compatibility-with-abi/Verify.cpp index 4c5f97b43..df064ed8c 100644 --- a/tests/abi/tools/check-compatibility-with-abi/Verify.cpp +++ b/tests/abi/tools/check-compatibility-with-abi/Verify.cpp @@ -269,8 +269,7 @@ VH::LeftToVerify VH::verifyAnArgument(const runtime_test::State &State, } } - revng_assert(!ABI.ScalarTypes().empty()); - auto &BiggestScalarType = *std::prev(ABI.ScalarTypes().end()); + auto &BiggestScalarType = ABI.getWidestIntegerType(); if (BiggestScalarType.alignedAt() != ABI.getPointerSize()) { // If the ABI supports unusual alignment, try to account for it, // by dropping an conflicting part of the stack data. diff --git a/tests/unit/Alignment.cpp b/tests/unit/Alignment.cpp index 3ca2559f2..376e58863 100644 --- a/tests/unit/Alignment.cpp +++ b/tests/unit/Alignment.cpp @@ -44,14 +44,14 @@ void testAlignment(model::UpcastableType &&Type, const Types &...TestCases) { static bool ABIhasIntsOfSizes(const abi::Definition &ABI, std::initializer_list Values) { return std::ranges::all_of(Values, [&ABI](uint64_t Value) { - return ABI.ScalarTypes().contains(Value); + return ABI.findIntegerType(Value) != nullptr; }); } static bool ABIhasFloatsOfSizes(const abi::Definition &ABI, std::initializer_list Values) { return std::ranges::all_of(Values, [&ABI](uint64_t Value) { - return ABI.FloatingPointScalarTypes().contains(Value); + return ABI.findFloatingPointType(Value) != nullptr; }); }