diff options
author | rtk0c <[email protected]> | 2022-07-17 23:09:00 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-07-17 23:09:00 -0700 |
commit | 8c2b1bd5bd85667a2ea24ec3aa85cbdd97f9ea1c (patch) | |
tree | 80b12277b667747aa4f18ebcc3931c2ea618cb1e /source/20-codegen-compiler/CodegenOutput.cpp | |
parent | c6e57dc94e532442ffa0bd57a16206217adbca92 (diff) |
Changeset: 85 Work on codegen (a big blob of changes about various things, giving up on writing a clear commit message)
- stuff along the lines of cleaning up store process
- remove completed TODOs
- move code generation out of parser loop
- ^^^ also introduce some weird bugs of DeclXxx::name field disappearing -- maybe fixed, maybe didn't, can't reliably reproduce
- add infra to mangle (not included in codegen yet, also not tested)
- convert SourceFile storage map to node map, ensuring pointer stability (was broken before)
- buildsystem asan and UBsan applying to all targest
Diffstat (limited to 'source/20-codegen-compiler/CodegenOutput.cpp')
-rw-r--r-- | source/20-codegen-compiler/CodegenOutput.cpp | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/source/20-codegen-compiler/CodegenOutput.cpp b/source/20-codegen-compiler/CodegenOutput.cpp index ccd163c..d85feac 100644 --- a/source/20-codegen-compiler/CodegenOutput.cpp +++ b/source/20-codegen-compiler/CodegenOutput.cpp @@ -8,15 +8,22 @@ void CodegenOutput::AddRequestInclude(std::string_view include) { } } -void CodegenOutput::AddOutputThing(CodegenOutputThing thing) { - mOutThings.push_back(std::move(thing)); +void CodegenOutput::AddOutputThing(CodegenOutputThing thing, int placementLocation) { + if (placementLocation < 0 || placementLocation >= mOutThings.size()) { + mOutThings.push_back(std::move(thing)); + } else { + int maxIndex = (int)mOutThings.size() - 1; + if (placementLocation > maxIndex) { + placementLocation = maxIndex; + } + + auto placementIter = mOutThings.begin() + placementLocation; + mOutThings.insert(placementIter, std::move(thing)); + } } void CodegenOutput::MergeContents(CodegenOutput other) { std::move(other.mOutThings.begin(), other.mOutThings.end(), std::back_inserter(this->mOutThings)); - std::move(other.mOutStructs.begin(), other.mOutStructs.end(), std::back_inserter(this->mOutStructs)); - std::move(other.mOutEnums.begin(), other.mOutEnums.end(), std::back_inserter(this->mOutEnums)); - std::move(other.mOutFunctions.begin(), other.mOutFunctions.end(), std::back_inserter(this->mOutFunctions)); } void CodegenOutput::Write(FILE* file) const { @@ -29,18 +36,4 @@ void CodegenOutput::Write(FILE* file) const { fwrite(thing.text.c_str(), sizeof(char), thing.text.size(), file); WRITE_LIT(file, "\n"); } - - for (auto& declStruct : mOutStructs) { - WRITE_FMT_LN(file, "struct %s {", declStruct.name.c_str()); - // TODO - WRITE_LIT_LN(file, "};"); - } - - for (auto& declEnum : mOutEnums) { - // TODO - } - - for (auto& declFunc : mOutFunctions) { - // TODO - } } |