From: Ulya Trofimovich Date: Mon, 17 Jul 2017 22:11:18 +0000 (+0100) Subject: Split source file in two. X-Git-Tag: 1.0~39^2~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13a93f126ff551d442dbecbfe5350b9cadef8b18;p=re2c Split source file in two. --- diff --git a/re2c/Makefile.am b/re2c/Makefile.am index 5fb65d94..6656a7c2 100644 --- a/re2c/Makefile.am +++ b/re2c/Makefile.am @@ -96,6 +96,7 @@ SRC = \ src/dfa/cfg/compact.cc \ src/dfa/cfg/dce.cc \ src/dfa/cfg/dump.cc \ + src/dfa/cfg/freeze.cc \ src/dfa/cfg/interfere.cc \ src/dfa/cfg/liveanal.cc \ src/dfa/cfg/normalize.cc \ diff --git a/re2c/src/dfa/cfg/freeze.cc b/re2c/src/dfa/cfg/freeze.cc new file mode 100644 index 00000000..6b8e9fb5 --- /dev/null +++ b/re2c/src/dfa/cfg/freeze.cc @@ -0,0 +1,52 @@ +#include "src/dfa/dfa.h" + +namespace re2c +{ + +/* note [tag freezing] + * + * Comparison of tag commands should be very fast (constant time): + * many optimizations rely on this (like tunnelling, hoisting and + * especially Moore's minimization, which compares whole classes + * of tagged transition at once). So we bring each command to some + * 'normal form' and insert it into common index. + * + * After that commands can be addressed and compared by index. + * They also become immutable, because different commands may + * share representation in memory. + */ +void freeze_tags(dfa_t &dfa) +{ + tcpool_t &pool = dfa.tcpool; + const size_t + nstate = dfa.states.size(), + nsym = dfa.nchars; + + dfa.tcid0 = pool.insert(dfa.tcmd0); + dfa.tcmd0 = NULL; + + for (size_t i = 0; i < nstate; ++i) { + dfa_state_t *s = dfa.states[i]; + tcmd_t **cmd = s->tcmd, + **const fin = cmd + nsym, + **const fall = fin + 1; + tcid_t *id = s->tcid = new tcid_t[nsym + 2]; + + // transition commands + for(; cmd < fin; ++cmd) { + *id++ = pool.insert(*cmd); + } + + // final epsilon-transition command + *id++ = pool.insert(*fin); + + // fallback epsilon-transition command + *id++ = pool.insert(*fall); + + delete[] s->tcmd; + s->tcmd = NULL; + } +} + +} // namespace re2c + diff --git a/re2c/src/dfa/cfg/optimize.cc b/re2c/src/dfa/cfg/optimize.cc index 02f76a00..f27820c0 100644 --- a/re2c/src/dfa/cfg/optimize.cc +++ b/re2c/src/dfa/cfg/optimize.cc @@ -39,50 +39,5 @@ void optimize_tags(dfa_t &dfa) } } -/* note [tag freezing] - * - * Comparison of tag commands should be very fast (constant time): - * many optimizations rely on this (like tunnelling, hoisting and - * especially Moore's minimization, which compares whole classes - * of tagged transition at once). So we bring each command to some - * 'normal form' and insert it into common index. - * - * After that commands can be addressed and compared by index. - * They also become immutable, because different commands may - * share representation in memory. - */ -void freeze_tags(dfa_t &dfa) -{ - tcpool_t &pool = dfa.tcpool; - const size_t - nstate = dfa.states.size(), - nsym = dfa.nchars; - - dfa.tcid0 = pool.insert(dfa.tcmd0); - dfa.tcmd0 = NULL; - - for (size_t i = 0; i < nstate; ++i) { - dfa_state_t *s = dfa.states[i]; - tcmd_t **cmd = s->tcmd, - **const fin = cmd + nsym, - **const fall = fin + 1; - tcid_t *id = s->tcid = new tcid_t[nsym + 2]; - - // transition commands - for(; cmd < fin; ++cmd) { - *id++ = pool.insert(*cmd); - } - - // final epsilon-transition command - *id++ = pool.insert(*fin); - - // fallback epsilon-transition command - *id++ = pool.insert(*fall); - - delete[] s->tcmd; - s->tcmd = NULL; - } -} - } // namespace re2c