From d607832645f6ed41b60db1928a281003dcf69083 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 20 May 2015 09:34:26 +0100 Subject: [PATCH] Finally removed auxiliary code generation pass to 'null device'. This pass was used to gather statistics: - which labels are used (to avoid 'unused label' warnings from C/C++ compiler) - in '-f' mode, how many times YYFILL is called (to generate dispatch to the arrpopriate YYFILL call and resume lexing from there) This commit deals with second case: it makes counting YYFILL calls independent of auxiliary pass. Counting relies on variable 're2c::last_fill_index', which is updated in 're2c::need' function (note that it is crucial that 're2c::need' is always called prior to generation of state dispatch). Also fixed documentation for '-f'. --- re2c/doc/re2c.ad.in | 9 ++------- re2c/src/codegen/emit_action.cc | 4 ++-- re2c/src/codegen/emit_dfa.cc | 17 ----------------- re2c/src/globals.h | 1 - re2c/src/main.cc | 1 - re2c/src/parse/scanner.cc | 2 +- 6 files changed, 5 insertions(+), 29 deletions(-) diff --git a/re2c/doc/re2c.ad.in b/re2c/doc/re2c.ad.in index 535025f3..b05e4713 100644 --- a/re2c/doc/re2c.ad.in +++ b/re2c/doc/re2c.ad.in @@ -724,18 +724,13 @@ chunk by chunk. When the scanner runs out of data to consume, it just stores its state, and return to the caller. When more input data is fed to the scanner, it resumes operations exactly where it left off. -When using the *-f* option *re2c* does not accept stdin because it has to do the -full generation process twice which means it has to read the input twice. That -means *re2c* would fail in case it cannot open the input twice or reading the -input for the first time influences the second read attempt. - Changes needed compared to the ``pull'' model: . User has to supply macros *YYSETSTATE ()* and *YYGETSTATE (state)*. . The *-f* option inhibits declaration of *yych* and *yyaccept*. So the user has to declare these. Also the user has -to save and restore these. In the example *examples/push.re* these +to save and restore these. In the example *examples/push_model/push.re* these are declared as fields of the (C\++) class of which the scanner is a method, so they do not need to be saved/restored explicitly. For C they could e.g. be made macros that select fields from a structure @@ -758,7 +753,7 @@ It is possible to trigger generation of the *YYGETSTATE ()* block earlier by placing a *$$/*!getstate:re2c*/$$* comment. This is especially useful when the scanner code should be wrapped inside a loop. -Please see *examples/push.re* for push-model scanner. The generated code can be +Please see *examples/push_model/push.re* for push-model scanner. The generated code can be tweaked using inplace configurations *$$state:abort$$* and *$$state:nextlabel$$*. diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index b1f0b577..57e140e6 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -304,11 +304,11 @@ void need (OutputFile & o, uint32_t ind, bool & readCh, uint32_t n, bool bSetMar return; } - uint32_t fillIndex = next_fill_index; + uint32_t fillIndex = last_fill_index; if (fFlag) { - next_fill_index++; + last_fill_index++; if (bUseYYSetStateParam) { o << indent(ind) << mapCodeName["YYSETSTATE"] << "(" << fillIndex << ");\n"; diff --git a/re2c/src/codegen/emit_dfa.cc b/re2c/src/codegen/emit_dfa.cc index faec05e8..457c1f64 100644 --- a/re2c/src/codegen/emit_dfa.cc +++ b/re2c/src/codegen/emit_dfa.cc @@ -111,23 +111,6 @@ void DFA::emit(Output & output, uint32_t& ind, const RegExpMap* specMap, const s vUsedLabels.insert(it->second->label); } - // Save 'next_fill_index' and compute information about code generation - // while writing to null device. - uint32_t save_fill_index = next_fill_index; - Output null_dev (NULL, NULL); - - for (s = head; s; s = s->next) - { - bool readCh = false; - s->emit(null_dev.source, ind, readCh, condName); - s->go.emit(null_dev.source, ind, readCh); - } - if (last_fill_index < next_fill_index) - { - last_fill_index = next_fill_index; - } - next_fill_index = save_fill_index; - // Generate prolog if (bProlog) { diff --git a/re2c/src/globals.h b/re2c/src/globals.h index 8c8d038e..e467a2ca 100644 --- a/re2c/src/globals.h +++ b/re2c/src/globals.h @@ -75,7 +75,6 @@ extern const uint32_t asc2asc[256]; extern const uint32_t asc2ebc[256]; extern const uint32_t ebc2asc[256]; -extern uint32_t next_fill_index; extern uint32_t last_fill_index; extern std::set vUsedLabels; extern CodeNames mapCodeName; diff --git a/re2c/src/main.cc b/re2c/src/main.cc index 62c8b6d4..11f1f6c0 100644 --- a/re2c/src/main.cc +++ b/re2c/src/main.cc @@ -72,7 +72,6 @@ bool bCaseInverted = false; Enc encoding; InputAPI input_api; -uint32_t next_fill_index = 0; uint32_t last_fill_index = 0; std::set vUsedLabels; CodeNames mapCodeName; diff --git a/re2c/src/parse/scanner.cc b/re2c/src/parse/scanner.cc index 4a4a2b0c..e6dad635 100644 --- a/re2c/src/parse/scanner.cc +++ b/re2c/src/parse/scanner.cc @@ -451,7 +451,7 @@ Scanner::~Scanner() void Scanner::reuse() { next_label = 0; - next_fill_index = 0; + last_fill_index = 0; bWroteGetState = false; bWroteCondCheck = false; mapCodeName.clear(); -- 2.40.0