Files
revng-revng/lib/HeadersGeneration/ModelTypeDefinitionPipe.cpp
Pietro Fezzardi 6a3ab92a9d Mark to-be-dropped pipeline names as legacy
Several components in both pipeline YAMLs are slated for removal.
Prepend a legacy prefix to their names, and to the matching c++ code, so
they are clearly distinguished from the new Clift-based pipeline until
they are dropped.
2026-06-15 17:28:22 +02:00

84 lines
3.1 KiB
C++

//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "revng/Backend/DecompileFunction.h"
#include "revng/HeadersGeneration/ModelTypeDefinitionPipe.h"
#include "revng/HeadersGeneration/PTMLHeaderBuilder.h"
#include "revng/Model/Binary.h"
#include "revng/Pipeline/AllRegistries.h"
#include "revng/Pipes/Kinds.h"
#include "revng/Pipes/ModelGlobal.h"
#include "revng/Pipes/StringMap.h"
namespace revng::pipes {
inline constexpr char ModelTypeDefinitionMime[] = "text/x.c+tar+gz";
inline constexpr char ModelTypeDefinitionName[] = "legacy-model-type-"
"definitions";
inline constexpr char ModelTypeDefinitionExtension[] = ".h";
using TypeDefinitionStringMap = TypeStringMap<&kinds::LegacyModelTypeDefinition,
ModelTypeDefinitionName,
ModelTypeDefinitionMime,
ModelTypeDefinitionExtension>;
class GenerateModelTypeDefinition {
public:
static constexpr auto Name = "legacy-generate-model-type-definition";
std::array<pipeline::ContractGroup, 1> getContract() const {
using namespace pipeline;
using namespace revng::kinds;
return { ContractGroup({ Contract(kinds::Binary,
0,
LegacyModelTypeDefinition,
1,
InputPreservation::Preserve) }) };
}
void run(pipeline::ExecutionContext &EC,
const BinaryFileContainer &SourceBinary,
TypeDefinitionStringMap &ModelTypesContainer) {
const model::Binary &Model = *getModelFromContext(EC);
for (const model::TypeDefinition &Type :
getTypeDefinitionsAndCommit(EC, ModelTypesContainer.name())) {
std::string &Result = ModelTypesContainer[Type.key()];
llvm::raw_string_ostream Out(Result);
ptml::ModelCBuilder B(Out,
Model,
true,
{ .EnablePrintingOfTheMaximumEnumValue = true,
.EnableExplicitPadding = false });
B.printDefinition(Type);
}
}
};
using namespace pipeline;
static RegisterDefaultConstructibleContainer<TypeDefinitionStringMap> F2;
} // end namespace revng::pipes
namespace revng::pypeline::piperuns {
using TD = UpcastablePointer<model::TypeDefinition>;
void GenerateModelTypeDefinition::runOnTypeDefinition(const TD
&TypeDefinition) {
auto OS = Output.getOStream(ObjectID(TypeDefinition->key()));
ptml::ModelCBuilder B(*OS,
*Model.get().get(),
true,
{ .EnablePrintingOfTheMaximumEnumValue = true,
.EnableExplicitPadding = false });
upcast(TypeDefinition,
[&B]<typename T>(const T &Upcasted) { B.printDefinition(Upcasted); });
}
} // namespace revng::pypeline::piperuns
static pipeline::RegisterPipe<revng::pipes::GenerateModelTypeDefinition> X2;