Skip to content

Commit

Permalink
remove _DEBUG and related code
Browse files Browse the repository at this point in the history
dumpNFAGraphViz and dumpDFAGraphViz are only used in _DEBUG mode.
But _DEBUG will never be used. Remove them for simpler code and one fewer warning
  • Loading branch information
linh2931 committed Oct 2, 2022
1 parent 3b83c1b commit 60e0ad1
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 168 deletions.
6 changes: 1 addition & 5 deletions libraries/wasm-jit/Source/Logging/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 1 addition & 21 deletions libraries/wasm-jit/Source/WAST/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -366,4 +346,4 @@ namespace WAST

return result;
}
}
}
135 changes: 0 additions & 135 deletions libraries/wasm-jit/Source/WAST/NFA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StateIndex> 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=\"&epsilon;\"];\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<StateIndex> 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<StateIndex,CharSet> 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 ? "&epsilon; " : "")
+ 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<StateIndex,CharSet> 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 ? "&epsilon; " : "")
+ 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;
}
}
8 changes: 1 addition & 7 deletions libraries/wasm-jit/Source/WAST/NFA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand All @@ -86,4 +80,4 @@ namespace NFA

void moveFrom(Machine&& inMachine);
};
}
}

0 comments on commit 60e0ad1

Please sign in to comment.