Changeset 4357
- Timestamp:
- Dec 24, 2014, 12:59:05 PM (4 years ago)
- Location:
- icGREP/icgrep-devel/icgrep
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp
r4337 r4357 49 49 50 50 pablo::Var * CC_Compiler::compileCC(const re::CC *cc) { 51 return mCG.createVar(mCG.createAssign(cc->canonicalName(ByteClass), charset_expr(cc))); 51 return compileCC(cc, mCG); 52 } 53 54 pablo::Var * CC_Compiler::compileCC(const re::CC *cc, pablo::PabloBlock & pb) { 55 return pb.createVar(pb.createAssign(cc->canonicalName(ByteClass), charset_expr(cc, pb))); 52 56 } 53 57 … … 84 88 } 85 89 else if (d && isa<CC>(d)) { 86 name->setCompiled(compileCC(cast<CC>(d) ));90 name->setCompiled(compileCC(cast<CC>(d), mCG)); 87 91 } 88 92 } … … 95 99 96 100 97 PabloAST * CC_Compiler::charset_expr(const CC * cc ) {101 PabloAST * CC_Compiler::charset_expr(const CC * cc, pablo::PabloBlock & pb) { 98 102 if (cc->empty()) { 99 return mCG.createZeroes();103 return pb.createZeroes(); 100 104 } 101 105 if (cc->size() > 2) { … … 123 127 lo &= (mask - 1); 124 128 hi |= (mask ^ (mask - 1)); 125 PabloAST * expr = make_range(lo, hi );129 PabloAST * expr = make_range(lo, hi, pb); 126 130 PabloAST * bit0 = getBasisVar(0); 127 131 if ((lo & 1) == 0) { 128 bit0 = mCG.createNot(bit0);132 bit0 = pb.createNot(bit0); 129 133 } 130 return mCG.createAnd(expr, bit0);134 return pb.createAnd(expr, bit0); 131 135 } 132 136 } … … 134 138 PabloAST * expr = nullptr; 135 139 for (const CharSetItem & item : *cc) { 136 PabloAST * temp = char_or_range_expr(item.lo_codepoint, item.hi_codepoint );137 expr = (expr == nullptr) ? temp : mCG.createOr(expr, temp);140 PabloAST * temp = char_or_range_expr(item.lo_codepoint, item.hi_codepoint, pb); 141 expr = (expr == nullptr) ? temp : pb.createOr(expr, temp); 138 142 } 139 143 return expr; 140 144 } 141 145 142 PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits )146 PabloAST * CC_Compiler::bit_pattern_expr(const unsigned pattern, unsigned selected_bits, pablo::PabloBlock & pb) 143 147 { 144 148 if (selected_bits == 0) { 145 return mCG.createOnes();149 return pb.createOnes(); 146 150 } 147 151 … … 165 169 else 166 170 { 167 bit_terms.push_back( mCG.createOnes());171 bit_terms.push_back(pb.createOnes()); 168 172 } 169 173 selected_bits &= ~test_bit; … … 177 181 for (auto i = 0; i < (bit_terms.size()/2); i++) 178 182 { 179 new_terms.push_back( mCG.createAnd(bit_terms[(2 * i) + 1], bit_terms[2 * i]));183 new_terms.push_back(pb.createAnd(bit_terms[(2 * i) + 1], bit_terms[2 * i])); 180 184 } 181 185 if (bit_terms.size() % 2 == 1) … … 188 192 } 189 193 190 inline PabloAST * CC_Compiler::char_test_expr(const CodePointType ch )191 { 192 return bit_pattern_expr(ch, mEncoding.getMask() );193 } 194 195 PabloAST * CC_Compiler::make_range(const CodePointType n1, const CodePointType n2 )194 inline PabloAST * CC_Compiler::char_test_expr(const CodePointType ch, pablo::PabloBlock & pb) 195 { 196 return bit_pattern_expr(ch, mEncoding.getMask(), pb); 197 } 198 199 PabloAST * CC_Compiler::make_range(const CodePointType n1, const CodePointType n2, pablo::PabloBlock & pb) 196 200 { 197 201 CodePointType diff_count = 0; … … 206 210 const CodePointType mask0 = (static_cast<CodePointType>(1) << diff_count) - 1; 207 211 208 PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncoding.getMask() ^ mask0 );212 PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncoding.getMask() ^ mask0, pb); 209 213 210 214 if (diff_count == 0) return common; … … 212 216 const CodePointType mask1 = (static_cast<CodePointType>(1) << (diff_count - 1)) - 1; 213 217 214 PabloAST* lo_test = GE_Range(diff_count - 1, n1 & mask1 );215 PabloAST* hi_test = LE_Range(diff_count - 1, n2 & mask1 );216 217 return mCG.createAnd(common, mCG.createSel(getBasisVar(diff_count - 1), hi_test, lo_test));218 } 219 220 PabloAST * CC_Compiler::GE_Range(const unsigned N, const unsigned n ) {218 PabloAST* lo_test = GE_Range(diff_count - 1, n1 & mask1, pb); 219 PabloAST* hi_test = LE_Range(diff_count - 1, n2 & mask1, pb); 220 221 return pb.createAnd(common, pb.createSel(getBasisVar(diff_count - 1), hi_test, lo_test)); 222 } 223 224 PabloAST * CC_Compiler::GE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb) { 221 225 if (N == 0) { 222 return mCG.createOnes(); //Return a true literal.226 return pb.createOnes(); //Return a true literal. 223 227 } 224 228 else if (((N % 2) == 0) && ((n >> (N - 2)) == 0)) { 225 return mCG.createOr(mCG.createOr(getBasisVar(N - 1), getBasisVar(N - 2)), GE_Range(N - 2, n));229 return pb.createOr(pb.createOr(getBasisVar(N - 1), getBasisVar(N - 2)), GE_Range(N - 2, n, pb)); 226 230 } 227 231 else if (((N % 2) == 0) && ((n >> (N - 2)) == 3)) { 228 return mCG.createAnd(mCG.createAnd(getBasisVar(N - 1), getBasisVar(N - 2)), GE_Range(N - 2, n - (3 << (N - 2))));232 return pb.createAnd(pb.createAnd(getBasisVar(N - 1), getBasisVar(N - 2)), GE_Range(N - 2, n - (3 << (N - 2)), pb)); 229 233 } 230 234 else if (N >= 1) … … 232 236 int hi_bit = n & (1 << (N - 1)); 233 237 int lo_bits = n - hi_bit; 234 PabloAST * lo_range = GE_Range(N - 1, lo_bits );238 PabloAST * lo_range = GE_Range(N - 1, lo_bits, pb); 235 239 if (hi_bit == 0) 236 240 { … … 240 244 the value of GE_range(N-1), lo_range) is required. 241 245 */ 242 return mCG.createOr(getBasisVar(N - 1), lo_range);246 return pb.createOr(getBasisVar(N - 1), lo_range); 243 247 } 244 248 else … … 248 252 in the target for >= and GE_range(N-1, lo_bits) must also be true. 249 253 */ 250 return mCG.createAnd(getBasisVar(N - 1), lo_range);254 return pb.createAnd(getBasisVar(N - 1), lo_range); 251 255 } 252 256 } … … 254 258 } 255 259 256 PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n )260 PabloAST * CC_Compiler::LE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb) 257 261 { 258 262 /* … … 261 265 */ 262 266 if ((n + 1) == (1 << N)) { 263 return mCG.createOnes(); //True.267 return pb.createOnes(); //True. 264 268 } 265 269 else { 266 return mCG.createNot(GE_Range(N, n + 1));267 } 268 } 269 270 inline PabloAST * CC_Compiler::char_or_range_expr(const CodePointType lo, const CodePointType hi ) {270 return pb.createNot(GE_Range(N, n + 1, pb)); 271 } 272 } 273 274 inline PabloAST * CC_Compiler::char_or_range_expr(const CodePointType lo, const CodePointType hi, pablo::PabloBlock & pb) { 271 275 if (lo == hi) { 272 return char_test_expr(lo );276 return char_test_expr(lo, pb); 273 277 } 274 278 else if (lo < hi) { 275 return make_range(lo, hi );279 return make_range(lo, hi, pb); 276 280 } 277 281 throw std::runtime_error(std::string("Invalid Character Set Range: [") + std::to_string(lo) + "," + std::to_string(hi) + "]"); -
icGREP/icgrep-devel/icgrep/cc/cc_compiler.h
r4337 r4357 28 28 std::vector<pablo::Var *> getBasisBits(const CC_NameMap & nameMap); 29 29 30 pablo::Var * compileCC(const re::CC *cc, pablo::PabloBlock & pb); 31 30 32 pablo::Var * compileCC(const re::CC *cc); 31 33 … … 34 36 private: 35 37 pablo::Var * getBasisVar(const int n) const; 36 pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits );37 pablo::PabloAST * char_test_expr(const re::CodePointType ch );38 pablo::PabloAST * make_range(const re::CodePointType n1, const re::CodePointType n2 );39 pablo::PabloAST * GE_Range(const unsigned N, const unsigned n );40 pablo::PabloAST * LE_Range(const unsigned N, const unsigned n );41 pablo::PabloAST * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi );42 pablo::PabloAST * charset_expr(const re::CC *cc );38 pablo::PabloAST * bit_pattern_expr(const unsigned pattern, unsigned selected_bits, pablo::PabloBlock & pb); 39 pablo::PabloAST * char_test_expr(const re::CodePointType ch, pablo::PabloBlock & pb); 40 pablo::PabloAST * make_range(const re::CodePointType n1, const re::CodePointType n2, pablo::PabloBlock & pb); 41 pablo::PabloAST * GE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb); 42 pablo::PabloAST * LE_Range(const unsigned N, const unsigned n, pablo::PabloBlock & pb); 43 pablo::PabloAST * char_or_range_expr(const re::CodePointType lo, const re::CodePointType hi, pablo::PabloBlock & pb); 44 pablo::PabloAST * charset_expr(const re::CC *cc, pablo::PabloBlock & pb); 43 45 44 46 void computeVariableConstraints(); -
icGREP/icgrep-devel/icgrep/re/re_compiler.cpp
r4352 r4357 80 80 mLineFeed = mCG.createVar(LF); 81 81 PabloAST * CR = ccc.compileCC(makeCC(0x0D)); 82 PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D)); 82 83 #ifndef USE_IF_FOR_CRLF 83 84 mCRLF = mCG.createAnd(mCG.createAdvance(CR, 1), mLineFeed); … … 90 91 #endif 91 92 92 PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D)); 93 #ifndef USE_IF_FOR_NONFINAL 93 94 PabloAST * u8single = ccc.compileCC(makeCC(0x00, 0x7F)); 94 95 PabloAST * u8pfx2 = ccc.compileCC(makeCC(0xC2, 0xDF)); … … 97 98 PabloAST * u8pfx = mCG.createOr(mCG.createOr(u8pfx2, u8pfx3), u8pfx4); 98 99 mInitial = mCG.createVar(mCG.createAssign(initial, mCG.createOr(u8pfx, u8single))); 99 100 #ifndef USE_IF_FOR_NONFINAL 100 101 101 PabloAST * u8scope32 = mCG.createAdvance(u8pfx3, 1); 102 102 PabloAST * u8scope42 = mCG.createAdvance(u8pfx4, 1); … … 108 108 mNonFinal = mCG.createVar(mCG.createAssign(nonfinal, mCG.createOr(mCG.createOr(u8pfx, u8scope32), mCG.createOr(u8scope42, u8scope43)))); 109 109 mUnicodeLineBreak = mCG.createAnd(LB_chars, mCG.createNot(mCRLF)); // count the CR, but not CRLF 110 #endif 111 #ifdef USE_IF_FOR_NONFINAL 110 #endif 111 112 #ifdef USE_IF_FOR_NONFINAL 113 PabloAST * u8single = ccc.compileCC(makeCC(0x00, 0x7F)); 114 PabloAST * u8pfx = ccc.compileCC(makeCC(0xC0, 0xFF)); 112 115 PabloBlock it(mCG); 116 PabloAST * u8pfx2 = ccc.compileCC(makeCC(0xC2, 0xDF), it); 117 PabloAST * u8pfx3 = ccc.compileCC(makeCC(0xE0, 0xEF), it); 118 PabloAST * u8pfx4 = ccc.compileCC(makeCC(0xF0, 0xF4), it); 119 Assign * valid_pfx = it.createAssign("valid_pfx", it.createOr(it.createOr(u8pfx2, u8pfx3), u8pfx4)); 113 120 PabloAST * u8scope32 = it.createAdvance(u8pfx3, 1); 114 121 PabloAST * u8scope42 = it.createVar(it.createAssign("u8scope42", it.createAdvance(u8pfx4, 1))); 115 122 PabloAST * u8scope43 = it.createAdvance(u8scope42, 1); 116 Assign * a = it.createAssign(nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));117 PabloAST * NEL = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xC2) ), 1), ccc.compileCC(makeCC(0x85)));118 PabloAST * E2_80 = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xE2) ), 1), ccc.compileCC(makeCC(0x80)));119 PabloAST * LS_PS = it.createAnd(it.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9) ));123 Assign * a_nonfinal = it.createAssign(nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43))); 124 PabloAST * NEL = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xC2), it), 1), ccc.compileCC(makeCC(0x85), it)); 125 PabloAST * E2_80 = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xE2), it), 1), ccc.compileCC(makeCC(0x80), it)); 126 PabloAST * LS_PS = it.createAnd(it.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9), it)); 120 127 Assign * NEL_LS_PS = it.createAssign("NEL_LS_PS", it.createOr(NEL, LS_PS)); 121 mCG.createIf(u8pfx, std::move(std::vector<Assign *>{ a, NEL_LS_PS}), std::move(it));128 mCG.createIf(u8pfx, std::move(std::vector<Assign *>{valid_pfx, a_nonfinal, NEL_LS_PS}), std::move(it)); 122 129 PabloAST * LB_chars = mCG.createOr(LF_VT_FF_CR, mCG.createVar(NEL_LS_PS)); 123 mNonFinal = mCG.createVar(a); 130 mInitial = mCG.createVar(mCG.createAssign(initial, mCG.createOr(u8single, mCG.createVar(valid_pfx)))); 131 mNonFinal = mCG.createVar(a_nonfinal); 124 132 mUnicodeLineBreak = mCG.createAnd(LB_chars, mCG.createNot(mCRLF)); // count the CR, but not CRLF 125 133 #endif
Note: See TracChangeset
for help on using the changeset viewer.