aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorClément Zrounba <6691770+clement-z@users.noreply.github.com>2023-11-03 15:04:06 +0100
committerClément Zrounba <6691770+clement-z@users.noreply.github.com>2023-11-03 15:04:06 +0100
commite95498f8e547b42233dfa2e1e756cac88ac4c5b9 (patch)
treeab09fbd0c253bb777ae99d0a4fd50911e8fa2727 /src
parent13c2d1ab595c5676ecd3f6bd974d834e2c3062c0 (diff)
downloadspecs-e95498f8e547b42233dfa2e1e756cac88ac4c5b9.tar.gz
specs-e95498f8e547b42233dfa2e1e756cac88ac4c5b9.zip
improve handling of multiple files
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp15
-rw-r--r--src/parser/parser.l15
2 files changed, 26 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 08cef21..e850e34 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -27,6 +27,7 @@ using namespace literals;
#include "../build/parser/parser.yy.h"
extern int yydebug;
int yywrap(yyscan_t scanner);
+extern "C" int yy_delete_buffer(yyscan_t scanner);
static deque<YY_BUFFER_STATE> netlist_buf_fifo;
@@ -42,13 +43,22 @@ FILE* open_netlist_file(const string &filename, yyscan_t &scanner)
exit(1);
}
+ string header = "\n**** START of " + filename + " ****\n";
+ netlist_buf_fifo.push_back(yy_scan_string(header.c_str(), scanner));
+
YY_BUFFER_STATE buf = yy_create_buffer(f, YY_BUF_SIZE, scanner);
netlist_buf_fifo.push_back(buf);
+
+ string footer = "\n**** END of " + filename + " ****\n";
+ netlist_buf_fifo.push_back(yy_scan_string(footer.c_str(), scanner));
+
return f;
}
int yywrap(yyscan_t scanner)
{
+ static YY_BUFFER_STATE *last_buffer = NULL;
+
if (netlist_buf_fifo.empty())
return 1;
else
@@ -56,6 +66,11 @@ int yywrap(yyscan_t scanner)
YY_BUFFER_STATE buf = netlist_buf_fifo.front();
netlist_buf_fifo.pop_front();
yy_switch_to_buffer(buf, scanner);
+ if ( last_buffer )
+ {
+ yy_delete_buffer( *last_buffer, scanner);
+ last_buffer = &buf;
+ }
return 0;
}
}
diff --git a/src/parser/parser.l b/src/parser/parser.l
index 7c33630..3edda2f 100644
--- a/src/parser/parser.l
+++ b/src/parser/parser.l
@@ -93,6 +93,13 @@ static T from_string(const string &str)
%% /*** Rules section ***/
+^.*{EOL} {
+ // print the netlist as it is read
+ // note: doesnt handle included files
+ if(false)
+ cout << yytext; REJECT;
+}
+
^\.include {yy_push_state(INCLUDE, yyscanner);}
<INCLUDE>{WS}* /* eat the whitespace */
<INCLUDE>[^ ;\t\n\r]+ { /* got the include file name */
@@ -383,12 +390,12 @@ static T from_string(const string &str)
<INITIAL,INCLUDE><<EOF>> {
yypop_buffer_state(yyscanner);
- if ( !YY_CURRENT_BUFFER )
- {
+ if ( !YY_CURRENT_BUFFER )
+ {
yyterminate();
- }
- return '\n';
}
+ return '\n';
+}
<SUBCKT_DECLARATION,IN_DQUOTES><<EOF>> {
exit(yylerror(yyscanner, "Unexpected end of file."));