From 7e51180ed80ce1c5718b65c6625dc12fe64c8bfa Mon Sep 17 00:00:00 2001 From: tareksander <57038324+tareksander@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:32:00 +0100 Subject: Reflection compiler option (#5507) * Moved the pretty writer code from slang-reflection-test into core * Moved reflection test code into the slang codebase and added the compiler option -reflection-json to store the reflection data in a separate file. * Documented -reflection-json command line option * moved PrettyWriter from core to compiler-core * Fixed variable shadowing warning * Use File::writeAllText instead of OSFilesystem and write to stdout if - is used as the path * format code * Fixed linker error * Fix COM Ptr life time issues. * Move enum to the end. * Fix formatting. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He --- source/slang/slang.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index eb938f49c..25419fb33 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -31,6 +31,7 @@ #include "slang-parameter-binding.h" #include "slang-parser.h" #include "slang-preprocessor.h" +#include "slang-reflection-json.h" #include "slang-repro.h" #include "slang-serialize-ast.h" #include "slang-serialize-container.h" @@ -6857,6 +6858,22 @@ SlangResult EndToEndCompileRequest::compile() } } + auto reflectionPath = getOptionSet().getStringOption(CompilerOptionName::EmitReflectionJSON); + if (reflectionPath.getLength() != 0) + { + auto bufferWriter = PrettyWriter(); + emitReflectionJSON(this, this->getReflection(), bufferWriter); + if (reflectionPath == "-") + { + auto builder = bufferWriter.getBuilder(); + StdWriters::getOut().write(builder.getBuffer(), builder.getLength()); + } + else if (SLANG_FAILED(File::writeAllText(reflectionPath, bufferWriter.getBuilder()))) + { + getSink()->diagnose(SourceLoc(), Diagnostics::unableToWriteFile, reflectionPath); + } + } + return res; } -- cgit v1.2.3