Changeset 3629 in CLRX


Ignore:
Timestamp:
Jan 18, 2018, 3:10:24 PM (2 years ago)
Author:
matszpk
Message:

CLRadeonExtender: Asm: Prepping to '.for' implementation. Fixed undefSymbol: do not remove symbol from map:
previous behaviour causes invalid reads after evaluating '.eqv' symbol after required symbol to evaluation).

Location:
CLRadeonExtender/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/CLRX/amdasm/AsmDefs.h

    r3578 r3629  
    331331    bool isEmpty() const
    332332    { return ops.empty(); }
    333 
     333   
    334334    /// helper to create symbol snapshot. Creates initial expression for symbol snapshot
    335335    AsmExpression* createForSnapshot(const AsmSourcePos* exprSourcePos) const;
  • CLRadeonExtender/trunk/CLRX/amdasm/AsmSource.h

    r3575 r3629  
    4040
    4141class Assembler;
     42class AsmExpression;
    4243
    4344/// line and column
     
    287288};
    288289
     290/// assembler repeat 'for'
     291class AsmFor: public AsmRepeat
     292{
     293private:
     294    void* iterSymEntry;
     295    std::unique_ptr<const AsmExpression> condExpr;
     296    std::unique_ptr<const AsmExpression> nextExpr;
     297public:
     298    /// constructor
     299    explicit AsmFor(const AsmSourcePos& pos, void* iterSymEntry,
     300            const AsmExpression* condExpr, const AsmExpression* nextExpr);
     301   
     302    /// get iteration symbol entry
     303    const void* getIterSymEntry() const
     304    { return iterSymEntry; }
     305    /// get condition expression
     306    const AsmExpression* getCondExpr() const
     307    { return condExpr.get(); }
     308    /// get next expression
     309    const AsmExpression* getNextExpr() const
     310    { return nextExpr.get(); }
     311};
     312
    289313/// assembler IRP
    290314class AsmIRP: public AsmRepeat
     
    455479class AsmRepeatInputFilter: public AsmInputFilter
    456480{
    457 private:
     481protected:
    458482    std::unique_ptr<const AsmRepeat> repeat;
    459483    uint64_t repeatCount;
     
    470494    uint64_t getRepeatCount() const
    471495    { return repeatCount; }
     496};
     497
     498/// assembler 'for' pseudo-op input filter
     499class AsmForInputFilter: public AsmRepeatInputFilter
     500{
     501public:
     502    /// constructor
     503    explicit AsmForInputFilter(const AsmFor* forRpt);
     504   
     505    const char* readLine(Assembler& assembler, size_t& lineSize);
    472506};
    473507
  • CLRadeonExtender/trunk/amdasm/AsmPseudoOps.cpp

    r3575 r3629  
    5151    "elseifndef", "elseifne", "elseifnes",
    5252    "elseifnfmt", "elseifngpu", "elseifnotdef",
    53     "endif", "endm", "endmacro", "endr", "endrept",
     53    "endif", "endm", "endmacro", "endr", "endrept", "for",
    5454    "if", "if32", "if64", "ifarch", "ifb", "ifc", "ifdef", "ifeq",
    5555    "ifeqs", "iffmt", "ifge", "ifgpu", "ifgt", "ifle",
     
    6262static const char* macroRepeatPseudoOpNamesTbl[] =
    6363{
    64     "endm", "endmacro", "endr", "endrept", "irp", "irpc", "macro", "rept"
     64    "endm", "endmacro", "endr", "endrept", "for", "irp", "irpc", "macro", "rept"
    6565};
    6666
     
    7676    ASMCOP_ELSEIFNFMT, ASMCOP_ELSEIFNGPU, ASMCOP_ELSEIFNOTDEF,
    7777    ASMCOP_ENDIF, ASMCOP_ENDM, ASMCOP_ENDMACRO, ASMCOP_ENDR, ASMCOP_ENDREPT,
    78     ASMCOP_IF, ASMCOP_IF32, ASMCOP_IF64, ASMCOP_IFARCH, ASMCOP_IFB,
     78    ASMCOP_FOR, ASMCOP_IF, ASMCOP_IF32, ASMCOP_IF64, ASMCOP_IFARCH, ASMCOP_IFB,
    7979    ASMCOP_IFC, ASMCOP_IFDEF, ASMCOP_IFEQ,
    8080    ASMCOP_IFEQS, ASMCOP_IFFMT, ASMCOP_IFGE, ASMCOP_IFGPU, ASMCOP_IFGT, ASMCOP_IFLE,
     
    8787enum
    8888{ ASMMROP_ENDM = 0, ASMMROP_ENDMACRO, ASMMROP_ENDR, ASMMROP_ENDREPT,
    89     ASMMROP_IRP, ASMMROP_IRPC, ASMMROP_MACRO, ASMMROP_REPT };
     89    ASMMROP_FOR, ASMMROP_IRP, ASMMROP_IRPC, ASMMROP_MACRO, ASMMROP_REPT };
    9090
    9191/// all main pseudo-ops (sorted by name)
     
    110110    "err", "error", "exitm", "extern",
    111111    "fail", "file", "fill", "fillq",
    112     "float", "format", "gallium", "get_64bit", "get_arch",
     112    "float", "for", "format", "gallium", "get_64bit", "get_arch",
    113113    "get_format", "get_gpu", "get_version", "global",
    114114    "globl", "gpu", "half", "hword", "if", "if32", "if64",
     
    153153    ASMOP_ERR, ASMOP_ERROR, ASMOP_EXITM, ASMOP_EXTERN,
    154154    ASMOP_FAIL, ASMOP_FILE, ASMOP_FILL, ASMOP_FILLQ,
    155     ASMOP_FLOAT, ASMOP_FORMAT, ASMOP_GALLIUM, ASMOP_GET_64BIT, ASMOP_GET_ARCH,
     155    ASMOP_FLOAT, ASMOP_FOR, ASMOP_FORMAT, ASMOP_GALLIUM, ASMOP_GET_64BIT, ASMOP_GET_ARCH,
    156156    ASMOP_GET_FORMAT, ASMOP_GET_GPU, ASMOP_GET_VERSION, ASMOP_GLOBAL,
    157157    ASMOP_GLOBL, ASMOP_GPU, ASMOP_HALF, ASMOP_HWORD, ASMOP_IF, ASMOP_IF32, ASMOP_IF64,
     
    20412041        asmr.printWarning(symNamePlace, (std::string("Symbol '") + symName.c_str() +
    20422042                "' already doesn't exist").c_str());
    2043     else if (it->second.occurrencesInExprs.empty())
    2044         // remove from symbol map if no occurrences anywhere
    2045         outScope->symbolMap.erase(sameSymName);
    2046     else
    2047         // if some occurrences in expression just mark as undefined
     2043    else // always undefine (do not remove, due to .eqv evaluation)
    20482044        it->second.undefine();
    20492045}
     
    24522448        case ASMOP_FLOAT:
    24532449            AsmPseudoOps::putFloats<uint32_t>(*this, stmtPlace, linePtr);
     2450            break;
     2451        case ASMOP_FOR:
    24542452            break;
    24552453        case ASMOP_FORMAT:
     
    29182916            case ASMCOP_IRPC:
    29192917            case ASMCOP_REPT:
     2918            case ASMCOP_FOR:
    29202919                if (!pushClause(stmtPlace, AsmClauseType::REPEAT))
    29212920                    good = false;
     
    29812980            case ASMMROP_IRPC:
    29822981            case ASMMROP_REPT:
     2982            case ASMMROP_FOR:
    29832983                if (!pushClause(stmtPlace, AsmClauseType::REPEAT))
    29842984                    good = false;
     
    30463046            case ASMMROP_IRPC:
    30473047            case ASMMROP_REPT:
     3048            case ASMMROP_FOR:
    30483049                if (!pushClause(stmtPlace, AsmClauseType::REPEAT))
    30493050                    good = false;
  • CLRadeonExtender/trunk/amdasm/AsmSource.cpp

    r3575 r3629  
    111111    contentLineNo++;
    112112}
     113
     114AsmFor::AsmFor(const AsmSourcePos& _pos, void* _iterSymEntry,
     115                const AsmExpression* _condExpr, const AsmExpression* _nextExpr)
     116        : AsmRepeat(_pos, 0), iterSymEntry(_iterSymEntry), condExpr(_condExpr),
     117                    nextExpr(_nextExpr)
     118{ }
    113119
    114120AsmIRP::AsmIRP(const AsmSourcePos& _pos, const CString& _symbolName,
     
    949955}
    950956
     957AsmForInputFilter::AsmForInputFilter(const AsmFor* forRpt) :
     958        AsmRepeatInputFilter(forRpt)
     959{ }
     960
     961const char* AsmForInputFilter::readLine(Assembler& assembler, size_t& lineSize)
     962{
     963    colTranslations.clear();
     964    const std::vector<LineTrans>& repeatColTrans = repeat->getColTranslations();
     965    const LineTrans* colTransEnd = repeatColTrans.data()+ repeatColTrans.size();
     966    const size_t contentSize = repeat->getContent().size();
     967    if (pos == contentSize)
     968    {
     969        repeatCount++;
     970        if (repeatCount == repeat->getRepeatsNum() || contentSize==0)
     971        {
     972            lineSize = 0;
     973            return nullptr;
     974        }
     975        sourceTransIndex = 0;
     976        curColTrans = repeat->getColTranslations().data();
     977        pos = 0;
     978        contentLineNo = 0;
     979        source = RefPtr<const AsmSource>(new AsmRepeatSource(
     980            repeat->getSourceTrans(0).source, repeatCount, repeat->getRepeatsNum()));
     981    }
     982    const char* content = repeat->getContent().data();
     983    size_t oldPos = pos;
     984    while (pos < contentSize && content[pos] != '\n')
     985        pos++;
     986   
     987    lineSize = pos - oldPos; // set new linesize
     988    if (pos < contentSize)
     989        pos++; // skip newline
     990   
     991    const LineTrans* oldCurColTrans = curColTrans;
     992    curColTrans++;
     993    while (curColTrans != colTransEnd && curColTrans->position > 0)
     994        curColTrans++;
     995    colTranslations.assign(oldCurColTrans, curColTrans);
     996   
     997    lineNo = (curColTrans != colTransEnd) ? curColTrans->lineNo : repeatColTrans[0].lineNo;
     998    if (sourceTransIndex+1 < repeat->getSourceTransSize())
     999    {
     1000        const AsmRepeat::SourceTrans& fpos = repeat->getSourceTrans(sourceTransIndex+1);
     1001        if (fpos.lineNo == contentLineNo)
     1002        {
     1003            macroSubst = fpos.macro;
     1004            sourceTransIndex++;
     1005            source = RefPtr<const AsmSource>(new AsmRepeatSource(
     1006                fpos.source, repeatCount, repeat->getRepeatsNum()));
     1007        }
     1008    }
     1009    contentLineNo++;
     1010    return content + oldPos;
     1011}
     1012
    9511013AsmIRPInputFilter::AsmIRPInputFilter(const AsmIRP* _irp) :
    9521014        AsmInputFilter(AsmInputFilterType::REPEAT), irp(_irp),
     
    11841246        size_t size = itocstrCStyle(sourceRept->repeatCount+1, numBuf, 32);
    11851247        numBuf[size++] = '/';
    1186         size += itocstrCStyle(sourceRept->repeatsNum, numBuf+size, 32-size);
     1248        if (sourceRept->repeatsNum!=0)
     1249            size += itocstrCStyle(sourceRept->repeatsNum, numBuf+size, 32-size);
     1250        else // print '?'. we don't know where is end
     1251            numBuf[size++] = '?';
    11871252        numBuf[size++] = ':';
    11881253        numBuf[size++] = '\n';
  • CLRadeonExtender/trunk/amdasm/Assembler.cpp

    r3598 r3629  
    609609        expression = nullptr;
    610610    }
     611    value = 0;
    611612    onceDefined = false;
    612613}
Note: See TracChangeset for help on using the changeset viewer.