Files
revng-revng/lib/Decompiler/AddPrimitiveTypesPass.cpp
T
Alvise de Faveri bda519b3e2 Add AddPrimitiveTypesPass to Decompiler
This pass is in charge of creating all the primitive types for any
of the typical sizes used for numbers.
2021-11-18 11:13:36 +01:00

42 lines
1.3 KiB
C++

//
// Copyright (c) rev.ng Srls. See LICENSE.md for details.
//
#include "revng/Model/LoadModelPass.h"
#include "revng/Model/Type.h"
#include "revng-c/Decompiler/AddPrimitiveTypesPass.h"
char AddPrimitiveTypesPass::ID = 0;
using Register = llvm::RegisterPass<AddPrimitiveTypesPass>;
static ::Register
X("add-primitives", "Pass to add primitive types to Model", false, false);
void AddPrimitiveTypesPass::getAnalysisUsage(llvm::AnalysisUsage &AU) const {
AU.addRequired<LoadModelWrapperPass>();
AU.setPreservesAll();
}
using namespace model::PrimitiveTypeKind;
bool AddPrimitiveTypesPass::runOnModule(llvm::Module &M) {
auto &ModelWrapper = getAnalysis<LoadModelWrapperPass>().get();
auto &WritableModel = ModelWrapper.getWriteableModel();
// For each of these types, we want to have in the model a corresponding
// PrimitiveType for each possible dimension
static constexpr const Values PrimitiveTypes[] = {
Generic, PointerOrNumber, Number, Unsigned, Signed
};
// TODO: Add 128-bit numbers if needed
static constexpr const uint8_t Sizes[] = { 1, 2, 4, 8 };
// getPrimitiveType() creates the type if it does not exist
for (auto &Type : PrimitiveTypes)
for (auto &Size : Sizes)
WritableModel->getPrimitiveType(Type, Size);
return true;
}