Ignore:
Timestamp:
Jan 9, 2018, 12:01:46 PM (11 months ago)
Author:
cameron
Message:

Direct CC compiler

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r5814 r5823  
    11/*
    2  *  Copyright (c) 2014 International Characters.
     2 *  Copyright (c) 2018 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 *  icgrep is a trademark of International Characters.
     
    66
    77#include "cc_compiler.h"
     8#include <cc/alphabet.h>
    89#include <pablo/codegenstate.h>
    910#include <pablo/boolean.h>
     
    228229}
    229230
     231   
     232PabloAST * compileCCfromCodeUnitStream(const CC *cc, PabloAST * codeUnitStream, PabloBuilder & pb) {
     233    const Alphabet * a = cc->getAlphabet();
     234    if (!isa<CodeUnitAlphabet>(a)) {
     235        llvm::report_fatal_error("compileCCfromCodeUnitStream must be applied to a CC with a CodeUnitAlphabet");
     236    }
     237    unsigned codeUnitWidth = cast<const CodeUnitAlphabet>(a)->getCodeUnitBitWidth();
     238    unsigned topBit = 1 << codeUnitWidth;
     239    unsigned maxCodeVal = (topBit - 1) | topBit;
     240    PabloAST * ccStrm = pb.createZeroes();
     241#ifdef PABLO_ALL
     242    for (const auto & interval : *cc) {
     243        unsigned lo = re::lo_codepoint(interval);
     244        unsigned hi = re::hi_codepoint(interval);
     245        if (lo == hi) {
     246            PabloAST * testVal = pb.createAll(codeUnitWidth, lo);
     247            ccStrm = pb.createOr(ccStrm, pb.createEqual(codeUnitStream, testVal));
     248        } else if (lo == 0) {
     249            if (hi == maxCodeVal) {
     250                // All code units
     251                ccStrm = pb.createOnes();
     252            } else {
     253                PabloAST * testVal = pb.createAll(codeUnitWidth, hi+1);
     254                ccStrm = pb.createOr(ccStrm, pb.createLessThan(codeUnitStream, testVal));
     255            }
     256        } else if (hi == maxCodeVal) {
     257            PabloAST * testVal = pb.createAll(codeUnitWidth, lo);
     258            ccStrm = pb.createOr(ccStrm, pb.createNot(pb.createLessThan(codeUnitStream, testVal));)
     259        } else {
     260            PabloAST * testVal_lo = pb.createAll(codeUnitWidth, lo);
     261            PabloAST * testVal_hi = pb.createAll(codeUnitWidth, hi+1);
     262            ccStrm = pb.createOr(ccStrm, pb.createAnd(pb.createNot(pb.createLessThan(codeUnitStream, testVal_lo)),
     263                                                      pb.createLessThan(codeUnitStream, testVal_hi)));
     264        }
     265    }
     266#endif
     267    return ccStrm;
     268}
    230269} // end of namespace cc
Note: See TracChangeset for help on using the changeset viewer.