Changeset 3632 in CLRX


Ignore:
Timestamp:
Jan 18, 2018, 7:18:53 PM (2 years ago)
Author:
matszpk
Message:

CLRadeonExtender: Asm: Tentative implementation of '.while' pseudo-op (repetition).

Location:
CLRadeonExtender/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/amdasm/AsmInternals.h

    r3631 r3632  
    289289    // do 'for'
    290290    static void doFor(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr);
     291    // do 'while'
     292    static void doWhile(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr);
    291293    // do open scope (.scope)
    292294    static void openScope(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr);
  • CLRadeonExtender/trunk/amdasm/AsmPseudoOps.cpp

    r3631 r3632  
    5656    "iflt", "ifnarch", "ifnb", "ifnc", "ifndef",
    5757    "ifne", "ifnes", "ifnfmt", "ifngpu", "ifnotdef",
    58     "irp", "irpc", "macro", "rept"
     58    "irp", "irpc", "macro", "rept", "while"
    5959};
    6060
     
    6262static const char* macroRepeatPseudoOpNamesTbl[] =
    6363{
    64     "endm", "endmacro", "endr", "endrept", "for", "irp", "irpc", "macro", "rept"
     64    "endm", "endmacro", "endr", "endrept", "for", "irp", "irpc", "macro", "rept", "while"
    6565};
    6666
     
    8181    ASMCOP_IFLT, ASMCOP_IFNARCH, ASMCOP_IFNB, ASMCOP_IFNC, ASMCOP_IFNDEF,
    8282    ASMCOP_IFNE, ASMCOP_IFNES, ASMCOP_IFNFMT, ASMCOP_IFNGPU, ASMCOP_IFNOTDEF,
    83     ASMCOP_IRP, ASMCOP_IRPC, ASMCOP_MACRO, ASMCOP_REPT
     83    ASMCOP_IRP, ASMCOP_IRPC, ASMCOP_MACRO, ASMCOP_REPT, ASMCOP_WHILE
    8484};
    8585
     
    8787enum
    8888{ ASMMROP_ENDM = 0, ASMMROP_ENDMACRO, ASMMROP_ENDR, ASMMROP_ENDREPT,
    89     ASMMROP_FOR, ASMMROP_IRP, ASMMROP_IRPC, ASMMROP_MACRO, ASMMROP_REPT };
     89    ASMMROP_FOR, ASMMROP_IRP, ASMMROP_IRPC, ASMMROP_MACRO, ASMMROP_REPT,
     90    ASMMROP_WHILE };
    9091
    9192/// all main pseudo-ops (sorted by name)
     
    129130    "string64", "struct", "text", "title",
    130131    "undef", "unusing", "usereg", "using", "version",
    131     "warning", "weak", "word"
     132    "warning", "weak", "while", "word"
    132133};
    133134
     
    172173    ASMOP_STRING64, ASMOP_STRUCT, ASMOP_TEXT, ASMOP_TITLE,
    173174    ASMOP_UNDEF, ASMOP_UNUSING, ASMOP_USEREG, ASMOP_USING, ASMOP_VERSION,
    174     ASMOP_WARNING, ASMOP_WEAK, ASMOP_WORD
     175    ASMOP_WARNING, ASMOP_WEAK, ASMOP_WHILE, ASMOP_WORD
    175176};
    176177
     
    19451946    asmr.pushClause(pseudoOpPlace, AsmClauseType::REPEAT);
    19461947    std::unique_ptr<AsmFor> repeat(new AsmFor(
    1947                 asmr.getSourcePos(pseudoOpPlace), iterSymbol, condExpr.get(), nextExpr.get()));
     1948                asmr.getSourcePos(pseudoOpPlace), iterSymbol, condExpr.get(),
     1949                nextExpr.get()));
    19481950    condExpr.release();
    19491951    nextExpr.release();
     1952    if (asmr.putRepetitionContent(*repeat))
     1953    {
     1954        // and input stream filter
     1955        std::unique_ptr<AsmInputFilter> newInputFilter(
     1956                    new AsmForInputFilter(repeat.release()));
     1957        asmr.asmInputFilters.push(newInputFilter.release());
     1958        asmr.currentInputFilter = asmr.asmInputFilters.top();
     1959        asmr.repetitionLevel++;
     1960    }
     1961}
     1962
     1963void AsmPseudoOps::doWhile(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr)
     1964{
     1965    std::unique_ptr<AsmExpression> condExpr(AsmExpression::parse(asmr, linePtr, true));
     1966    if (!checkGarbagesAtEnd(asmr, linePtr))
     1967        return;
     1968   
     1969    if (condExpr==nullptr)
     1970        return; // if no expressions
     1971   
     1972    // check depth of repetitions
     1973    if (asmr.repetitionLevel == 1000)
     1974        PSEUDOOP_RETURN_BY_ERROR("Repetition level is greater than 1000")
     1975   
     1976    // create AsmFor
     1977    asmr.pushClause(pseudoOpPlace, AsmClauseType::REPEAT);
     1978    std::unique_ptr<AsmFor> repeat(new AsmFor(
     1979                asmr.getSourcePos(pseudoOpPlace), nullptr, condExpr.get(), nullptr));
     1980    condExpr.release();
    19501981    if (asmr.putRepetitionContent(*repeat))
    19511982    {
     
    27852816        case ASMOP_WEAK:
    27862817            AsmPseudoOps::setSymbolBind(*this, linePtr, STB_WEAK);
     2818            break;
     2819        case ASMOP_WHILE:
     2820            AsmPseudoOps::doWhile(*this, stmtPlace, linePtr);
    27872821            break;
    27882822        case ASMOP_WORD:
     
    29953029            case ASMCOP_REPT:
    29963030            case ASMCOP_FOR:
     3031            case ASMCOP_WHILE:
    29973032                if (!pushClause(stmtPlace, AsmClauseType::REPEAT))
    29983033                    good = false;
     
    30593094            case ASMMROP_REPT:
    30603095            case ASMMROP_FOR:
     3096            case ASMMROP_WHILE:
    30613097                if (!pushClause(stmtPlace, AsmClauseType::REPEAT))
    30623098                    good = false;
  • CLRadeonExtender/trunk/amdasm/AsmSource.cpp

    r3631 r3632  
    978978        cxuint sectionId = ASMSECT_ABS;
    979979        bool good = true;
     980        if (asmFor->getNextExpr() != nullptr)
    980981        {
    981982            std::unique_ptr<AsmExpression> nextEvExpr(asmFor->getNextExpr()->
  • CLRadeonExtender/trunk/doc/ClrxAsmPseudoOps.md

    r3631 r3632  
    933933the CLRX assembler.
    934934
     935### .while
     936
     937Syntax: .while COND-EXPR
     938
     939Open 'while' repetition.The code between this pseudo-operation and `.endr` will be repeated
     940until COND-EXPR returns zero. Example:
     941
     942```
     943x=1
     944.while x<16
     945    .int x
     946    x=x+1
     947.endr
     948```
     949
     950generates:
     951
     952```
     953.int x      # x=1
     954.int x      # x=2
     955.int x      # x=4
     956.int x      # x=8
     957```
     958
    935959### .word
    936960
  • CLRadeonExtender/trunk/tests/amdasm/AsmBasicsCases2.cpp

    r3631 r3632  
    20572057        }, true, "", ""
    20582058    },
     2059    /* 75 - '.while' repetition */
     2060    {
     2061        R"ffDXD(
     2062            x=1
     2063            .while  x  <  16
     2064                .int x
     2065                x=x+x
     2066            .endr
     2067)ffDXD",
     2068        BinaryFormat::AMD, GPUDeviceType::CAPE_VERDE, false, { },
     2069        { { nullptr, ASMKERN_GLOBAL, AsmSectionType::DATA,
     2070            {
     2071                0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
     2072                0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00
     2073            } } },
     2074        {
     2075            { ".", 16U, 0, 0U, true, false, false, 0, 0 },
     2076            { "x", 16U, ASMSECT_ABS, 0U, true, false, false, 0, 0 }
     2077        }, true, "", ""
     2078    },
    20592079    { nullptr }
    20602080};
Note: See TracChangeset for help on using the changeset viewer.