Files
Alessandro Di Federico 247879f7fc model::Type::ID: switch to progressive IDs
This commit switches `model::Type::ID` from being a GUID to be a
progressive number, in order to make things easier for humans.

On top of this, this commit introduces the following changes:

* TypeCopier: import all the necessary PrimitiveTypes and improve
  handling of CustomName.
* Move Kind as the last field of the key of each TupleTree type used in
  an `UpcastablePointer`.
* Update the ground truth of tests to ignore the `CustomName` in favor
  of focusing on `OriginalName`.
* Increase adoption of `model::Binary::makeType`, equivalent to
  `Binary.recordNewType(makeType<model::*Type>())`.
2023-08-23 16:14:04 +02:00

67 lines
2.2 KiB
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Instructions.h"
#include "revng/Model/Binary.h"
#include "revng/Support/Assert.h"
#include "revng/Support/IRHelpers.h"
#include "revng/Support/MetaAddress.h"
inline MetaAddress getMetaAddressOfIsolatedFunction(const llvm::Function &F) {
revng_assert(FunctionTags::Isolated.isTagOf(&F));
return getMetaAddressMetadata(&F, FunctionEntryMDNName);
}
inline model::Function *llvmToModelFunction(model::Binary &Binary,
const llvm::Function &F) {
auto MaybeMetaAddress = getMetaAddressMetadata(&F, FunctionEntryMDNName);
if (MaybeMetaAddress == MetaAddress::invalid())
return nullptr;
if (auto It = Binary.Functions().find(MaybeMetaAddress);
It != Binary.Functions().end())
return &*It;
return nullptr;
}
inline const model::Function *llvmToModelFunction(const model::Binary &Binary,
const llvm::Function &F) {
auto MaybeMetaAddress = getMetaAddressMetadata(&F, FunctionEntryMDNName);
if (MaybeMetaAddress == MetaAddress::invalid())
return nullptr;
if (auto It = Binary.Functions().find(MaybeMetaAddress);
It != Binary.Functions().end())
return &*It;
return nullptr;
}
inline llvm::IntegerType *
getLLVMIntegerTypeFor(llvm::LLVMContext &Context,
const model::QualifiedType &QT) {
revng_assert(QT.size());
return llvm::IntegerType::getIntNTy(Context, *QT.size() * 8);
}
inline llvm::IntegerType *getLLVMTypeForScalar(llvm::LLVMContext &Context,
const model::QualifiedType &QT) {
revng_assert(QT.isScalar());
return getLLVMIntegerTypeFor(Context, QT);
}
/// Create an empty model::StructType of size Size in Binary
inline model::TypePath createEmptyStruct(model::Binary &Binary, uint64_t Size) {
using namespace model;
revng_assert(Size > 0 and Size < std::numeric_limits<int64_t>::max());
TypePath Path = Binary.makeType<model::StructType>().second;
model::StructType *NewStruct = llvm::cast<model::StructType>(Path.get());
NewStruct->Size() = Size;
return Path;
}