mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
Add AddPrimitiveTypesPass to Decompiler
This pass is in charge of creating all the primitive types for any of the typical sizes used for numbers.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user