summaryrefslogtreecommitdiff
path: root/src/reduce.cc
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2017-07-27 12:11:13 -0400
committerAdrian Thurston <thurston@colm.net>2017-07-27 12:11:13 -0400
commit3f74fc17cee81774ddcc29c0a3560f81f7b60b7d (patch)
treedd3cc86a2cbc0b6eceb2755f084800718842fb1c /src/reduce.cc
parent1395ab646772f3c37e3fbad207d9f12a9d3f3140 (diff)
downloadcolm-3f74fc17cee81774ddcc29c0a3560f81f7b60b7d.tar.gz
added a read_reduce statement to call postfix reducer
Triggers the generation of the reducer. Accepts a stream.
Diffstat (limited to 'src/reduce.cc')
-rw-r--r--src/reduce.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/reduce.cc b/src/reduce.cc
index 4b6fa230..01f42d0f 100644
--- a/src/reduce.cc
+++ b/src/reduce.cc
@@ -43,7 +43,7 @@ void Compiler::writeCommitStub()
"int " << objectName << "_reducer_need_ign( program_t *prg, "
"struct pda_run *pda_run ) { return COLM_RN_BOTH; }\n"
"\n"
- "void " << objectName << "_read_reduce( program_t *prg, int reducer ) {}\n"
+ "void " << objectName << "_read_reduce( program_t *prg, int reducer, stream_t *stream ) {}\n"
;
}
@@ -438,6 +438,9 @@ void Compiler::writeCommit()
"#include <errno.h>\n"
"\n"
"#include <iostream>\n"
+ "#include <ext/stdio_filebuf.h>\n"
+ "#include <fstream>\n"
+ "\n"
"using std::endl;\n"
"\n"
"#include \"reducer.h\"\n"
@@ -626,7 +629,7 @@ void Compiler::writeCommit()
/* READ REDUCE */
*outStream <<
- "extern \"C\" void " << objectName << "_read_reduce( program_t *prg, int reducer )\n"
+ "extern \"C\" void " << objectName << "_read_reduce( program_t *prg, int reducer, stream_t *stream )\n"
"{\n"
" switch ( reducer ) {\n";
@@ -634,7 +637,7 @@ void Compiler::writeCommit()
Reduction *reduction = *r;
*outStream <<
" case " << reduction->id << ":\n"
- " ((" << reduction->name << "*)prg->red_ctx)->read_reduce_forward( prg );\n"
+ " ((" << reduction->name << "*)prg->red_ctx)->read_reduce_forward( prg, stream->impl->file );\n"
" break;\n";
}
@@ -685,9 +688,10 @@ void Compiler::writeCommit()
" *dest = 0;\n"
"}\n"
"\n"
- "void " << reduction->name << "::read_reduce_forward( program_t *prg )\n"
+ "void " << reduction->name << "::read_reduce_forward( program_t *prg, FILE *file )\n"
"{\n"
- " std::ifstream in( \"postfix.txt\" );\n"
+ " __gnu_cxx::stdio_filebuf<char> fbuf( file, std::ios::in|std::ios::out|std::ios::app );\n"
+ " std::iostream in( &fbuf );\n"
" std::string type, tok, text;\n"
" long _id, line, column, byte, prod_num, children;\n"
" read_reduce_node sentinal;\n"