Ignore:
Timestamp:
Jul 28, 2011, 7:22:06 AM (8 years ago)
Author:
cameron
Message:

Inline error reporting in parabix2_pablo.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/pablo_template.cpp

    r972 r1230  
    2626#include "TagMatcher.h"
    2727#include "LineColTracker.h"
     28
    2829
    2930#ifdef BUFFER_PROFILING
     
    4546int buffer_last;
    4647char * source;
     48
     49
    4750LineColTracker tracker;
     51
     52static inline void ReportError(const char * error_msg, int error_pos_in_block) {
     53  int error_line, error_column;
     54  tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
     55  fprintf(stderr, "%s at line %i, column %i\n", error_msg, error_line, error_column);
     56}
     57
     58class ErrorTracker {
     59public:
     60        ErrorTracker() { noted_pos_in_block = -1;}
     61
     62        inline void NoteError(const char * error_msg, BitBlock err_strm) {
     63          int pos_in_block = count_forward_zeroes(err_strm);
     64          if ((noted_pos_in_block == -1) || (noted_pos_in_block > pos_in_block)) {
     65            noted_pos_in_block = pos_in_block;
     66            noted_error = error_msg;
     67          }
     68        }
     69
     70        inline void If_Error_Report_First() {
     71          if (noted_pos_in_block > -1) {
     72                  int error_line, error_column;
     73                  ReportError(noted_error, noted_pos_in_block);
     74                  exit(-1);
     75          }
     76        }
     77 
     78private:
     79  const char * noted_error;
     80  int noted_pos_in_block;       
     81};
     82
     83
    4884TagMatcher matcher;
    4985BitBlock EOF_mask = simd_const_1(1);
    5086
     87ErrorTracker error_tracker;
    5188
    5289static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int)) {
     
    66103}
    67104
    68 
    69 static inline void ReportError(const char * error_msg, int error_pos_in_block) {
    70   int error_line, error_column;
    71   tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    72   fprintf(stderr, "%s at line %i, column %i\n", error_msg, error_line, error_column);
    73 }
    74105
    75106
     
    253284                }
    254285
    255                 if (bitblock_has_bit(check_streams.error_mask)) {
    256                   int errpos = count_forward_zeroes(check_streams.error_mask);
    257                   ReportError("error found", errpos);
    258               exit(-1);
    259                 }
     286                error_tracker.If_Error_Report_First();
    260287
    261288                matcher.store_streams(check_streams.tag_marks, check_streams.name_follows, check_streams.misc_mask, chars_avail);
Note: See TracChangeset for help on using the changeset viewer.