mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
ea3cbe4c1b
Type inlining was a feature that allowed type definitions of structs/unions/enums to be printed in C directly inside the definition of another parent struct/union, if the inner type was only used once in the parent type. This kind of reasoning is inherently global: a type definition of the subtype can be inlined in the parent type one only if *globally* the subtype it isn't referred anywhere else. This caused issues with type inlining inside definitions of stack types in the body of functions. Indeed, for a given function, due to type inlining, it was necessary to do global reasoning about what other types could be inlined in the definition of the function's stack frame type. This, in turn, had heavy consequences on invalidation, because any change to any type (even if it wasn't referred in a given function's body) was causing invalidation of all functions' bodies. For this reason it was decided to drop the type inlining feature.
75 lines
2.6 KiB
C++
75 lines
2.6 KiB
C++
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "revng/HeadersGeneration/Options.h"
|
|
#include "revng/HeadersGeneration/PTMLHeaderBuilder.h"
|
|
#include "revng/Pipeline/AllRegistries.h"
|
|
#include "revng/Pipeline/RegisterContainerFactory.h"
|
|
#include "revng/Pipes/FileContainer.h"
|
|
#include "revng/Pipes/Kinds.h"
|
|
#include "revng/Pipes/ModelGlobal.h"
|
|
|
|
namespace revng::pipes {
|
|
|
|
inline constexpr char ModelHeaderFileContainerMIMEType[] = "text/x.c+ptml";
|
|
inline constexpr char ModelHeaderFileContainerSuffix[] = ".h";
|
|
inline constexpr char ModelHeaderFileContainerName[] = "model-header";
|
|
using ModelHeaderFileContainer = FileContainer<&kinds::ModelHeader,
|
|
ModelHeaderFileContainerName,
|
|
ModelHeaderFileContainerMIMEType,
|
|
ModelHeaderFileContainerSuffix>;
|
|
|
|
class ModelToHeader {
|
|
public:
|
|
static constexpr auto Name = "model-to-header";
|
|
|
|
std::array<pipeline::ContractGroup, 1> getContract() const {
|
|
using namespace pipeline;
|
|
using namespace revng::kinds;
|
|
|
|
Contract C1(Binary, 0, ModelHeader, 1, InputPreservation::Preserve);
|
|
return { ContractGroup({ C1 }) };
|
|
}
|
|
|
|
// TODO: BinaryFile here is a placeholder. In principle this pipe has no real
|
|
// input container. It just uses the model in EC to generated HeaderFile.
|
|
// At the moment revng-pipeline does not support pipes with no inputs, so we
|
|
// had to resort to this trick. Whenever pipes with no inputs are supported
|
|
// BinaryFile can be dropped.
|
|
void run(pipeline::ExecutionContext &EC,
|
|
const BinaryFileContainer &BinaryFile,
|
|
ModelHeaderFileContainer &HeaderFile) {
|
|
if (EC.getRequestedTargetsFor(HeaderFile).empty())
|
|
return;
|
|
|
|
std::error_code ErrorCode;
|
|
llvm::raw_fd_ostream Header(HeaderFile.getOrCreatePath(), ErrorCode);
|
|
if (ErrorCode)
|
|
revng_abort(ErrorCode.message().c_str());
|
|
|
|
namespace options = revng::options;
|
|
ptml::CTypeBuilder
|
|
B(Header,
|
|
*getModelFromContext(EC),
|
|
/* EnableTaglessMode = */ false,
|
|
{ .EnableStackFrameInlining = options::EnableStackFrameInlining,
|
|
.EnablePrintingOfTheMaximumEnumValue = true });
|
|
ptml::HeaderBuilder(B).printModelHeader();
|
|
|
|
Header.flush();
|
|
ErrorCode = Header.error();
|
|
if (ErrorCode)
|
|
revng_abort(ErrorCode.message().c_str());
|
|
|
|
EC.commitUniqueTarget(HeaderFile);
|
|
}
|
|
};
|
|
|
|
static pipeline::RegisterDefaultConstructibleContainer<ModelHeaderFileContainer>
|
|
Reg;
|
|
|
|
} // namespace revng::pipes
|
|
|
|
static pipeline::RegisterPipe<revng::pipes::ModelToHeader> Y;
|