| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <errno.h> |
|---|
| 4 | #include <sys/types.h> |
|---|
| 5 | #include <sys/stat.h> |
|---|
| 6 | |
|---|
| 7 | #define LocalCarryDeclare(name, count)\ |
|---|
| 8 | CarryArray<count> name;\ |
|---|
| 9 | |
|---|
| 10 | #include "../lib/bitblock.hpp" |
|---|
| 11 | #include "../lib/carryQ.hpp" |
|---|
| 12 | #include "../lib/bitstream_iterator.hpp" |
|---|
| 13 | #include "../lib/bitblock_iterator.hpp" |
|---|
| 14 | #include "../lib/s2p.hpp" |
|---|
| 15 | |
|---|
| 16 | #define SEGMENT_BLOCKS 12 |
|---|
| 17 | #define BUFFER_SIZE (BLOCK_SIZE * SEGMENT_BLOCKS) |
|---|
| 18 | #define OVERLAP_BUFSIZE (sizeof(BitBlock)) |
|---|
| 19 | |
|---|
| 20 | #include "xmldecl.h" |
|---|
| 21 | #include "namechars.h" |
|---|
| 22 | #include "../lib/perflib/perfsec.h" |
|---|
| 23 | |
|---|
| 24 | #include "TagMatcher.hpp" |
|---|
| 25 | #include "LineColTracker.hpp" |
|---|
| 26 | #include "ErrorUtil.h" |
|---|
| 27 | #include "ErrorTracker.h" |
|---|
| 28 | #include "XMLTestSuiteError.h" |
|---|
| 29 | |
|---|
| 30 | #ifdef BUFFER_PROFILING |
|---|
| 31 | BOM_Table * parser_timer; |
|---|
| 32 | |
|---|
| 33 | #elif CODE_CLOCKER |
|---|
| 34 | #define NUM_EVENTS 1 |
|---|
| 35 | int Events[NUM_EVENTS] = {PAPI_TOT_CYC}; |
|---|
| 36 | //int Events[NUM_EVENTS] = {PAPI_L2_DCM}; |
|---|
| 37 | //int Events[NUM_EVENTS] = {PAPI_TOT_CYC, PAPI_BR_MSP}; |
|---|
| 38 | int cal_size = 20; |
|---|
| 39 | CC * parser_timer = new CC(Events,NUM_EVENTS,cal_size); |
|---|
| 40 | #else |
|---|
| 41 | void * parser_timer; |
|---|
| 42 | #endif |
|---|
| 43 | |
|---|
| 44 | int block_base=0; |
|---|
| 45 | int buffer_base=0; |
|---|
| 46 | char * source; |
|---|
| 47 | |
|---|
| 48 | LineColTracker tracker; |
|---|
| 49 | TagMatcher matcher; |
|---|
| 50 | ErrorTracker error_tracker; |
|---|
| 51 | BitBlock EOF_mask = simd<1>::constant<1>(); |
|---|
| 52 | |
|---|
| 53 | static inline int NameStrt_check(int pos); |
|---|
| 54 | static inline int Name_check(int pos); |
|---|
| 55 | static inline int PIName_check(int pos); |
|---|
| 56 | static inline int CD_check(int pos); |
|---|
| 57 | static inline int GenRef_check(int pos); |
|---|
| 58 | static inline int HexRef_check(int pos); |
|---|
| 59 | static inline int DecRef_check(int pos); |
|---|
| 60 | static inline int AttRef_check(int pos); |
|---|
| 61 | |
|---|
| 62 | @global |
|---|
| 63 | |
|---|
| 64 | static inline void s2p_do_block(BytePack U8[], Basis_bits & basis_bits); |
|---|
| 65 | static inline void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, BitBlock EOF_mask); |
|---|
| 66 | static inline void postprocess_do_block(Lex & lex, CtCDPI_Callouts & ctCDPI_Callouts, Ref_Callouts & ref_Callouts, Check_streams & check_streams, int chars_avail); |
|---|
| 67 | |
|---|
| 68 | void do_process(FILE *infile, FILE *outfile); |
|---|
| 69 | |
|---|
| 70 | static inline void validate_block(BitBlockForwardIterator & start, int block_base, int is_valid(int)); |
|---|
| 71 | static inline void validate_block(BitBlockForwardIterator & start, int block_base, int is_valid(int,int)); |
|---|
| 72 | |
|---|
| 73 | int main(int argc, char * argv[]) { |
|---|
| 74 | |
|---|
| 75 | char * infilename, * outfilename; |
|---|
| 76 | FILE *infile, *outfile; |
|---|
| 77 | struct stat fileinfo; |
|---|
| 78 | |
|---|
| 79 | if (argc < 2) { |
|---|
| 80 | printf("Usage: %s <filename> [<outputfile>]\n", argv[0]); |
|---|
| 81 | exit(-1); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | infilename = argv[1]; |
|---|
| 85 | stat(infilename, &fileinfo); |
|---|
| 86 | infile = fopen(infilename, "rb"); |
|---|
| 87 | if (!infile) { |
|---|
| 88 | fprintf(stderr, "Error: cannot open %s for input.\n", infilename); |
|---|
| 89 | exit(-1); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | if (argc < 3) outfile = stdout; |
|---|
| 93 | else { |
|---|
| 94 | outfilename = argv[2]; |
|---|
| 95 | outfile = fopen(outfilename, "wb"); |
|---|
| 96 | if (!outfile) { |
|---|
| 97 | fprintf(stderr, "Error: cannot open %s for writing.\n", outfilename); |
|---|
| 98 | exit(-1); |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | // PERF_SEC_BIND(1); |
|---|
| 103 | |
|---|
| 104 | PERF_SEC_INIT(parser_timer); |
|---|
| 105 | |
|---|
| 106 | do_process(infile, outfile); |
|---|
| 107 | |
|---|
| 108 | PERF_SEC_DUMP(parser_timer); |
|---|
| 109 | |
|---|
| 110 | PERF_SEC_DESTROY(parser_timer); |
|---|
| 111 | |
|---|
| 112 | fclose(infile); |
|---|
| 113 | fclose(outfile); |
|---|
| 114 | |
|---|
| 115 | return(0); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | /* s2p Definitions */ |
|---|
| 119 | static inline void s2p_do_block(BytePack U8[], Basis_bits & basis_bits) { |
|---|
| 120 | s2p(U8[0], U8[1], U8[2], U8[3], U8[4], U8[5], U8[6], U8[7], |
|---|
| 121 | 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); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | static inline void s2p_do_final_block(BytePack U8[], Basis_bits & basis_bits, BitBlock EOF_mask) { |
|---|
| 125 | s2p_do_block(U8, basis_bits); |
|---|
| 126 | basis_bits.bit_0 = simd_and(basis_bits.bit_0, EOF_mask); |
|---|
| 127 | basis_bits.bit_1 = simd_and(basis_bits.bit_1, EOF_mask); |
|---|
| 128 | basis_bits.bit_2 = simd_and(basis_bits.bit_2, EOF_mask); |
|---|
| 129 | basis_bits.bit_3 = simd_and(basis_bits.bit_3, EOF_mask); |
|---|
| 130 | basis_bits.bit_4 = simd_and(basis_bits.bit_4, EOF_mask); |
|---|
| 131 | basis_bits.bit_5 = simd_and(basis_bits.bit_5, EOF_mask); |
|---|
| 132 | basis_bits.bit_6 = simd_and(basis_bits.bit_6, EOF_mask); |
|---|
| 133 | basis_bits.bit_7 = simd_and(basis_bits.bit_7, EOF_mask); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | static inline int NameStrt_check(int pos) { |
|---|
| 138 | if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&source[pos]) == 0){ |
|---|
| 139 | return XMLTestSuiteError::NAME_START; |
|---|
| 140 | } |
|---|
| 141 | return 0; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | static inline int Name_check(int pos) { |
|---|
| 145 | if(XML_10_UTF8_NameChar_bytes((unsigned char*)&source[pos]) == 0){ |
|---|
| 146 | return XMLTestSuiteError::NAME; |
|---|
| 147 | } |
|---|
| 148 | return 0; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | static inline int PIName_check(int pos, int file_pos) { |
|---|
| 152 | if (at_XxMmLll<ASCII>((unsigned char*)&source[pos]) && (source[pos+3]=='?' || source[pos+3]<= ' ')) { |
|---|
| 153 | // "<?xml" legal at start of file. |
|---|
| 154 | if (!((file_pos == 2) && at_XmlDecl_start<ASCII>((unsigned char*)&source[0]))) { |
|---|
| 155 | return XMLTestSuiteError::XMLPINAME; |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | return 0; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | static inline int CD_check(int pos) { |
|---|
| 162 | if (!at_CDATA1<ASCII>((unsigned char*)&source[pos])){ |
|---|
| 163 | return XMLTestSuiteError::CDATA; |
|---|
| 164 | } |
|---|
| 165 | return 0; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | static inline int GenRef_check(int pos) { |
|---|
| 169 | unsigned char* s = (unsigned char*)&source[pos]; |
|---|
| 170 | if (!(at_Ref_gt<ASCII>(s)||at_Ref_lt<ASCII>(s)||at_Ref_amp<ASCII>(s)||at_Ref_quot<ASCII>(s)||at_Ref_apos<ASCII>(s))){ |
|---|
| 171 | return XMLTestSuiteError::UNDEFREF; |
|---|
| 172 | } |
|---|
| 173 | return 0; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | static inline int HexRef_check(int pos) { |
|---|
| 177 | unsigned char* s = (unsigned char*)&source[pos]; |
|---|
| 178 | int ch_val = 0; |
|---|
| 179 | while(at_HexDigit<ASCII>(s)){ |
|---|
| 180 | ch_val = HexVal<ASCII>(s[0]) + (ch_val<<4); |
|---|
| 181 | if (ch_val> 0x10FFFF ){ |
|---|
| 182 | return XMLTestSuiteError::CHARREF; |
|---|
| 183 | } |
|---|
| 184 | s++; |
|---|
| 185 | } |
|---|
| 186 | if ((ch_val == 0x0) || ((ch_val | 0x7FF) == 0xDFFF)|| ((ch_val | 0x1) == 0xFFFF)){ |
|---|
| 187 | return XMLTestSuiteError::CHARREF; |
|---|
| 188 | } |
|---|
| 189 | else if (((ch_val < 0x20) && (ch_val != 0x9) && (ch_val != 0xD) && (ch_val != 0xA))){ |
|---|
| 190 | return XMLTestSuiteError::XML10CHARREF; |
|---|
| 191 | } |
|---|
| 192 | return 0; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | static inline int DecRef_check(int pos) { |
|---|
| 196 | unsigned char* s = (unsigned char*)&source[pos]; |
|---|
| 197 | int ch_val = 0; |
|---|
| 198 | while(at_HexDigit<ASCII>(s)){ |
|---|
| 199 | ch_val = DigitVal<ASCII>(s[0]) + ch_val*10; |
|---|
| 200 | if (ch_val> 0x10FFFF ){ |
|---|
| 201 | return XMLTestSuiteError::CHARREF; |
|---|
| 202 | } |
|---|
| 203 | s++; |
|---|
| 204 | } |
|---|
| 205 | if ((ch_val == 0x0) || ((ch_val | 0x7FF) == 0xDFFF)|| ((ch_val | 0x1) == 0xFFFF)){ |
|---|
| 206 | return XMLTestSuiteError::CHARREF; |
|---|
| 207 | } |
|---|
| 208 | else if (((ch_val < 0x20) && (ch_val != 0x9) && (ch_val != 0xD) && (ch_val != 0xA))){ |
|---|
| 209 | return XMLTestSuiteError::XML10CHARREF; |
|---|
| 210 | } |
|---|
| 211 | return 0; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | static inline int AttRef_check(int pos) { |
|---|
| 215 | unsigned char* s = (unsigned char*)&source[pos]; |
|---|
| 216 | int ch_val = 0; |
|---|
| 217 | if(s[0]=='#'){ |
|---|
| 218 | s++; |
|---|
| 219 | if(s[0]=='x' || s[0]=='X'){ |
|---|
| 220 | s++; |
|---|
| 221 | while(at_HexDigit<ASCII>(s)){ |
|---|
| 222 | ch_val = HexVal<ASCII>(s[0]) + (ch_val<<4); |
|---|
| 223 | s++; |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | else{ |
|---|
| 227 | while(at_HexDigit<ASCII>(s)){ |
|---|
| 228 | ch_val = DigitVal<ASCII>(s[0]) + ch_val*10; |
|---|
| 229 | s++; |
|---|
| 230 | } |
|---|
| 231 | } |
|---|
| 232 | if (ch_val==60){ |
|---|
| 233 | return XMLTestSuiteError::ATTREF; |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | else if(at_Ref_lt<ASCII>(s)){ |
|---|
| 237 | return XMLTestSuiteError::ATTREF; |
|---|
| 238 | } |
|---|
| 239 | return 0; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | static inline void validate_block(BitBlockForwardIterator & start, int block_base, int is_valid(int)) { |
|---|
| 243 | |
|---|
| 244 | int pos, block_pos; |
|---|
| 245 | BitBlockForwardIterator end; |
|---|
| 246 | while(start != end) { |
|---|
| 247 | |
|---|
| 248 | block_pos = block_base + *start; |
|---|
| 249 | int rv = is_valid(block_pos); |
|---|
| 250 | |
|---|
| 251 | if (rv) { |
|---|
| 252 | int error_line, error_column; |
|---|
| 253 | tracker.get_Line_and_Column(block_pos, error_line, error_column); |
|---|
| 254 | ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column); |
|---|
| 255 | exit(-1); |
|---|
| 256 | } |
|---|
| 257 | start++; |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | static inline void validate_block(BitBlockForwardIterator & start, int block_base, int buffer_base, int is_valid(int,int)) { |
|---|
| 262 | |
|---|
| 263 | int pos, block_pos, file_pos; |
|---|
| 264 | BitBlockForwardIterator end; |
|---|
| 265 | while(start != end) { |
|---|
| 266 | |
|---|
| 267 | block_pos = block_base + *start; |
|---|
| 268 | file_pos = block_pos+buffer_base; |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | int rv = is_valid(block_pos, file_pos); |
|---|
| 272 | |
|---|
| 273 | if (rv) { |
|---|
| 274 | int error_line, error_column; |
|---|
| 275 | tracker.get_Line_and_Column(block_pos, error_line, error_column); |
|---|
| 276 | ReportError(XMLTestSuiteError::get_msg(rv), error_line, error_column); |
|---|
| 277 | exit(-1); |
|---|
| 278 | } |
|---|
| 279 | start++; |
|---|
| 280 | } |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | static inline void postprocess_do_block(Lex & lex, CtCDPI_Callouts & ctCDPI_Callouts, Ref_Callouts & ref_Callouts, Check_streams & check_streams, int chars_avail){ |
|---|
| 284 | BitBlockForwardIterator iter; |
|---|
| 285 | |
|---|
| 286 | tracker.StoreNewlines(lex.LF); |
|---|
| 287 | |
|---|
| 288 | if (bitblock_has_bit(simd_or(check_streams.non_ascii_name_starts, check_streams.non_ascii_names))) { |
|---|
| 289 | iter.init(&check_streams.non_ascii_name_starts); |
|---|
| 290 | validate_block(iter, block_base, NameStrt_check); |
|---|
| 291 | iter.init(&check_streams.non_ascii_names); |
|---|
| 292 | validate_block(iter, block_base, Name_check); |
|---|
| 293 | } |
|---|
| 294 | if (bitblock_has_bit(ctCDPI_Callouts.PI_name_starts)){ |
|---|
| 295 | iter.init(&(ctCDPI_Callouts.PI_name_starts)); |
|---|
| 296 | validate_block(iter, block_base, buffer_base, PIName_check); |
|---|
| 297 | } |
|---|
| 298 | if (bitblock_has_bit(ctCDPI_Callouts.CD_starts)){ |
|---|
| 299 | iter.init(&ctCDPI_Callouts.CD_starts); |
|---|
| 300 | validate_block(iter, block_base, CD_check); |
|---|
| 301 | } |
|---|
| 302 | if(bitblock_has_bit(ref_Callouts.GenRef_starts)){ |
|---|
| 303 | iter.init(&ref_Callouts.GenRef_starts); |
|---|
| 304 | validate_block(iter, block_base, GenRef_check); |
|---|
| 305 | } |
|---|
| 306 | if(bitblock_has_bit(ref_Callouts.DecRef_starts)){ |
|---|
| 307 | iter.init(&ref_Callouts.DecRef_starts); |
|---|
| 308 | validate_block(iter, block_base, DecRef_check); |
|---|
| 309 | } |
|---|
| 310 | if(bitblock_has_bit(ref_Callouts.HexRef_starts)){ |
|---|
| 311 | iter.init(&ref_Callouts.HexRef_starts); |
|---|
| 312 | validate_block(iter, block_base, HexRef_check); |
|---|
| 313 | } |
|---|
| 314 | if(bitblock_has_bit(check_streams.att_refs)){ |
|---|
| 315 | iter.init(&check_streams.att_refs); |
|---|
| 316 | validate_block(iter, block_base, AttRef_check); |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | if(error_tracker.Has_Noted_Error()){ |
|---|
| 320 | int error_line, error_column; |
|---|
| 321 | tracker.get_Line_and_Column(error_tracker.Noted_Pos_In_Block(), error_line, error_column); |
|---|
| 322 | ReportError(error_tracker.Noted_Error_Msg(), error_line, error_column); |
|---|
| 323 | exit(-1); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | matcher.store_streams(check_streams.tag_marks, check_streams.name_follows, check_streams.misc_mask, chars_avail); |
|---|
| 327 | tracker.AdvanceBlock(); |
|---|
| 328 | |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | void do_process(FILE *infile, FILE *outfile) { |
|---|
| 332 | |
|---|
| 333 | @decl |
|---|
| 334 | |
|---|
| 335 | int buf_pos = 0; |
|---|
| 336 | int block_pos = 0; |
|---|
| 337 | int chars_avail = 0; |
|---|
| 338 | int check_pos = 0; |
|---|
| 339 | int chars_read = 0; |
|---|
| 340 | BytePack buf[(BUFFER_SIZE+BLOCK_SIZE+OVERLAP_BUFSIZE*2)/sizeof(BitBlock)]; |
|---|
| 341 | |
|---|
| 342 | char * srcbuf = ((char *) buf) + OVERLAP_BUFSIZE; |
|---|
| 343 | buffer_base = buf_pos; |
|---|
| 344 | source = srcbuf; |
|---|
| 345 | |
|---|
| 346 | chars_read = fread((void *)srcbuf, 1, BUFFER_SIZE + OVERLAP_BUFSIZE, infile); |
|---|
| 347 | chars_avail = chars_read; |
|---|
| 348 | if (chars_avail > BUFFER_SIZE) chars_avail = BUFFER_SIZE; |
|---|
| 349 | |
|---|
| 350 | matcher.setSrc(srcbuf); |
|---|
| 351 | |
|---|
| 352 | if(chars_read<4){ |
|---|
| 353 | fprintf(stderr,"File is too short. Not well formed.\n"); |
|---|
| 354 | exit(-1); |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | Entity_Info * e = new Entity_Info; |
|---|
| 358 | e->AnalyzeSignature((unsigned char *)srcbuf); |
|---|
| 359 | |
|---|
| 360 | if (e->code_unit_base == ASCII) { |
|---|
| 361 | |
|---|
| 362 | XML_Decl_Parser<ASCII> decl_parser((unsigned char *)srcbuf); |
|---|
| 363 | |
|---|
| 364 | decl_parser.ReadXMLInfo(*e); |
|---|
| 365 | |
|---|
| 366 | if (e->code_unit_size != SingleByte || (e->has_encoding_decl && (!at_UTF_8(e->encoding)))){ |
|---|
| 367 | fprintf(stderr,"Sorry, this xmlwf demo only works for UTF-8.\n"); |
|---|
| 368 | exit(-1); |
|---|
| 369 | } |
|---|
| 370 | } |
|---|
| 371 | else { |
|---|
| 372 | fprintf(stderr,"Sorry, this xmlwf demo does not process EBCDIC.\n"); |
|---|
| 373 | exit(-1); |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | if (e->content_start != 0) { |
|---|
| 377 | memmove(&srcbuf[0], &srcbuf[e->content_start], chars_read - e->content_start); |
|---|
| 378 | buf_pos = e->content_start; |
|---|
| 379 | if (chars_avail == BUFFER_SIZE) { |
|---|
| 380 | chars_read = chars_read - e->content_start + |
|---|
| 381 | fread(&srcbuf[chars_read-e->content_start], 1, e->content_start, infile); |
|---|
| 382 | chars_avail = chars_read; |
|---|
| 383 | if (chars_avail > BUFFER_SIZE) chars_avail = BUFFER_SIZE; |
|---|
| 384 | } |
|---|
| 385 | else { |
|---|
| 386 | chars_read -=e->content_start; |
|---|
| 387 | chars_avail -=e->content_start; |
|---|
| 388 | } |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | @stream_stmts |
|---|
| 392 | |
|---|
| 393 | /* Full Buffers */ |
|---|
| 394 | |
|---|
| 395 | while (chars_avail == BUFFER_SIZE) { |
|---|
| 396 | PERF_SEC_START(parser_timer); |
|---|
| 397 | for (int blk = 0; blk < SEGMENT_BLOCKS; blk++) { |
|---|
| 398 | block_base = blk*BLOCK_SIZE; |
|---|
| 399 | s2p_do_block((BytePack *) &srcbuf[block_base], basis_bits); |
|---|
| 400 | @block_stmts |
|---|
| 401 | postprocess_do_block(lex, ctCDPI_Callouts, ref_Callouts, check_streams, chars_avail); |
|---|
| 402 | } |
|---|
| 403 | matcher.StreamScan(chars_avail); |
|---|
| 404 | matcher.Advance_buffer(); |
|---|
| 405 | tracker.Advance_buffer(); |
|---|
| 406 | PERF_SEC_END(parser_timer, chars_avail); |
|---|
| 407 | |
|---|
| 408 | int bytes_left = chars_read - chars_avail; |
|---|
| 409 | memmove(srcbuf, &srcbuf[BUFFER_SIZE], bytes_left); |
|---|
| 410 | chars_read = fread(&srcbuf[bytes_left],1, BUFFER_SIZE + OVERLAP_BUFSIZE - bytes_left, infile) + bytes_left; |
|---|
| 411 | chars_avail = chars_read; |
|---|
| 412 | if (chars_avail > BUFFER_SIZE) chars_avail = BUFFER_SIZE; |
|---|
| 413 | buf_pos += chars_avail; |
|---|
| 414 | buffer_base = buf_pos; |
|---|
| 415 | } |
|---|
| 416 | /* Final Partial Buffer */ |
|---|
| 417 | PERF_SEC_START(parser_timer); |
|---|
| 418 | |
|---|
| 419 | block_pos = 0; |
|---|
| 420 | int remaining = chars_avail; |
|---|
| 421 | /* Full Blocks */ |
|---|
| 422 | while (remaining >= BLOCK_SIZE) { |
|---|
| 423 | block_base = block_pos; |
|---|
| 424 | s2p_do_block((BytePack *) &srcbuf[block_pos], basis_bits); |
|---|
| 425 | @block_stmts |
|---|
| 426 | postprocess_do_block(lex, ctCDPI_Callouts, ref_Callouts, check_streams, chars_avail); |
|---|
| 427 | block_pos += BLOCK_SIZE; |
|---|
| 428 | remaining -= BLOCK_SIZE; |
|---|
| 429 | } |
|---|
| 430 | block_base = block_pos; |
|---|
| 431 | if (remaining > 0 || @any_carry) { |
|---|
| 432 | EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE-remaining)); |
|---|
| 433 | s2p_do_final_block((BytePack *) &srcbuf[block_pos], basis_bits, EOF_mask); |
|---|
| 434 | @final_block_stmts |
|---|
| 435 | postprocess_do_block(lex, ctCDPI_Callouts, ref_Callouts, check_streams, chars_avail); |
|---|
| 436 | } |
|---|
| 437 | buf_pos += chars_avail; |
|---|
| 438 | buffer_base = buf_pos; |
|---|
| 439 | |
|---|
| 440 | matcher.StreamScan(chars_avail); |
|---|
| 441 | matcher.Advance_buffer(); |
|---|
| 442 | tracker.Advance_buffer(); |
|---|
| 443 | |
|---|
| 444 | |
|---|
| 445 | PERF_SEC_END(parser_timer, chars_avail); |
|---|
| 446 | if (matcher.depth != 0) { |
|---|
| 447 | fprintf(stderr, "tag matching error (depth %i) at position %i\n", matcher.depth, buffer_base); |
|---|
| 448 | exit(-1); |
|---|
| 449 | } |
|---|
| 450 | } |
|---|
| 451 | |
|---|