Changeset 5308


Ignore:
Timestamp:
Feb 9, 2017, 4:06:24 PM (2 years ago)
Author:
cameron
Message:

Boundary assertions; comment out a bug with RemoveNullableAfterAssertion?

Location:
icGREP/icgrep-devel/icgrep
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5283 r5308  
    1111#include <llvm/IR/Function.h>
    1212#include <llvm/IR/TypeBuilder.h>
     13#include <fcntl.h>  // for
    1314
    1415using namespace llvm;
     16
     17llvm::Value * CBuilder::CreateOpenCall(Value * filename, Value * oflag, Value * mode) {
     18    Function * openFn = mMod->getFunction("open");
     19    if (openFn == nullptr) {
     20        IntegerType * int32Ty = getInt32Ty();
     21        PointerType * int8PtrTy = getInt8PtrTy();
     22        openFn = cast<Function>(mMod->getOrInsertFunction("open",
     23                                                         int32Ty, int8PtrTy, int32Ty, int32Ty, nullptr));
     24    }
     25    return CreateCall(openFn, {filename, oflag, mode});
     26}
     27
     28
    1529
    1630// ssize_t write(int fildes, const void *buf, size_t nbyte);
     
    4054    return CreateCall(readFn, {fildes, buf, nbyte});
    4155}
     56
     57llvm::Value * CBuilder::CreateCloseCall(Value * fildes) {
     58    Function * closeFn = mMod->getFunction("close");
     59    if (closeFn == nullptr) {
     60        IntegerType * int32Ty = getInt32Ty();
     61        closeFn = cast<Function>(mMod->getOrInsertFunction("close",
     62                                                           int32Ty, int32Ty, nullptr));
     63    }
     64    return CreateCall(closeFn, {fildes});
     65}
     66
     67
    4268
    4369Function * CBuilder::GetPrintf() {
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5283 r5308  
    5252    // stdio.h functions
    5353    //
    54     //  Create a call to:  FILE *fopen(const char *filename, const char *mode);
     54    //  Create a call to:  FILE * fopen(const char *filename, const char *mode);
    5555    llvm::Value * CreateFOpenCall(llvm::Value * filename, llvm::Value * mode);
    5656    //  Create a call to:  size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
     
    6565    //  Create calls to unistd.h functions.
    6666    //
     67    //  Create a call to:  int open(const char *filename, int oflag, ...);
     68    llvm::Value * CreateOpenCall(llvm::Value * filename, llvm::Value * oflag, llvm::Value * mode);
    6769    //  Create a call to:  ssize_t write(int fildes, const void *buf, size_t nbyte);
    6870    llvm::Value * CreateWriteCall(llvm::Value * fildes, llvm::Value * buf, llvm::Value * nbyte);
    6971    //  Create a call to:  ssize_t read(int fildes, void *buf, size_t nbyte);
    7072    llvm::Value * CreateReadCall(llvm::Value * fildes, llvm::Value * buf, llvm::Value * nbyte);
     73    //  Create a call to:  int close(int filedes);
     74    llvm::Value * CreateCloseCall(llvm::Value * fildes);
    7175
    72    
    7376    //  Posix thread (pthread.h) functions.
    7477    //
  • icGREP/icgrep-devel/icgrep/re/printer_re.cpp

    r5267 r5308  
    5757    } else if (const Assertion * a = dyn_cast<const Assertion>(re)) {
    5858        retVal = (a->getSense() == Assertion::Sense::Positive) ? "" : "Negative";
    59         retVal += (a->getKind() == Assertion::Kind::Lookahead) ? "Lookahead" : "Lookbehind";
     59        switch (a->getKind()) {
     60            case Assertion::Kind::Lookahead:
     61                retVal += "Lookahead";
     62                break;
     63            case Assertion::Kind::Lookbehind:
     64                retVal += "Lookbehind";
     65                break;
     66            case Assertion::Kind::Boundary:
     67                retVal += "Boundary";
     68                break;
     69        }
    6070        retVal += "Assertion(";
    6171        retVal += PrintRE(a->getAsserted());
  • icGREP/icgrep-devel/icgrep/re/re_assertion.h

    r4829 r5308  
    2020        return false;
    2121    }
    22     enum class Kind {Lookbehind, Lookahead};
     22    enum class Kind {Lookbehind, Lookahead, Boundary};
    2323    enum class Sense {Positive, Negative};
    2424
     
    6060}
    6161
     62inline RE * makeBoundaryAssertion(RE * r) {
     63    return makeAssertion(r, Assertion::Kind::Boundary, Assertion::Sense::Positive);
     64}
     65
     66inline RE * makeNegativeBoundaryAssertion(RE * r) {
     67    return makeAssertion(r, Assertion::Kind::Boundary, Assertion::Sense::Negative);
     68}
     69   
    6270}
    6371
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5267 r5308  
    266266        return compileEnd(marker, pb);
    267267    }
    268     throw std::runtime_error("RE Compiler failed to process " + Printer_RE::PrintRE(re));
     268    UnsupportedRE("RE Compiler failed to process " + Printer_RE::PrintRE(re));
    269269}
    270270
     
    313313        return m;
    314314    }
    315     throw std::runtime_error("Unresolved name " + name->getName());
     315    UnsupportedRE("Unresolved name " + name->getName());
    316316}
    317317
     
    377377        }
    378378        return makeMarker(markerPos(marker), pb.createAnd(markerVar(marker), lb, "lookback"));
     379    } else if (a->getKind() == Assertion::Kind::Boundary) {
     380        MarkerType cond = compile(asserted, pb);
     381        if (LLVM_LIKELY(markerPos(cond) == MarkerPosition::FinalMatchUnit)) {
     382            MarkerType postCond = AdvanceMarker(cond, MarkerPosition::FinalPostPositionUnit, pb);
     383            PabloAST * boundaryCond = pb.createAnd(mAny, pb.createXor(markerVar(cond), markerVar(postCond)));
     384            if (a->getSense() == Assertion::Sense::Negative) {
     385                boundaryCond = pb.createNot(boundaryCond);
     386            }
     387            MarkerType fbyte = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
     388            return makeMarker(MarkerPosition::FinalPostPositionUnit, pb.createAnd(markerVar(fbyte), boundaryCond, "boundary"));
     389        }
     390        else UnsupportedRE("Unsupported boundary assertion");
    379391    } else if (isUnicodeUnitLength(asserted)) {
    380392        MarkerType lookahead = compile(asserted, pb);
     
    388400        }
    389401    }
    390     throw std::runtime_error("Unsupported lookahead assertion.");
     402    UnsupportedRE("Unsupported lookahead assertion.");
    391403}
    392404
     
    406418        return makeMarker(markerPos(t1), pb.createAnd(markerVar(t1), pb.createNot(markerVar(t2)), "diff"));
    407419    }
    408     throw std::runtime_error("Unsupported Diff operands: " + Printer_RE::PrintRE(diff));
     420    UnsupportedRE("Unsupported Diff operands: " + Printer_RE::PrintRE(diff));
    409421}
    410422
     
    418430        return makeMarker(markerPos(t1), pb.createAnd(markerVar(t1), markerVar(t2), "intersect"));
    419431    }
    420     throw std::runtime_error("Unsupported Intersect operands: " + Printer_RE::PrintRE(x));
     432    UnsupportedRE("Unsupported Intersect operands: " + Printer_RE::PrintRE(x));
    421433}
    422434
     
    625637    }
    626638}
     639   
     640LLVM_ATTRIBUTE_NORETURN void RE_Compiler::UnsupportedRE(std::string errmsg) {
     641    llvm::report_fatal_error(errmsg);
     642}
     643   
     644   
    627645
    628646RE_Compiler::RE_Compiler(PabloKernel * kernel, cc::CC_Compiler & ccCompiler, bool CountOnly)
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r5267 r5308  
    6767    }
    6868
     69    static LLVM_ATTRIBUTE_NORETURN void UnsupportedRE(std::string errmsg);
     70   
    6971private:
    7072
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r5267 r5308  
    10811081
    10821082inline RE * RE_Parser::makeReBoundary(RE * re) {
    1083     return makeAlt({makeSeq({makeNegativeLookBehindAssertion(re), makeLookAheadAssertion(re)}),
    1084                     makeSeq({makeLookBehindAssertion(re), makeNegativeLookAheadAssertion(re)})});
     1083    return makeBoundaryAssertion(re);
    10851084}
    10861085inline RE * RE_Parser::makeReNonBoundary(RE * re) {
    1087     return makeAlt({makeSeq({makeNegativeLookBehindAssertion(re), makeNegativeLookAheadAssertion(re)}),
    1088                     makeSeq({makeLookBehindAssertion(re), makeLookAheadAssertion(re)})});
     1086    return makeNegativeBoundaryAssertion(re);
    10891087}
    10901088
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r5295 r5308  
    7272        std::cerr << "RemoveNullableAssertion:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    7373    }
    74     re_ast = re::RE_Nullable::removeNullableAfterAssertion(re_ast);
    75     if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
    76         std::cerr << "RemoveNullableAfterAssertion" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    77     }
     74    //re_ast = re::RE_Nullable::removeNullableAfterAssertion(re_ast);
     75    //if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
     76    //    std::cerr << "RemoveNullableAfterAssertion" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     77    //}
    7878   
    7979    re_ast = re::RE_Simplifier::simplify(re_ast);
Note: See TracChangeset for help on using the changeset viewer.