|
6 | 6 |
|
7 | 7 | \*******************************************************************/
|
8 | 8 |
|
9 |
| -#include <fstream> |
| 9 | +#include "verilog_preprocessor.h" |
10 | 10 |
|
11 | 11 | #include <util/config.h>
|
12 | 12 |
|
13 |
| -#include "verilog_preprocessor.h" |
| 13 | +#include "verilog_preprocessor_error.h" |
| 14 | + |
| 15 | +#include <fstream> |
14 | 16 |
|
15 | 17 | /*******************************************************************\
|
16 | 18 |
|
@@ -245,44 +247,55 @@ Function: verilog_preprocessort::preprocessor
|
245 | 247 |
|
246 | 248 | void verilog_preprocessort::preprocessor()
|
247 | 249 | {
|
248 |
| - files.emplace_back(false, &in, filename); |
249 |
| - |
250 |
| - while(!files.empty()) |
| 250 | + try |
251 | 251 | {
|
252 |
| - files.back().print_line(out, files.size()==1?0:2); |
| 252 | + files.emplace_back(false, &in, filename); |
253 | 253 |
|
254 |
| - char ch, last_out=0; |
255 |
| - |
256 |
| - while(files.back().get(ch)) |
| 254 | + while(!files.empty()) |
257 | 255 | {
|
258 |
| - switch(ch) |
259 |
| - { |
260 |
| - case '`': |
261 |
| - directive(); |
262 |
| - break; |
| 256 | + files.back().print_line(out, files.size() == 1 ? 0 : 2); |
263 | 257 |
|
264 |
| - default: |
265 |
| - if(condition) |
| 258 | + char ch, last_out = 0; |
| 259 | + |
| 260 | + while(files.back().get(ch)) |
| 261 | + { |
| 262 | + switch(ch) |
266 | 263 | {
|
267 |
| - filet &file=files.back(); |
| 264 | + case '`': |
| 265 | + directive(); |
| 266 | + break; |
268 | 267 |
|
269 |
| - if(last_out=='\n' && file.last_line!=file.line && |
270 |
| - ch!='\n') |
| 268 | + default: |
| 269 | + if(condition) |
271 | 270 | {
|
272 |
| - file.print_line(out, 0); |
273 |
| - file.last_line=file.line; |
274 |
| - } |
| 271 | + filet &file = files.back(); |
| 272 | + |
| 273 | + if(last_out == '\n' && file.last_line != file.line && ch != '\n') |
| 274 | + { |
| 275 | + file.print_line(out, 0); |
| 276 | + file.last_line = file.line; |
| 277 | + } |
275 | 278 |
|
276 |
| - out << ch; |
277 |
| - last_out=ch; |
| 279 | + out << ch; |
| 280 | + last_out = ch; |
278 | 281 |
|
279 |
| - if(ch=='\n') file.last_line++; |
| 282 | + if(ch == '\n') |
| 283 | + file.last_line++; |
| 284 | + } |
280 | 285 | }
|
281 | 286 | }
|
282 |
| - } |
283 | 287 |
|
284 |
| - if(last_out!='\n') out << '\n'; |
285 |
| - files.pop_back(); |
| 288 | + if(last_out != '\n') |
| 289 | + out << '\n'; |
| 290 | + files.pop_back(); |
| 291 | + } |
| 292 | + } |
| 293 | + catch(const verilog_preprocessor_errort &e) |
| 294 | + { |
| 295 | + if(!files.empty()) |
| 296 | + error().source_location = files.back().make_source_location(); |
| 297 | + error() << e.what() << eom; |
| 298 | + throw 0; |
286 | 299 | }
|
287 | 300 | }
|
288 | 301 |
|
@@ -591,9 +604,8 @@ void verilog_preprocessort::directive()
|
591 | 604 |
|
592 | 605 | if(it==defines.end())
|
593 | 606 | {
|
594 |
| - error().source_location = source_location; |
595 |
| - error() << "unknown preprocessor directive \"" << text << "\"" << eom; |
596 |
| - throw 0; |
| 607 | + throw verilog_preprocessor_errort() |
| 608 | + << "unknown preprocessor directive \"" << text << "\""; |
597 | 609 | }
|
598 | 610 |
|
599 | 611 | // found it! replace it!
|
|
0 commit comments