Ignore:
Timestamp:
Feb 2, 2011, 11:41:20 PM (9 years ago)
Author:
ksherdy
Message:

Update template and compilable for separate compilation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/pablo_template.c

    r866 r881  
    1414typedef SIMD_type BitBlock;
    1515
    16 
    1716#include "../lib/carryQ.h"
    18 
    19 
    20        
    21 
    2217#include "xmldecl.h"
    2318#include "xml_error.c"
     
    4944int buffer_last;
    5045char * source;
    51 LineColTracker tracker; 
     46LineColTracker tracker;
    5247
    5348
     
    6661        }
    6762        return 0;
    68 } 
     63}
    6964
    7065
     
    9691static inline int PIName_check(int pos) {
    9792        int block_pos = block_base + pos;
    98         int file_pos = block_pos+buffer_base; 
     93        int file_pos = block_pos+buffer_base;
    9994        if (at_XxMmLll<ASCII>((unsigned char*)&source[block_pos]) && (source[block_pos+3]=='?' || source[block_pos+3]<= ' ')) {
    10095              // "<?xml" legal at start of file.
     
    184179            }
    185180          }
    186           else{     
     181          else{
    187182            while(at_HexDigit<ASCII>(s)){
    188183              ch_val = DigitVal<ASCII>(s[0]) + ch_val*10;
     
    193188            ReportError("Attribute values contain '<' characters after reference expansion", pos);
    194189            exit(-1);
    195           }       
     190          }
    196191        }
    197192        else if(at_Ref_lt<ASCII>(s)){
    198193          ReportError("Attribute values contain '<' characters after reference expansion", pos);
    199194          exit(-1);
    200         }         
     195        }
    201196        return 0;
    202197}
     
    206201void do_process(FILE *infile, FILE *outfile) {
    207202
    208   @decl
    209 
    210 
     203@decl
     204
     205  masks.EOF_mask = simd_const_1(1);
     206  BitBlock EOF_mask = simd_const_1(1);
    211207
    212208  BytePack U8[8];
    213   BitBlock bit[8];
    214   BitBlock EOF_mask = simd_const_1(1);
     209//  BitBlock bit[8];
    215210  int buf_pos = 0;
    216211  int block_pos = 0;
     
    220215  int chars_read = 0;
    221216  BytePack buf[(BUFFER_SIZE+BLOCK_SIZE+OVERLAP_BUFSIZE*2)/sizeof(SIMD_type)];
    222  
     217
    223218  char * srcbuf = ((char *) buf) + OVERLAP_BUFSIZE;
    224219  buffer_base = buf_pos;
    225220  source = srcbuf;
    226  
     221
    227222  chars_read = fread((void *)srcbuf, 1, BUFFER_SIZE + OVERLAP_BUFSIZE, infile);
    228   chars_avail = min(chars_read,BUFFER_SIZE); 
    229    
     223  chars_avail = min(chars_read,BUFFER_SIZE);
     224
    230225  tag_matcher t(srcbuf);
    231  
     226
    232227  if(chars_read<4){
    233228    fprintf(stderr,"File is too short. Not well formed.\n");
     
    239234
    240235  if (e->code_unit_base == ASCII) {
    241                        
     236
    242237    XML_Decl_Parser<ASCII> decl_parser((unsigned char *)srcbuf);
    243238
    244     decl_parser.ReadXMLInfo(*e); 
    245    
     239    decl_parser.ReadXMLInfo(*e);
     240
    246241    if (e->code_unit_size != SingleByte || (e->has_encoding_decl && (!at_UTF_8(e->encoding)))){
    247242        fprintf(stderr,"Sorry, this xmlwf demo only works for UTF-8.\n");
     
    253248        exit(-1);
    254249  }
    255  
     250
    256251  if (e->content_start != 0) {
    257252        memmove(&srcbuf[0], &srcbuf[e->content_start], chars_read - e->content_start);
    258253        buf_pos = e->content_start;
    259254        if (chars_avail == BUFFER_SIZE) {
    260                 chars_read = chars_read - e->content_start + 
     255                chars_read = chars_read - e->content_start +
    261256                             fread(&srcbuf[chars_read-e->content_start], 1, e->content_start, infile);
    262257                chars_avail = min(chars_read,BUFFER_SIZE);
     
    267262        }
    268263  }
    269  
    270   @stream_stmts
     264
     265@stream_stmts
    271266
    272267  while(1){
     
    277272
    278273    if(chars_avail < BUFFER_SIZE){
    279      
     274
    280275      while (block_pos <= chars_avail){
    281276
    282         int bytes = chars_avail - block_pos;   
     277        int bytes = chars_avail - block_pos;
    283278        block_base = block_pos;
    284          
     279
    285280        if(bytes < BLOCK_SIZE){
     281          masks.EOF_mask = sisd_srl(simd_const_1(1),sisd_from_int(BLOCK_SIZE-bytes));
    286282          EOF_mask = sisd_srl(simd_const_1(1),sisd_from_int(BLOCK_SIZE-bytes));
    287283        }
    288284        BytePack * U8 = (BytePack *) &srcbuf[block_pos];
    289        
     285
    290286        s2p(U8[0], U8[1], U8[2], U8[3], U8[4], U8[5], U8[6], U8[7],
    291         bit[0], bit[1], bit[2], bit[3], bit[4], bit[5], bit[6], bit[7]);
    292 
    293         bit[0] = simd_and(bit[0], EOF_mask);
    294         bit[1] = simd_and(bit[1], EOF_mask);
    295         bit[2] = simd_and(bit[2], EOF_mask);
    296         bit[3] = simd_and(bit[3], EOF_mask);
    297         bit[4] = simd_and(bit[4], EOF_mask);
    298         bit[5] = simd_and(bit[5], EOF_mask);
    299         bit[6] = simd_and(bit[6], EOF_mask);
    300         bit[7] = simd_and(bit[7], EOF_mask);
     287        basis_bits.bit_0, basis_bits.bit_1, basis_bits.bit_2, basis_bits.bit_3, basis_bits.bit_4, basis_bits.bit_5, basis_bits.bit_6, basis_bits.bit_7);
     288
     289        basis_bits.bit_0 = simd_and(basis_bits.bit_0, masks.EOF_mask);
     290        basis_bits.bit_1 = simd_and(basis_bits.bit_1, masks.EOF_mask);
     291        basis_bits.bit_2 = simd_and(basis_bits.bit_2, masks.EOF_mask);
     292        basis_bits.bit_3 = simd_and(basis_bits.bit_3, masks.EOF_mask);
     293        basis_bits.bit_4 = simd_and(basis_bits.bit_4, masks.EOF_mask);
     294        basis_bits.bit_5 = simd_and(basis_bits.bit_5, masks.EOF_mask);
     295        basis_bits.bit_6 = simd_and(basis_bits.bit_6, masks.EOF_mask);
     296        basis_bits.bit_7 = simd_and(basis_bits.bit_7, masks.EOF_mask);
    301297
    302298        @block_stmts
    303                
    304         tracker.StoreNewlines(lex.LF); 
    305 
    306         if (bitblock_has_bit(simd_or(name_check,name_start_check))) {
    307           StreamScan((ScanBlock *) &name_start_check, sizeof(BitBlock)/sizeof(ScanBlock), NameStrt_check);
    308           StreamScan((ScanBlock *) &name_check, sizeof(BitBlock)/sizeof(ScanBlock), Name_check);
    309         }
    310          
     299
     300        tracker.StoreNewlines(lex.LF);
     301
     302        if (bitblock_has_bit(simd_or(post_process.non_ascii_name_starts, post_process.non_ascii_names))) {
     303          StreamScan((ScanBlock *) &post_process.non_ascii_name_starts, sizeof(BitBlock)/sizeof(ScanBlock), NameStrt_check);
     304          StreamScan((ScanBlock *) &post_process.non_ascii_names, sizeof(BitBlock)/sizeof(ScanBlock), Name_check);
     305        }
     306
    311307        if (bitblock_has_bit(ctCDPI_Callouts.PI_name_starts)){
    312308          StreamScan((ScanBlock *) &ctCDPI_Callouts.PI_name_starts, sizeof(BitBlock)/sizeof(ScanBlock), PIName_check);
    313309        }
    314        
     310
    315311        if (bitblock_has_bit(ctCDPI_Callouts.CD_starts)){
    316312          StreamScan((ScanBlock *) &ctCDPI_Callouts.CD_starts, sizeof(BitBlock)/sizeof(ScanBlock), CD_check);
    317313        }
    318        
     314
    319315        if (bitblock_has_bit(ref_Callouts.GenRef_starts)){
    320316          StreamScan((ScanBlock *) &ref_Callouts.GenRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), GenRef_check);
    321317        }
    322        
     318
    323319        if (bitblock_has_bit(ref_Callouts.DecRef_starts)){
    324320          StreamScan((ScanBlock *) &ref_Callouts.DecRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), DecRef_check);
    325321        }
    326        
     322
    327323        if (bitblock_has_bit(ref_Callouts.HexRef_starts)){
    328324          StreamScan((ScanBlock *) &ref_Callouts.HexRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), HexRef_check);
    329325        }
    330        
    331         if (bitblock_has_bit(AttRef)){
    332           StreamScan((ScanBlock *) &AttRef, sizeof(BitBlock)/sizeof(ScanBlock), AttRef_check);
    333         }
    334 
    335         if (bitblock_has_bit(error_mask)) {
    336           int errpos = count_forward_zeroes(error_mask);
     326
     327        if (bitblock_has_bit(post_process.att_refs)){
     328          StreamScan((ScanBlock *) &post_process.att_refs, sizeof(BitBlock)/sizeof(ScanBlock), AttRef_check);
     329        }
     330
     331        if (bitblock_has_bit(post_process.error_mask)) {
     332          int errpos = count_forward_zeroes(post_process.error_mask);
    337333          ReportError("error found", errpos);
    338           exit(-1);
    339         }
    340 
    341         t.store_streams(tag_marks, NameFollows, Misc_mask, chars_avail);
    342         tracker.AdvanceBlock(); 
     334      exit(-1);
     335        }
     336
     337        t.store_streams(post_process.tag_marks, post_process.name_follows, post_process.misc_mask, chars_avail);
     338        tracker.AdvanceBlock();
    343339        block_pos += BLOCK_SIZE;
    344340      }
     
    346342    else{
    347343      while (block_pos < chars_avail){
    348        
     344
    349345        block_base = block_pos;
    350          
     346
    351347        BytePack * U8 = (BytePack *) &srcbuf[block_pos];
    352        
     348
    353349        s2p(U8[0], U8[1], U8[2], U8[3], U8[4], U8[5], U8[6], U8[7],
    354         bit[0], bit[1], bit[2], bit[3], bit[4], bit[5], bit[6], bit[7]);
    355 
    356         @block_stmts   
    357        
    358         tracker.StoreNewlines(lex.LF); 
    359                
    360         if (bitblock_has_bit(simd_or(name_check,name_start_check))) {
    361           StreamScan((ScanBlock *) &name_start_check, sizeof(BitBlock)/sizeof(ScanBlock), NameStrt_check);
    362           StreamScan((ScanBlock *) &name_check, sizeof(BitBlock)/sizeof(ScanBlock), Name_check);
    363         }
    364        
     350        basis_bits.bit_0, basis_bits.bit_1, basis_bits.bit_2, basis_bits.bit_3, basis_bits.bit_4, basis_bits.bit_5, basis_bits.bit_6, basis_bits.bit_7);
     351
     352        @block_stmts
     353
     354        tracker.StoreNewlines(lex.LF);
     355
     356        if (bitblock_has_bit(simd_or(post_process.non_ascii_name_starts, post_process.non_ascii_names))) {
     357          StreamScan((ScanBlock *) &post_process.non_ascii_name_starts, sizeof(BitBlock)/sizeof(ScanBlock), NameStrt_check);
     358          StreamScan((ScanBlock *) &post_process.non_ascii_names, sizeof(BitBlock)/sizeof(ScanBlock), Name_check);
     359        }
     360
    365361        if (bitblock_has_bit(ctCDPI_Callouts.PI_name_starts)){
    366362          StreamScan((ScanBlock *) &ctCDPI_Callouts.PI_name_starts, sizeof(BitBlock)/sizeof(ScanBlock), PIName_check);
    367363        }
    368        
     364
    369365        if (bitblock_has_bit(ctCDPI_Callouts.CD_starts)){
    370366          StreamScan((ScanBlock *) &ctCDPI_Callouts.CD_starts, sizeof(BitBlock)/sizeof(ScanBlock), CD_check);
    371367        }
    372        
     368
    373369        if (bitblock_has_bit(ref_Callouts.GenRef_starts)){
    374370          StreamScan((ScanBlock *) &ref_Callouts.GenRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), GenRef_check);
    375371        }
    376        
     372
    377373        if (bitblock_has_bit(ref_Callouts.DecRef_starts)){
    378374          StreamScan((ScanBlock *) &ref_Callouts.DecRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), DecRef_check);
    379375        }
    380        
     376
    381377        if (bitblock_has_bit(ref_Callouts.HexRef_starts)){
    382378          StreamScan((ScanBlock *) &ref_Callouts.HexRef_starts, sizeof(BitBlock)/sizeof(ScanBlock), HexRef_check);
    383379        }
    384        
    385         if (bitblock_has_bit(AttRef)){
    386           StreamScan((ScanBlock *) &AttRef, sizeof(BitBlock)/sizeof(ScanBlock), AttRef_check);
    387         }
    388        
    389         if (bitblock_has_bit(error_mask)) {
    390           int errpos = count_forward_zeroes(error_mask);
     380
     381        if (bitblock_has_bit(post_process.att_refs)){
     382          StreamScan((ScanBlock *) &post_process.att_refs, sizeof(BitBlock)/sizeof(ScanBlock), AttRef_check);
     383        }
     384
     385        if (bitblock_has_bit(post_process.error_mask)) {
     386          int errpos = count_forward_zeroes(post_process.error_mask);
    391387          ReportError("error found", errpos);
    392           exit(-1);
    393         }
    394 
    395         t.store_streams(tag_marks, NameFollows, Misc_mask, chars_avail);
     388      exit(-1);
     389        }
     390
     391        t.store_streams(post_process.tag_marks, post_process.name_follows, post_process.misc_mask, chars_avail);
    396392        tracker.AdvanceBlock();
    397393        block_pos += BLOCK_SIZE;
     
    416412    }
    417413    else
    418       break;   
     414      break;
    419415  }
    420416  if(t.depth!=0){
    421417    fprintf(stderr, "tag matching error (depth %i) at position %i\n", t.depth, buffer_base);
    422418    exit(-1);
    423   }       
    424    
     419  }
     420
    425421}
    426422
     
    429425int
    430426main(int argc, char * argv[]) {
    431         char * infilename, * outfilename;       
     427        char * infilename, * outfilename;
    432428        FILE *infile, *outfile;
    433429        struct stat fileinfo;
     
    445441                exit(-1);
    446442        }
    447        
     443
    448444        if (argc < 3) outfile = stdout;
    449445        else {
     
    461457
    462458        do_process(infile, outfile);
    463        
     459
    464460        PERF_SEC_DUMP(parser_timer);
    465        
     461
    466462        PERF_SEC_DESTROY(parser_timer);
    467463
Note: See TracChangeset for help on using the changeset viewer.