/** * @file rex/codegen/codegen_writer.h * @brief Consolidated codegen output writer * * @copyright Copyright (c) 2026 Tom Clay * All rights reserved. * * @license BSD 3-Clause License * See LICENSE file in the project root for full license text. */ #pragma once #include #include #include #include #include namespace rex { class Runtime; } namespace rex::codegen { class CodegenWriter { public: CodegenWriter(CodegenContext& ctx, Runtime* runtime = nullptr); /// Run the full output pipeline: validate, clean old files, generate, flush. bool write(bool force); private: CodegenContext& ctx_; Runtime* runtime_; std::string out; size_t cppFileIndex = 0; std::vector> pendingWrites; template void print(fmt::format_string fmt, Args&&... args) { fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...)); } template void println(fmt::format_string fmt, Args&&... args) { fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...)); out += '\n'; } void SaveCurrentOutData(std::string_view name = {}); void FlushPendingWrites(); // Convenience accessors FunctionGraph& graph(); const FunctionGraph& graph() const; const BinaryView& binary() const; RecompilerConfig& config(); const RecompilerConfig& config() const; AnalysisState& analysisState(); const AnalysisState& analysisState() const; }; } // namespace rex::codegen