Changeset 4516


Ignore:
Timestamp:
Feb 25, 2015, 3:04:36 PM (3 years ago)
Author:
nmedfort
Message:

More memory leak fixes. All known leaks accounted for.

Location:
icGREP/icgrep-devel/icgrep
Files:
2 added
19 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4510 r4516  
    5353find_package(Boost)
    5454
    55 add_library(PabloADT pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp)
     55add_library(PabloADT pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp)
    5656add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_parser.cpp re/re_rep.cpp re/parsefailure.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/printer_re.cpp re/re_diff.cpp re/re_intersect.cpp re/re_analysis.cpp)
    5757add_library(CCADT cc/cc_namemap.cpp cc/cc_compiler.cpp utf8_encoder.cpp UCD/CaseFolding_txt.cpp)
  • icGREP/icgrep-devel/icgrep/cc/cc_namemap.cpp

    r4406 r4516  
    5757        auto f = mNameMap.find(classname);
    5858        if (f == mNameMap.end()) {
    59             Name * n;
    60             if (t == ByteClass) {
    61               n = makeByteName(classname, cc);
    62             }
    63             else {
    64               n = makeName(classname, cc);
    65             }
     59            Name * n = (t == ByteClass) ? makeByteName(classname, cc) : makeName(classname, cc);
    6660            return insert(std::move(classname), n);
    6761        }
  • icGREP/icgrep-devel/icgrep/compiler.cpp

    r4513 r4516  
    5555namespace icgrep {
    5656
    57 LLVM_Gen_RetVal compile(const Encoding encoding, const std::vector<std::string> regexps, const ModeFlagSet initialFlags) {
     57CompiledPabloFunction compile(const Encoding encoding, const std::vector<std::string> regexps, const ModeFlagSet initialFlags) {
    5858    std::vector<RE *> REs;
    5959    RE * re_ast = nullptr;
     
    157157    install_property_PropList_fn_ptrs(pablo_compiler);
    158158
    159     LLVM_Gen_RetVal retVal = pablo_compiler.compile(main);
     159    CompiledPabloFunction retVal = pablo_compiler.compile(main);
    160160
    161161    RE::release_memory();
  • icGREP/icgrep-devel/icgrep/compiler.h

    r4412 r4516  
    1616namespace icgrep {
    1717
    18     pablo::LLVM_Gen_RetVal compile(const Encoding encoding, const std::vector<std::string> regexps, const re::ModeFlagSet initialFlags);
     18    pablo::CompiledPabloFunction compile(const Encoding encoding, const std::vector<std::string> regexps, const re::ModeFlagSet initialFlags);
    1919
    2020}
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4460 r4516  
    105105    const auto llvm_codegen = icgrep::compile(encoding, regexVector, globalFlags);
    106106
    107     if (llvm_codegen.process_block_fptr != 0) {
     107    if (llvm_codegen.FunctionPointer) {
    108108        void (*FP)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output) =
    109            (void (*)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output))(void*)llvm_codegen.process_block_fptr;
    110         GrepExecutor grepEngine = GrepExecutor(llvm_codegen.carry_q_size, llvm_codegen.advance_q_size, FP);
     109           (void (*)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output))(void*)llvm_codegen.FunctionPointer;
     110        GrepExecutor grepEngine = GrepExecutor(llvm_codegen.CarryQueueSize, llvm_codegen.AdvanceQueueSize, FP);
    111111        grepEngine.setCountOnlyOption(CountOnly);
    112112        grepEngine.setNormalizeLineBreaksOption(NormalizeLineBreaks);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4510 r4516  
    105105PabloCompiler::~PabloCompiler()
    106106{
    107     // delete mMod;
     107
    108108}
    109109   
     
    113113
    114114
    115 LLVM_Gen_RetVal PabloCompiler::compile(PabloBlock & pb)
     115CompiledPabloFunction PabloCompiler::compile(PabloBlock & pb)
    116116{
    117117    mNestingDepth = 0;
     
    194194    mExecutionEngine->finalizeObject();
    195195
    196     LLVM_Gen_RetVal retVal;
    197196    //Return the required size of the carry queue and a pointer to the process_block function.
    198     retVal.carry_q_size = mCarryQueueSize;
    199     retVal.advance_q_size = mAdvanceQueueSize;
    200     retVal.process_block_fptr = mExecutionEngine->getPointerToFunction(mFunction);
    201 
    202     return retVal;
     197    return CompiledPabloFunction(mCarryQueueSize, mAdvanceQueueSize, mFunction, mExecutionEngine);
    203198}
    204199
     
    10921087}
    10931088
    1094 }
     1089CompiledPabloFunction::CompiledPabloFunction(unsigned carryQSize, unsigned advanceQSize, Function * function, ExecutionEngine * executionEngine)
     1090: CarryQueueSize(carryQSize)
     1091, AdvanceQueueSize(advanceQSize)
     1092, FunctionPointer(executionEngine->getPointerToFunction(function))
     1093, mFunction(function)
     1094, mExecutionEngine(executionEngine)
     1095{
     1096
     1097}
     1098
     1099// Clean up the memory for the compiled function once we're finished using it.
     1100CompiledPabloFunction::~CompiledPabloFunction() {
     1101    if (mExecutionEngine) {
     1102        assert (mFunction);
     1103        // mExecutionEngine->freeMachineCodeForFunction(mFunction); // This function only prints a "not supported" message. Reevaluate with LLVM 3.6.
     1104        delete mExecutionEngine;
     1105    }
     1106}
     1107
     1108}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4510 r4516  
    5151class StatementList;
    5252
    53 struct LLVM_Gen_RetVal
    54 {
    55     int carry_q_size;
    56     int advance_q_size;
    57     void *process_block_fptr;
     53struct CompiledPabloFunction {
     54    const unsigned      CarryQueueSize;
     55    const unsigned      AdvanceQueueSize;
     56    void * const        FunctionPointer;
     57private:
     58    Function *          mFunction;
     59    ExecutionEngine *   mExecutionEngine;
     60public:
     61    CompiledPabloFunction(unsigned carryQSize, unsigned advanceQSize, Function * function, ExecutionEngine * executionEngine);
     62
     63    inline CompiledPabloFunction(CompiledPabloFunction && cpf)
     64    : CarryQueueSize(cpf.CarryQueueSize)
     65    , AdvanceQueueSize(cpf.AdvanceQueueSize)
     66    , FunctionPointer(cpf.FunctionPointer)
     67    , mFunction(cpf.mFunction)
     68    , mExecutionEngine(cpf.mExecutionEngine)
     69    {
     70        cpf.mFunction = nullptr;
     71        cpf.mExecutionEngine = nullptr;
     72    }
     73
     74    ~CompiledPabloFunction();
     75
    5876};
    5977
     
    7492    ~PabloCompiler();
    7593    void InstallExternalFunction(std::string C_fn_name, void * fn_ptr);
    76     LLVM_Gen_RetVal compile(PabloBlock & pb);
     94    CompiledPabloFunction compile(PabloBlock & pb);
    7795private:
    7896    void DefineTypes();
  • icGREP/icgrep-devel/icgrep/re/re_alt.h

    r4432 r4516  
    3232    : Vector(ClassTypeId::Alt, begin, end) {
    3333
    34     }
    35     void* operator new (std::size_t size) noexcept {
    36         return mAllocator.allocate(size);
    3734    }
    3835private:
  • icGREP/icgrep-devel/icgrep/re/re_assertion.h

    r4407 r4516  
    3131protected:
    3232    friend Assertion * makeAssertion(RE * asserted, Kind k, Sense s);
    33     void* operator new (std::size_t size) noexcept {
    34         return mAllocator.allocate(size);
    35     }
    3633    Assertion(RE * r, Kind k, Sense s) : RE(ClassTypeId::Assertion), mAsserted(r), mKind(k), mSense(s) {}
    3734    virtual ~Assertion() {}
  • icGREP/icgrep-devel/icgrep/re/re_cc.h

    r4510 r4516  
    120120    friend CC * makeCC(const CC * cc1, const CC * cc2);
    121121    friend CC * subtractCC(const CC * cc1, const CC * cc2);
    122     void* operator new (std::size_t size) noexcept {
    123         return mAllocator.allocate(size);
    124     }
    125122    inline CC()
    126123    : RE(ClassTypeId::CC)
  • icGREP/icgrep-devel/icgrep/re/re_diff.h

    r4319 r4516  
    2929protected:
    3030    friend RE * makeDiff(RE*, RE*);
    31     void* operator new (std::size_t size) noexcept {
    32         return mAllocator.allocate(size);
    33     }
    3431    Diff(RE * lh, RE * rh)
    3532    : RE(ClassTypeId::Diff)
  • icGREP/icgrep-devel/icgrep/re/re_end.h

    r4272 r4516  
    2323protected:
    2424    friend End * makeEnd();
    25     void* operator new (std::size_t size) noexcept {
    26         return mAllocator.allocate(size);
    27     }
    2825    End() : RE(ClassTypeId::End) {}
    2926};
  • icGREP/icgrep-devel/icgrep/re/re_intersect.h

    r4319 r4516  
    2828protected:
    2929    friend RE * makeIntersect(RE*, RE*);
    30     void* operator new (std::size_t size) noexcept {
    31         return mAllocator.allocate(size);
    32     }
    3330    Intersect(RE * lh, RE * rh)
    3431    : RE(ClassTypeId::Intersect)
  • icGREP/icgrep-devel/icgrep/re/re_name.h

    r4438 r4516  
    2222        return false;
    2323    }
     24    using length_t = std::string::size_type;
    2425    enum class Type {
    2526        Byte
     
    2829        , Unknown
    2930    };
    30     const std::string & getNamespace() const;
    31     const std::string & getName() const;
    32     void setName(std::string);
     31    std::string getNamespace() const;
     32    std::string getName() const;
     33    void setName(const std::string &);
    3334    Type getType() const;
    3435    RE *getDefinition() const;
     
    4243    virtual ~Name() {}
    4344protected:
    44     friend Name * makeName(const std::string, RE *);   
    45     friend Name * makeByteName(const std::string, RE *);
    46     friend Name * makeName(const std::string, const Type);
    47     friend Name * makeName(const std::string, const std::string, const Type);   
    48     void* operator new (std::size_t size) noexcept {
    49         return mAllocator.allocate(size);
    50     }
    51     Name(const std::string && nameSpace, const std::string && name, const Type type, RE * defn)
     45    friend Name * makeName(const std::string &, RE *);
     46    friend Name * makeByteName(const std::string &, RE *);
     47    friend Name * makeName(const std::string &, const Type);
     48    friend Name * makeName(const std::string &, const std::string &, const Type);
     49    Name(const char * nameSpace, const length_t namespaceLength, const char * name, const length_t nameLength, const Type type, RE * defn)
    5250    : RE(ClassTypeId::Name)
    53     , mNamespace(std::move(nameSpace))
    54     , mName(std::move(name))
     51    , mNamespaceLength(namespaceLength)
     52    , mNamespace(replicateString(nameSpace, namespaceLength))
     53    , mNameLength(nameLength)
     54    , mName(replicateString(name, nameLength))
    5555    , mType(type)
    5656    , mDefiningRE(defn)
     
    5959
    6060    }
     61    inline const char * replicateString(const char * string, const length_t length) {
     62        if (string) {
     63            char * allocated = reinterpret_cast<char*>(mAllocator.allocate(length));
     64            std::memcpy(allocated, string, length);
     65            string = allocated;
     66        }
     67        return string;
     68    }
    6169
    6270private:
    63     std::string         mNamespace;
    64     std::string         mName;
     71    length_t            mNamespaceLength;
     72    const char *        mNamespace;
     73    length_t            mNameLength;
     74    const char *        mName;
    6575    const Type          mType;
    6676    RE *                mDefiningRE;
     
    6878};
    6979
    70 inline const std::string & Name::getNamespace() const {
    71     return mNamespace;
     80inline std::string Name::getNamespace() const {
     81    return std::string(mNamespace, mNamespaceLength);
    7282}
    7383
    74     inline const std::string & Name::getName() const {
    75         return mName;
    76     }
    77    
    78     inline void Name::setName(std::string n) {
    79         mName = n;
    80     }
     84inline std::string Name::getName() const {
     85    return std::string(mName, mNameLength);
     86}
     87
     88inline void Name::setName(const std::string & n) {
     89    mNameLength = n.length();
     90    mName = replicateString(n.c_str(), n.length());
     91}
    8192   
    8293inline Name::Type Name::getType() const {
     
    92103}
    93104
    94 inline Name * makeName(const std::string name, const Name::Type type = Name::Type::Unicode) {
    95     return new Name("", std::move(name), type, nullptr);
     105inline Name * makeName(const std::string & name, const Name::Type type = Name::Type::Unicode) {
     106    return new Name(nullptr, 0, name.c_str(), name.length(), type, nullptr);
    96107}
    97108
    98 inline Name * makeName(const std::string property, const std::string value, const Name::Type type = Name::Type::Unicode) {
    99     return new Name(std::move(property), std::move(value), type, nullptr);
     109inline Name * makeName(const std::string & property, const std::string & value, const Name::Type type = Name::Type::Unicode) {
     110    return new Name(property.c_str(), property.length(), value.c_str(), value.length(), type, nullptr);
    100111}
    101112
    102 inline Name * makeName(const std::string name, RE * cc) {
     113inline Name * makeName(const std::string & name, RE * cc) {
    103114    if (isa<Name>(cc)) {
    104115        return cast<Name>(cc);
     
    106117    else if (isa<CC>(cc)) {
    107118        Name::Type ccType = cast<CC>(cc)->max_codepoint() <= 0x7F ? Name::Type::Byte : Name::Type::Unicode;
    108         return new Name("", std::move(name), ccType, cc);
     119        return new Name(nullptr, 0, name.c_str(), name.length(), ccType, cc);
    109120    }
    110     else return new Name("", std::move(name), Name::Type::Unknown, cc);
     121    else return new Name(nullptr, 0, name.c_str(), name.length(), Name::Type::Unknown, cc);
    111122}
    112123
    113 inline Name * makeByteName(const std::string name, RE * cc) {
     124inline Name * makeByteName(const std::string & name, RE * cc) {
    114125    if (isa<Name>(cc)) {
    115126        return cast<Name>(cc);
    116127    }
    117128    else {
    118         return new Name("", std::move(name), Name::Type::Byte, cc);
     129        return new Name(nullptr, 0, name.c_str(), name.length(), Name::Type::Byte, cc);
    119130    }
    120131}
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r4429 r4516  
    570570    bool negated = false;
    571571    if (_cursor != _end && *_cursor == '^') {
    572       negated = true;
    573       ++_cursor;
     572        negated = true;
     573        ++_cursor;
    574574    }
    575575    throw_incomplete_expression_error_if_end_of_stream();
     
    587587        lastItemKind = CodepointItem;
    588588        lastCodepointItem = static_cast<codepoint_t> ('-');
    589                 if (*_cursor == '-') throw ParseFailure("Set operator has no left operand.");
     589        if (*_cursor == '-') {
     590            throw ParseFailure("Set operator has no left operand.");
     591        }
    590592    }
    591593    while (_cursor != _end) {
    592594        CharsetOperatorKind op = getCharsetOperator();
    593595        switch (op) {
    594             case intersectOp: case setDiffOp: {
    595                 if (lastItemKind == NoItem) throw ParseFailure("Set operator has no left operand.");
    596                 if (cc->begin() != cc->end()) subexprs.push_back(cc);
     596            case intersectOp:
     597            case setDiffOp: {
     598                if (lastItemKind == NoItem) {
     599                    throw ParseFailure("Set operator has no left operand.");
     600                }
     601                if (cc->begin() != cc->end()) {
     602                    subexprs.push_back(cc);
     603                }
    597604                RE * newOperand = makeAlt(subexprs.begin(), subexprs.end());
    598605                subexprs.clear();
     
    615622            break;
    616623            case setCloser: {
    617                 if (lastItemKind == NoItem) throw ParseFailure("Set operator has no right operand.");
     624                if (lastItemKind == NoItem) {
     625                    throw ParseFailure("Set operator has no right operand.");
     626                }
    618627                if (cc->begin() != cc->end()) {
    619628                    subexprs.push_back(cc);
     
    633642                    }
    634643                }
    635                 if (negated) return makeComplement(newOperand);
    636                 else return newOperand;
    637             }
    638             case setOpener: case posixPropertyOpener: {
     644                return negated ? makeComplement(newOperand) : newOperand;
     645            }
     646            case setOpener:
     647            case posixPropertyOpener: {
    639648                if (lastItemKind != NoItem) {
    640649                    if (cc->begin() != cc->end()) subexprs.push_back(cc);
     
    676685            break;
    677686            case rangeHyphen:
    678                 if (lastItemKind != CodepointItem) throw ParseFailure("Range operator - has illegal left operand.");
     687                if (lastItemKind != CodepointItem) {
     688                    throw ParseFailure("Range operator - has illegal left operand.");
     689                }
    679690                cc->insert_range(lastCodepointItem, parse_codepoint());
    680691                lastItemKind = RangeItem;
  • icGREP/icgrep-devel/icgrep/re/re_re.h

    r4510 r4516  
    6868
    6969    }
     70    void* operator new (std::size_t size) noexcept {
     71        return mAllocator.allocate(size);
     72    }
    7073    const ClassTypeId mClassTypeId;
    7174
  • icGREP/icgrep-devel/icgrep/re/re_rep.h

    r4272 r4516  
    3030protected:
    3131    friend RE * makeRep(RE *, const int, const int);
    32     void* operator new (std::size_t size) noexcept {
    33         return mAllocator.allocate(size);
    34     }
    3532    Rep(RE * re, const int lb, const int ub);
    3633private:
  • icGREP/icgrep-devel/icgrep/re/re_seq.h

    r4272 r4516  
    2525protected:
    2626    friend Seq * makeSeq();
    27     void* operator new (std::size_t size) noexcept {
    28         return mAllocator.allocate(size);
    29     }
    3027    template<typename iterator> friend RE * makeSeq(iterator, iterator);
    3128    Seq()
  • icGREP/icgrep-devel/icgrep/re/re_start.h

    r4272 r4516  
    2222protected:
    2323    friend Start * makeStart();
    24     void* operator new (std::size_t size) noexcept {
    25         return mAllocator.allocate(size);
    26     }
    2724    Start() : RE(ClassTypeId::Start) {}
    2825    virtual ~Start() {}
Note: See TracChangeset for help on using the changeset viewer.