From 60e0ad1ec2c4eaf06c0aff90d662dd6eef986d31 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Sun, 2 Oct 2022 09:37:53 -0400 Subject: [PATCH] remove _DEBUG and related code dumpNFAGraphViz and dumpDFAGraphViz are only used in _DEBUG mode. But _DEBUG will never be used. Remove them for simpler code and one fewer warning --- libraries/wasm-jit/Source/Logging/Logging.cpp | 6 +- libraries/wasm-jit/Source/WAST/Lexer.cpp | 22 +-- libraries/wasm-jit/Source/WAST/NFA.cpp | 135 ------------------ libraries/wasm-jit/Source/WAST/NFA.h | 8 +- 4 files changed, 3 insertions(+), 168 deletions(-) diff --git a/libraries/wasm-jit/Source/Logging/Logging.cpp b/libraries/wasm-jit/Source/Logging/Logging.cpp index 7fae383da9..672cc6f632 100644 --- a/libraries/wasm-jit/Source/Logging/Logging.cpp +++ b/libraries/wasm-jit/Source/Logging/Logging.cpp @@ -10,11 +10,7 @@ namespace Log static bool categoryEnabled[(Uptr)Category::num] = { true, // error - #ifdef _DEBUG // debug - true, - #else - false, - #endif + false, // debug WAVM_METRICS_OUTPUT != 0 // metrics }; void setCategoryEnabled(Category category,bool enable) diff --git a/libraries/wasm-jit/Source/WAST/Lexer.cpp b/libraries/wasm-jit/Source/WAST/Lexer.cpp index c345d79ab3..addd7acfd2 100644 --- a/libraries/wasm-jit/Source/WAST/Lexer.cpp +++ b/libraries/wasm-jit/Source/WAST/Lexer.cpp @@ -121,26 +121,6 @@ namespace WAST addLiteralToNFA(literalString,nfaBuilder,0,finalState); } - #ifndef _DEBUG - if(false) - #endif - { - std::ofstream debugGraphStream("nfaGraph.dot"); - debugGraphStream << NFA::dumpNFAGraphViz(nfaBuilder).c_str(); - debugGraphStream.close(); - } - - nfaMachine = NFA::Machine(nfaBuilder); - - #ifndef _DEBUG - if(false) - #endif - { - std::ofstream debugGraphStream("dfaGraph.dot"); - debugGraphStream << nfaMachine.dumpDFAGraphViz().c_str(); - debugGraphStream.close(); - } - Timing::logTimer("built lexer tables",timer); } @@ -366,4 +346,4 @@ namespace WAST return result; } -} \ No newline at end of file +} diff --git a/libraries/wasm-jit/Source/WAST/NFA.cpp b/libraries/wasm-jit/Source/WAST/NFA.cpp index 27352fe7e1..d7bb7b40f1 100644 --- a/libraries/wasm-jit/Source/WAST/NFA.cpp +++ b/libraries/wasm-jit/Source/WAST/NFA.cpp @@ -463,139 +463,4 @@ namespace NFA if(numSetChars > 1) { edgeLabel += "]"; } return edgeLabel; } - - std::string dumpNFAGraphViz(const Builder* builder) - { - std::string result; - result += "digraph {\n"; - std::set terminalStates; - for(Uptr stateIndex = 0;stateIndex < builder->nfaStates.size();++stateIndex) - { - const NFAState& nfaState = builder->nfaStates[stateIndex]; - - result += "state" + std::to_string(stateIndex) + "[shape=square label=\"" + std::to_string(stateIndex) + "\"];\n"; - - for(const auto& statePredicatePair : nfaState.nextStateToPredicateMap) - { - std::string edgeLabel = getGraphEdgeLabel(statePredicatePair.second); - std::string nextStateName = statePredicatePair.first < 0 - ? "terminal" + std::to_string(-statePredicatePair.first) - : "state" + std::to_string(statePredicatePair.first); - result += "state" + std::to_string(stateIndex) - + " -> " - + nextStateName + "[label=\"" + escapeString(edgeLabel) + "\"];\n"; - if(statePredicatePair.first < 0) - { - terminalStates.emplace(statePredicatePair.first); - } - } - - for(auto epsilonNextState : nfaState.epsilonNextStates) - { - std::string nextStateName = epsilonNextState < 0 - ? "terminal" + std::to_string(-epsilonNextState) - : "state" + std::to_string(epsilonNextState); - result += "state" + std::to_string(stateIndex) + " -> " + nextStateName + "[label=\"ε\"];\n"; - } - } - for(auto terminalState : terminalStates) - { - result += "terminal" + std::to_string(-terminalState) - + "[shape=octagon label=\"" + std::to_string(maximumTerminalStateIndex - terminalState) + "\"];\n"; - } - result += "}\n"; - return result; - } - - std::string Machine::dumpDFAGraphViz() const - { - std::string result; - result += "digraph {\n"; - std::set terminalStates; - - CharSet* classCharSets = (CharSet*)alloca(sizeof(CharSet) * numClasses); - memset((char*)classCharSets,0,sizeof(CharSet) * numClasses); - for(Uptr charIndex = 0;charIndex < 256;++charIndex) - { - const Uptr classIndex = charToOffsetMap[charIndex] / numStates; - classCharSets[classIndex].add((U8)charIndex); - } - - { - std::map transitions; - for(Uptr classIndex = 0;classIndex < numClasses;++classIndex) - { - const InternalStateIndex nextState = stateAndOffsetToNextStateMap[0 + classIndex * numStates]; - CharSet& transitionPredicate = transitions[nextState]; - transitionPredicate = classCharSets[classIndex] | transitionPredicate; - } - - Uptr startIndex = 0; - for(auto transitionPair : transitions) - { - if((transitionPair.first & ~edgeDoesntConsumeInputFlag) != unmatchedCharacterTerminal) - { - result += "start" + std::to_string(startIndex) + "[shape=triangle label=\"\"];\n"; - - std::string edgeLabel = getGraphEdgeLabel(transitionPair.second); - std::string nextStateName = transitionPair.first < 0 - ? "terminal" + std::to_string(-(transitionPair.first & ~edgeDoesntConsumeInputFlag)) - : "state" + std::to_string(transitionPair.first); - result += "start" + std::to_string(startIndex) - + " -> " - + nextStateName + "[label=\"" - + (transitionPair.first < 0 && (transitionPair.first & edgeDoesntConsumeInputFlag) != 0 ? "ε " : "") - + escapeString(edgeLabel) + "\"];\n"; - - if(transitionPair.first < 0) - { - terminalStates.emplace(StateIndex(transitionPair.first & ~edgeDoesntConsumeInputFlag)); - } - - ++startIndex; - } - } - } - - for(Uptr stateIndex = 1;stateIndex < numStates;++stateIndex) - { - result += "state" + std::to_string(stateIndex) + "[shape=square label=\"" + std::to_string(stateIndex) + "\"];\n"; - - std::map transitions; - for(Uptr classIndex = 0;classIndex < numClasses;++classIndex) - { - const InternalStateIndex nextState = stateAndOffsetToNextStateMap[stateIndex + classIndex * numStates]; - CharSet& transitionPredicate = transitions[nextState]; - transitionPredicate = classCharSets[classIndex] | transitionPredicate; - } - - for(auto transitionPair : transitions) - { - if((transitionPair.first & ~edgeDoesntConsumeInputFlag) != unmatchedCharacterTerminal) - { - std::string edgeLabel = getGraphEdgeLabel(transitionPair.second); - std::string nextStateName = transitionPair.first < 0 - ? "terminal" + std::to_string(-(transitionPair.first & ~edgeDoesntConsumeInputFlag)) - : "state" + std::to_string(transitionPair.first); - result += "state" + std::to_string(stateIndex) - + " -> " - + nextStateName + "[label=\"" - + (transitionPair.first < 0 && (transitionPair.first & edgeDoesntConsumeInputFlag) != 0 ? "ε " : "") - + escapeString(edgeLabel) + "\"];\n"; - - if(transitionPair.first < 0) - { - terminalStates.emplace(transitionPair.first); - } - } - } - } - for(auto terminalState : terminalStates) - { - result += "terminal" + std::to_string(-(terminalState & ~edgeDoesntConsumeInputFlag)) - + "[shape=octagon label=\"" + std::to_string(maximumTerminalStateIndex - (terminalState & ~edgeDoesntConsumeInputFlag)) + "\"];\n"; - } - result += "}\n"; - return result; - } } diff --git a/libraries/wasm-jit/Source/WAST/NFA.h b/libraries/wasm-jit/Source/WAST/NFA.h index 73331c0fec..bb1e74d2c6 100644 --- a/libraries/wasm-jit/Source/WAST/NFA.h +++ b/libraries/wasm-jit/Source/WAST/NFA.h @@ -30,9 +30,6 @@ namespace NFA void addEpsilonEdge(Builder* builder,StateIndex initialState,StateIndex nextState); StateIndex getNonTerminalEdge(Builder* builder,StateIndex initialState,char c); - // Dumps the NFA's states and edges to the GraphViz .dot format. - std::string dumpNFAGraphViz(const Builder* builder); - // Encapsulates a NFA that has been translated into a DFA that can be efficiently executed. struct Machine { @@ -71,9 +68,6 @@ namespace NFA return (StateIndex)state; } - // Dumps the DFA's states and edges to the GraphViz .dot format. - std::string dumpDFAGraphViz() const; - private: typedef I16 InternalStateIndex; @@ -86,4 +80,4 @@ namespace NFA void moveFrom(Machine&& inMachine); }; -} \ No newline at end of file +}