Ignore:
Timestamp:
Jul 31, 2010, 12:34:29 PM (9 years ago)
Author:
lindanl
Message:

stream scan for name checking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/template.c

    r557 r560  
    3030        void * parser_timer;
    3131#endif
     32
     33int block_base=0;
     34int buffer_base=0;
     35char * source;
     36
     37typedef long ScanBlock;
     38
     39static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int)) {
     40        int blk;
     41        int block_pos = 0;
     42
     43        for (blk = 0; blk < blk_count; blk++) {
     44                ScanBlock s = stream[blk];
     45                while(s) {
     46                        int code = (ProcessPos(cfzl(s) + block_pos));
     47                        if (code) return code;
     48                        s = s & (s-1);  // clear rightmost bit.
     49                }
     50                block_pos += 8 * sizeof(ScanBlock);
     51        }
     52        return 0;
     53}
     54
     55
    3256
    3357inline bool bit_test(unsigned char * bit_Map, int codepoint) {
     
    109133        }
    110134        else return 0;
     135}
     136
     137
     138static inline int NameStrt_check(int pos) {
     139        int block_pos = block_base + pos;
     140        if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&source[block_pos]) == 0){
     141              fprintf(stderr, "name start error found at position %i\n",block_pos+buffer_base);
     142              exit(-1);
     143        }
     144        return 0;
     145}
     146
     147static inline int Name_check(int pos) {
     148        int block_pos = block_base + pos;
     149        if(XML_10_UTF8_NameChar_bytes((unsigned char*)&source[block_pos]) == 0){
     150              fprintf(stderr, "name error found at position %i\n",block_pos+buffer_base);
     151              exit(-1);
     152        }
     153        return 0;
    111154}
    112155
     
    184227  char srcbuf[BUFFER_SIZE+BLOCK_SIZE];
    185228 
     229  buffer_base = buf_pos;
     230  source = srcbuf;
     231 
    186232  EOF_mask = simd_const_1(1);
    187233  chars_read = fread((void *)srcbuf, 1, BUFFER_SIZE, infile);
     
    239285        @block_stmts
    240286
     287
    241288        if (bitblock_has_bit(error_mask)) {
    242289          errpos = block_pos + buf_pos + count_forward_zeroes(error_mask);
     
    246293       
    247294        if (bitblock_has_bit(simd_or(name_check,name_start_check))) {
    248           if(bitblock_has_bit(name_start_check)){
    249             check_pos = block_pos + count_forward_zeroes(name_start_check);
    250             if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&srcbuf[check_pos]) == 0)
    251               fprintf(stderr, "name start error found at position %i\n",check_pos+buf_pos);
    252           }
    253           if(bitblock_has_bit(name_check)){
    254             check_pos = block_pos + count_forward_zeroes(name_start_check);
    255             if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&srcbuf[check_pos]) == 0)
    256               fprintf(stderr, "name error found at position %i\n",check_pos+buf_pos);
    257           }
     295          block_base = block_pos;
     296          StreamScan((ScanBlock *) &name_start_check, sizeof(BitBlock)/sizeof(ScanBlock), NameStrt_check);
     297          StreamScan((ScanBlock *) &name_check, sizeof(BitBlock)/sizeof(ScanBlock), Name_check);
    258298        }
    259299       
     
    286326       
    287327        if (bitblock_has_bit(simd_or(name_check,name_start_check))) {
    288           if(bitblock_has_bit(name_start_check)){
    289             check_pos = block_pos + count_forward_zeroes(name_start_check);
    290             if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&srcbuf[check_pos]) == 0)
    291               fprintf(stderr, "name start error found at position %i\n",check_pos+buf_pos);
    292           }
    293           if(bitblock_has_bit(name_check)){
    294             check_pos = block_pos + count_forward_zeroes(name_start_check);
    295             if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&srcbuf[check_pos]) == 0)
    296               fprintf(stderr, "name error found at position %i\n",check_pos+buf_pos);
    297           }
     328          block_base = block_pos;
     329          StreamScan((ScanBlock *) &name_start_check, sizeof(BitBlock)/sizeof(ScanBlock), NameStrt_check);
     330          StreamScan((ScanBlock *) &name_check, sizeof(BitBlock)/sizeof(ScanBlock), Name_check);
    298331        }
    299332       
     
    341374        }
    342375
    343         PERF_SEC_BIND(1);
     376//      PERF_SEC_BIND(1);
    344377
    345378        PERF_SEC_INIT(parser_timer);
Note: See TracChangeset for help on using the changeset viewer.