|
6 | 6 |
|
7 | 7 | \*******************************************************************/
|
8 | 8 |
|
9 |
| -#include <fstream> |
| 9 | +#include "verilog_preprocessor.h" |
10 | 10 |
|
11 | 11 | #include <util/config.h>
|
12 | 12 | #include <util/file_util.h>
|
13 | 13 |
|
14 |
| -#include "verilog_preprocessor.h" |
| 14 | +#include "verilog_preprocessor_error.h" |
| 15 | + |
| 16 | +#include <fstream> |
15 | 17 |
|
16 | 18 | /*******************************************************************\
|
17 | 19 |
|
@@ -221,44 +223,55 @@ Function: verilog_preprocessort::preprocessor
|
221 | 223 |
|
222 | 224 | void verilog_preprocessort::preprocessor()
|
223 | 225 | {
|
224 |
| - files.emplace_back(false, &in, filename); |
225 |
| - |
226 |
| - while(!files.empty()) |
| 226 | + try |
227 | 227 | {
|
228 |
| - files.back().print_line(out, files.size()==1?0:2); |
| 228 | + files.emplace_back(false, &in, filename); |
229 | 229 |
|
230 |
| - char ch, last_out=0; |
231 |
| - |
232 |
| - while(files.back().get(ch)) |
| 230 | + while(!files.empty()) |
233 | 231 | {
|
234 |
| - switch(ch) |
235 |
| - { |
236 |
| - case '`': |
237 |
| - directive(); |
238 |
| - break; |
| 232 | + files.back().print_line(out, files.size() == 1 ? 0 : 2); |
239 | 233 |
|
240 |
| - default: |
241 |
| - if(condition) |
| 234 | + char ch, last_out = 0; |
| 235 | + |
| 236 | + while(files.back().get(ch)) |
| 237 | + { |
| 238 | + switch(ch) |
242 | 239 | {
|
243 |
| - filet &file=files.back(); |
| 240 | + case '`': |
| 241 | + directive(); |
| 242 | + break; |
244 | 243 |
|
245 |
| - if(last_out=='\n' && file.last_line!=file.line && |
246 |
| - ch!='\n') |
| 244 | + default: |
| 245 | + if(condition) |
247 | 246 | {
|
248 |
| - file.print_line(out, 0); |
249 |
| - file.last_line=file.line; |
250 |
| - } |
| 247 | + filet &file = files.back(); |
| 248 | + |
| 249 | + if(last_out == '\n' && file.last_line != file.line && ch != '\n') |
| 250 | + { |
| 251 | + file.print_line(out, 0); |
| 252 | + file.last_line = file.line; |
| 253 | + } |
251 | 254 |
|
252 |
| - out << ch; |
253 |
| - last_out=ch; |
| 255 | + out << ch; |
| 256 | + last_out = ch; |
254 | 257 |
|
255 |
| - if(ch=='\n') file.last_line++; |
| 258 | + if(ch == '\n') |
| 259 | + file.last_line++; |
| 260 | + } |
256 | 261 | }
|
257 | 262 | }
|
258 |
| - } |
259 | 263 |
|
260 |
| - if(last_out!='\n') out << '\n'; |
261 |
| - files.pop_back(); |
| 264 | + if(last_out != '\n') |
| 265 | + out << '\n'; |
| 266 | + files.pop_back(); |
| 267 | + } |
| 268 | + } |
| 269 | + catch(const verilog_preprocessor_errort &e) |
| 270 | + { |
| 271 | + if(!files.empty()) |
| 272 | + error().source_location = files.back().make_source_location(); |
| 273 | + error() << e.what() << eom; |
| 274 | + throw 0; |
262 | 275 | }
|
263 | 276 | }
|
264 | 277 |
|
@@ -567,9 +580,8 @@ void verilog_preprocessort::directive()
|
567 | 580 |
|
568 | 581 | if(it==defines.end())
|
569 | 582 | {
|
570 |
| - error().source_location = source_location; |
571 |
| - error() << "unknown preprocessor directive \"" << text << "\"" << eom; |
572 |
| - throw 0; |
| 583 | + throw verilog_preprocessor_errort() |
| 584 | + << "unknown preprocessor directive \"" << text << "\""; |
573 | 585 | }
|
574 | 586 |
|
575 | 587 | // found it! replace it!
|
|
0 commit comments