summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-source-embed-util.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-05-22 17:22:22 -0400
committerGitHub <noreply@github.com>2023-05-22 17:22:22 -0400
commit972a931452c3f06a23a4f67ccfb655851df53fa4 (patch)
tree309a75c5239af163e47bc0e123d023683c1ec74a /source/compiler-core/slang-source-embed-util.h
parent33e15236c6fd8623bc516a194ca65e8810f1f855 (diff)
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.
Diffstat (limited to 'source/compiler-core/slang-source-embed-util.h')
-rw-r--r--source/compiler-core/slang-source-embed-util.h59
1 files changed, 59 insertions, 0 deletions
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<NamesDescriptionValue> getStyleInfos();
+
+ /// Given an artifact and
+ static SlangResult createEmbedded(IArtifact* artifact, const Options& options, ComPtr<IArtifact>& 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