// // 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 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 F2; } // end namespace revng::pipes namespace revng::pypeline::piperuns { using TD = UpcastablePointer; 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](const T &Upcasted) { B.printDefinition(Upcasted); }); } } // namespace revng::pypeline::piperuns static pipeline::RegisterPipe X2;