#pragma once #include "CodegenDecl.hpp" #include #include #include #include // A generic "thing" (could be anything, comments, string-concated functionsm, etc.) to spit into the output file struct CodegenOutputThing { std::string text; }; class CodegenOutput { private: std::vector mOutThings; std::vector mOutStructs; std::vector mOutEnums; std::vector mOutFunctions; public: std::string optionOutPrefix; // Whether to add prefixes mOutPrefix to all global names or not bool optionAutoAddPrefix : 1 = false; public: void AddOutputThing(CodegenOutputThing thing) { mOutThings.push_back(std::move(thing)); } void MergeContents(CodegenOutput other) { std::move(other.mOutThings.begin(), other.mOutThings.end(), std::back_inserter(this->mOutThings)); } void Write(FILE* file) { #define WRITE_LITERAL(str) fwrite(str, sizeof(char), sizeof(str) - 1, file) for (auto& thing : mOutThings) { WRITE_LITERAL("// Output thing\n"); fwrite(thing.text.c_str(), sizeof(char), thing.text.size(), file); WRITE_LITERAL("\n"); } #undef WRITE_LITERAL } };