From 972a931452c3f06a23a4f67ccfb655851df53fa4 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 22 May 2023 17:22:22 -0400 Subject: Source embedding for output (#2889) * #include an absolute path didn't work - because paths were taken to always be relative. * Fix typo. * Add options for source embedding. * Small improvements. * Working with tests. * Add check for supported language types for embedding. * Try and remove assume warning. * Fix warning on MacOSX. * Some extra checking around Style::Text. * Some small improvements to docs/handling for headers extensions. * Fix md issue. * Small fixes around zeroing partial last element. * Another small fix.... * Small improvement in hex conversion. * Add an assert for unsignedness. --- source/compiler-core/slang-source-embed-util.h | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 source/compiler-core/slang-source-embed-util.h (limited to 'source/compiler-core/slang-source-embed-util.h') diff --git a/source/compiler-core/slang-source-embed-util.h b/source/compiler-core/slang-source-embed-util.h new file mode 100644 index 000000000..70389cfe1 --- /dev/null +++ b/source/compiler-core/slang-source-embed-util.h @@ -0,0 +1,59 @@ +#ifndef SLANG_SOURCE_EMBED_UTIL_H +#define SLANG_SOURCE_EMBED_UTIL_H + +#include "../core/slang-basic.h" + +#include "slang-artifact.h" +#include "slang-diagnostic-sink.h" + +#include "../../slang-com-ptr.h" + +#include "../core/slang-name-value.h" + +namespace Slang +{ + + +struct SourceEmbedUtil +{ + enum class Style : uint32_t + { + None, ///< No embedding + Default, ///< Default embedding for the type + Text, ///< Embed as text. May change line endings. If output isn't text will use 'default'. Size will *not* contain terminating 0 + BinaryText, ///< Embed as text assuming contents is binary. + U8, ///< Embed as unsigned bytes + U16, ///< Embed as uint16_t + U32, ///< Embed as uint32_t + U64, ///< Embed as uint64_t + CountOf, + }; + + struct Options + { + Style style = Style::Default; ///< Style of embedding + Count lineLength = 120; ///< The line length, lines can be larger for some styles, but will aim to keep within range + SlangSourceLanguage language = SLANG_SOURCE_LANGUAGE_C; ///< The language to output for + String variableName; ///< The name to give the variable + String indent = " "; ///< Indenting + }; + + /// Get the style infos + static ConstArrayView getStyleInfos(); + + /// Given an artifact and + static SlangResult createEmbedded(IArtifact* artifact, const Options& options, ComPtr& outArtifact); + + /// Returns the default style for the desc + static Style getDefaultStyle(const ArtifactDesc& desc); + + /// Returns true if supports the specified language for embedding + static bool isSupported(SlangSourceLanguage lang); + + /// Given the path return the output path. If no path is available return the empty string + static String getPath(const String& path, const Options& options); +}; + +} + +#endif -- cgit v1.2.3