diff --git a/setup.sh b/setup.sh index eafa964..c83b7bf 100755 --- a/setup.sh +++ b/setup.sh @@ -1,6 +1,6 @@ #!/bin/sh -sudo -H apt install -y python3 python3-pip python3-setuptools g++-9 +sudo -H apt install -y python3 python3-pip python3-setuptools g++-9 patchelf sudo -H pip3 install conan conan profile new default --detect diff --git a/src/assembly/parser.cpp b/src/assembly/parser.cpp index ae2173f..d87c59b 100644 --- a/src/assembly/parser.cpp +++ b/src/assembly/parser.cpp @@ -229,6 +229,11 @@ void AsmParser::AssemblyTextParser::extractUsedLabelsFromDataLine(const std::str for (auto &label_ref : this->state.currentLine->labels) { this->data_used_labels[label_ref.name].insert(this->state.previousLabel); + + if (this->state.currentSourceRef.inside_proc) + { + this->data_used_labels[label_ref.name].insert(this->state.previousParentLabel); + } } } @@ -352,7 +357,7 @@ void AsmParser::AssemblyTextParser::eol() this->state.currentLine->text = std::move(filteredLine); } - if (AssemblyTextParserUtils::startBlock(this->state.currentLine->text) && this->state.currentSourceRef.line == 0) + if (AssemblyTextParserUtils::startProcBlock(this->state.currentLine->text) && this->state.currentSourceRef.line == 0) { this->markPreviousInternalLabelAsInsideProc(); if (this->filter.directives) @@ -586,7 +591,7 @@ bool AsmParser::AssemblyTextParser::isUsedThroughAlias(const std::string_view la bool AsmParser::AssemblyTextParser::isUsed(const std::string_view label, const int depth) const { - if (usercode_labels.contains(label)) + if (this->usercode_labels.contains(label)) return true; const auto usedfind = this->used_labels.find(label); @@ -742,7 +747,7 @@ void AsmParser::AssemblyTextParser::removeUnused() if (remove || removeOnlyThis || (!isUsed && !isUsedThroughAlias && !isDataUsedThroughAlias && this->filter.compatmode && - this->filter.directives && line->is_data)) + this->filter.directives && line->is_data && !line->source.inside_proc)) { // filter this out this->state.filteredlines.push_back(std::move(line)); @@ -835,7 +840,8 @@ void AsmParser::AssemblyTextParser::outputDebugJson(std::ostream &out) const { const std::vector labels = this->redetermineLabels(); - DebugJsonWriter writer(out, this->lines, labels, this->filter, this->used_labels, this->weakly_used_labels, this->aliased_labels); + DebugJsonWriter writer(out, this->lines, labels, this->filter, this->used_labels, this->weakly_used_labels, + this->aliased_labels, this->data_used_labels); writer.write(); } diff --git a/src/test/test_test.cpp b/src/test/test_test.cpp index 0d72d56..0a63355 100644 --- a/src/test/test_test.cpp +++ b/src/test/test_test.cpp @@ -16,8 +16,11 @@ TEST_CASE("Test text assembly utilities", "[asm]") REQUIRE(file_def.value().file_index == 2); REQUIRE(file_def.value().file_name == "/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/bits/char_traits.h"); - const auto endproc = AsmParser::AssemblyTextParserUtils::endBlock("\t.cfi_endproc"); - CHECK(endproc); + const auto endproc1 = AsmParser::AssemblyTextParserUtils::endBlock("\t.cfi_endproc"); + CHECK(endproc1); + + const auto endproc2 = AsmParser::AssemblyTextParserUtils::endProcBlock("\t.cfi_endproc"); + CHECK(endproc2); const auto indentedLabel = AsmParser::AssemblyTextParserUtils::getLineWithoutComment("\tlabel:"); REQUIRE(indentedLabel == "\tlabel:"); diff --git a/src/utils/jsonwriter.cpp b/src/utils/jsonwriter.cpp index 8382908..9cf1d00 100644 --- a/src/utils/jsonwriter.cpp +++ b/src/utils/jsonwriter.cpp @@ -378,9 +378,10 @@ AsmParser::DebugJsonWriter::DebugJsonWriter(std::ostream &out, const Filter filter, const std::unordered_map> used_labels, const std::unordered_map> used_weak_labels, - const std::unordered_map aliased_labels) + const std::unordered_map aliased_labels, + const std::unordered_map> used_data_labels) : AsmParser::JsonWriter::JsonWriter(out, lines, labels, filter), used_labels(used_labels), - used_weak_labels(used_weak_labels), aliased_labels(aliased_labels) + used_weak_labels(used_weak_labels), aliased_labels(aliased_labels), used_data_labels(used_data_labels) { } @@ -560,6 +561,40 @@ void AsmParser::DebugJsonWriter::write() } this->out << "}"; + this->out << ",\n"; + this->writeKeyName("used_data_labels"); + this->out << "{"; + firstLabel = true; + for (auto &usedlabel : this->used_data_labels) + { + if (firstLabel) + { + firstLabel = false; + } + else + { + this->out << ","; + } + + this->writeKeyName(usedlabel.first); + this->out << "["; + bool firstref = true; + for (auto &ref : usedlabel.second) + { + if (firstref) + { + firstref = false; + this->writeValue(ref, jsonopt::none); + } + else + { + this->writeValue(ref, jsonopt::prefixwithcomma); + } + } + this->out << "]"; + } + this->out << "}"; + this->out << ",\n"; this->writeKeyName("aliased_labels"); this->out << "{"; diff --git a/src/utils/jsonwriter.hpp b/src/utils/jsonwriter.hpp index 972dd65..7a96f29 100644 --- a/src/utils/jsonwriter.hpp +++ b/src/utils/jsonwriter.hpp @@ -58,6 +58,7 @@ class DebugJsonWriter : public JsonWriter const std::unordered_map> used_labels; const std::unordered_map> used_weak_labels; const std::unordered_map aliased_labels; + const std::unordered_map> used_data_labels; void writeDebugLine(const asm_line_v *line); @@ -68,7 +69,8 @@ class DebugJsonWriter : public JsonWriter const Filter filter, const std::unordered_map> used_labels, const std::unordered_map> used_weak_labels, - const std::unordered_map aliased_labels); + const std::unordered_map aliased_labels, + const std::unordered_map> used_data_labels); void write() override; }; diff --git a/src/utils/regexes.hpp b/src/utils/regexes.hpp index 23c01fd..f86ce96 100644 --- a/src/utils/regexes.hpp +++ b/src/utils/regexes.hpp @@ -50,8 +50,9 @@ struct Regexes static constexpr auto sourceD2Tag = ctre::match; static constexpr auto sourceD2File = ctre::match; static constexpr auto stdInLooking = ctre::search|^-$|example\.[^/]+$|)re">; - static constexpr auto startBlock = ctre::search; + static constexpr auto startProcBlock = ctre::search; static constexpr auto endBlock = ctre::search; + static constexpr auto endProcBlock = ctre::search; static constexpr auto sectionDef = ctre::search; diff --git a/src/utils/regexwrappers.cpp b/src/utils/regexwrappers.cpp index 07b661d..55558fb 100644 --- a/src/utils/regexwrappers.cpp +++ b/src/utils/regexwrappers.cpp @@ -412,9 +412,9 @@ bool AsmParser::AssemblyTextParserUtils::endAsmNesting(const std::string_view li return false; } -bool AsmParser::AssemblyTextParserUtils::startBlock(const std::string_view line) +bool AsmParser::AssemblyTextParserUtils::startProcBlock(const std::string_view line) { - if (Regexes::startBlock(line)) + if (Regexes::startProcBlock(line)) return true; return false; @@ -428,6 +428,14 @@ bool AsmParser::AssemblyTextParserUtils::endBlock(const std::string_view line) return false; } +bool AsmParser::AssemblyTextParserUtils::endProcBlock(const std::string_view line) +{ + if (Regexes::endProcBlock(line)) + return true; + + return false; +} + std::optional AsmParser::AssemblyTextParserUtils::getLabel(const std::string_view line) { auto match = Regexes::labelDef(line); diff --git a/src/utils/regexwrappers.hpp b/src/utils/regexwrappers.hpp index 625b21f..b2fc197 100644 --- a/src/utils/regexwrappers.hpp +++ b/src/utils/regexwrappers.hpp @@ -63,8 +63,9 @@ class AssemblyTextParserUtils static bool startAsmNesting(const std::string_view line); static bool endAsmNesting(const std::string_view line); - static bool startBlock(const std::string_view line); + static bool startProcBlock(const std::string_view line); static bool endBlock(const std::string_view line); + static bool endProcBlock(const std::string_view line); static bool isCudaEndDef(const std::string_view line); static bool isDataDefn(const std::string_view line); diff --git a/test.sh b/test.sh index 18e55bb..350531c 100755 --- a/test.sh +++ b/test.sh @@ -5,7 +5,7 @@ PATH=$PATH:/opt/compiler-explorer/cmake/bin export CXX=/opt/compiler-explorer/gcc-11.2.0/bin/g++ export CC=/opt/compiler-explorer/gcc-11.2.0/bin/gcc export CXXFLAGS="-I$PWD/ctre/include" -export LD_LIBRARY_PATH=/opt/compiler-explorer/gcc-11.2.0/lib64 +# export LD_LIBRARY_PATH=/opt/compiler-explorer/gcc-11.2.0/lib64 # export CXX=/opt/compiler-explorer/clang-12.0.0/bin/clang++ # export CC=/opt/compiler-explorer/clang-12.0.0/bin/clang @@ -43,6 +43,8 @@ if [ $? -ne 0 ]; then exit $? fi +patchelf --set-rpath /opt/compiler-explorer/gcc-11.2.0/lib64 bin/test + bin/test if [ $? -ne 0 ]; then exit $? @@ -54,10 +56,11 @@ if [ $? -ne 0 ]; then exit $? fi +patchelf --set-rpath /opt/compiler-explorer/gcc-11.2.0/lib64 bin/asm-parser + cd .. -echo 995test -/usr/bin/time --verbose build/bin/asm-parser -comment_only -directives -unused_labels /opt/compiler-explorer/ce/test/filters-cases/bug-995.asm > bla.json +# /usr/bin/time --verbose build/bin/asm-parser -comment_only -directives -unused_labels /opt/compiler-explorer/ce/test/filters-cases/bug-995.asm > bla.json # echo bintest-1 # build/bin/asm-parser -binary /opt/compiler-explorer/ce/test/filters-cases/bintest-1.asm > /opt/compiler-explorer/ce/test/filters-cases/bintest-1.asm.binary.directives.labels.comments.json