Changeset 4102 in CLRX


Ignore:
Timestamp:
May 7, 2018, 4:01:28 PM (2 months ago)
Author:
matszpk
Message:

CLRadeonExtender: Asm: Add enums (pseudo-ops '.enum').

Location:
CLRadeonExtender/trunk
Files:
6 edited

Legend:

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

    r3786 r4102  
    676676    bool temporary; ///< true if temporary
    677677    std::list<AsmScope*> usedScopes;    ///< list of used scope in this scope
     678    uint64_t enumCount;
    678679   
    679680    /// set of used scopes in this scope
     
    683684    AsmScope(AsmScope* _parent, const AsmSymbolMap& _symbolMap,
    684685                     bool _temporary = false)
    685             : parent(_parent), symbolMap(_symbolMap), temporary(_temporary)
     686            : parent(_parent), symbolMap(_symbolMap), temporary(_temporary), enumCount(0)
    686687    { }
    687688    /// constructor
    688689    AsmScope(AsmScope* _parent = nullptr, bool _temporary= false)
    689             : parent(_parent), temporary(_temporary)
     690            : parent(_parent), temporary(_temporary), enumCount(0)
    690691    { }
    691692    /// destructor
  • CLRadeonExtender/trunk/amdasm/AsmInternals.h

    r3740 r4102  
    298298    static void closeScope(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr);
    299299    // start using scope (.using)
    300     static void startUsing(Assembler& asmr, const char* pseudoOpPlace,
    301                         const char* linePtr);
     300    static void startUsing(Assembler& asmr, const char* linePtr);
    302301    // stop using scope (.unusing)
    303     static void stopUsing(Assembler& asmr, const char* pseudoOpPlace,
    304                         const char* linePtr);
     302    static void stopUsing(Assembler& asmr, const char* linePtr);
    305303    // .usereg ?
    306     static void doUseReg(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr);
     304    static void doUseReg(Assembler& asmr, const char* linePtr);
    307305    // .undef
    308306    static void undefSymbol(Assembler& asmr, const char* linePtr);
    309307    // .regvar
    310     static void defRegVar(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr);
     308    static void defRegVar(Assembler& asmr, const char* linePtr);
    311309    // .cf_ (code flow pseudo-ops)
    312310    static void addCodeFlowEntries(Assembler& asmr, const char* pseudoOpPlace,
     
    318316                        AsmPredefined predefined);
    319317   
     318    // enumerate
     319    static void doEnum(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr);
     320   
    320321    static void ignoreString(Assembler& asmr, const char* linePtr);
    321322   
  • CLRadeonExtender/trunk/amdasm/AsmPseudoOps.cpp

    r3787 r4102  
    108108    "end", "endif", "endm", "endmacro",
    109109    "endr", "endrept", "ends", "endscope",
    110     "equ", "equiv", "eqv",
     110    "enum", "equ", "equiv", "eqv",
    111111    "err", "error", "exitm", "extern",
    112112    "fail", "file", "fill", "fillq",
     
    151151    ASMOP_END, ASMOP_ENDIF, ASMOP_ENDM, ASMOP_ENDMACRO,
    152152    ASMOP_ENDR, ASMOP_ENDREPT, ASMOP_ENDS, ASMOP_ENDSCOPE,
    153     ASMOP_EQU, ASMOP_EQUIV, ASMOP_EQV,
     153    ASMOP_ENUM, ASMOP_EQU, ASMOP_EQUIV, ASMOP_EQV,
    154154    ASMOP_ERR, ASMOP_ERROR, ASMOP_EXITM, ASMOP_EXTERN,
    155155    ASMOP_FAIL, ASMOP_FILE, ASMOP_FILL, ASMOP_FILLQ,
     
    20492049}
    20502050
    2051 void AsmPseudoOps::startUsing(Assembler& asmr, const char* pseudoOpPlace,
    2052                     const char* linePtr)
     2051void AsmPseudoOps::startUsing(Assembler& asmr, const char* linePtr)
    20532052{
    20542053    const char* end = asmr.line+asmr.lineSize;
     
    20662065}
    20672066
    2068 void AsmPseudoOps::doUseReg(Assembler& asmr, const char* pseudoOpPlace,
    2069                     const char* linePtr)
     2067void AsmPseudoOps::doUseReg(Assembler& asmr, const char* linePtr)
    20702068{
    20712069    const char* end = asmr.line+asmr.lineSize;
     
    21192117}
    21202118
    2121 void AsmPseudoOps::stopUsing(Assembler& asmr, const char* pseudoOpPlace,
    2122                     const char* linePtr)
     2119void AsmPseudoOps::stopUsing(Assembler& asmr, const char* linePtr)
    21232120{
    21242121    const char* end = asmr.line+asmr.lineSize;
     
    21762173}
    21772174
    2178 void AsmPseudoOps::defRegVar(Assembler& asmr, const char* pseudoOpPlace,
    2179                        const char* linePtr)
     2175void AsmPseudoOps::defRegVar(Assembler& asmr, const char* linePtr)
    21802176{
    21812177    const char* end = asmr.line+asmr.lineSize;
     
    23032299}
    23042300
     2301void AsmPseudoOps::doEnum(Assembler& asmr, const char* pseudoOpPlace, const char* linePtr)
     2302{
     2303    const char* end = asmr.line + asmr.lineSize;
     2304    skipSpacesToEnd(linePtr, end);
     2305    uint64_t& enumCount = asmr.currentScope->enumCount;
     2306    if (linePtr!=end && *linePtr=='>')
     2307    {
     2308        // parse enum start
     2309        linePtr++;
     2310        uint64_t enumStart = 0;
     2311        if (!getAbsoluteValueArg(asmr, enumStart, linePtr, false))
     2312            return;
     2313       
     2314        enumCount = enumStart;
     2315        if (!skipRequiredComma(asmr, linePtr))
     2316            return;
     2317    }
     2318    skipSpacesToEnd(linePtr, end);
     2319    do {
     2320        const char* strAtSymName = linePtr;
     2321        CString symbolName = extractScopedSymName(linePtr, end, false);
     2322        if (!symbolName.empty())
     2323        {
     2324            std::pair<AsmSymbolEntry*, bool> res =
     2325                    asmr.insertSymbolInScope(symbolName, AsmSymbol());
     2326            if (!res.second && res.first->second.isDefined())
     2327                // found and can be only once defined
     2328                asmr.printError(strAtSymName, (std::string("Symbol '") +
     2329                        symbolName.c_str() + "' is already defined").c_str());
     2330            else
     2331            {
     2332                asmr.setSymbol(*res.first, enumCount++, ASMSECT_ABS);
     2333                res.first->second.onceDefined = true;
     2334            }
     2335        }
     2336        else
     2337            asmr.printError(linePtr, "Expected symbol name");
     2338       
     2339    } while(skipCommaForMultipleArgs(asmr, linePtr));
     2340    checkGarbagesAtEnd(asmr, linePtr);
     2341}
     2342
    23052343void AsmPseudoOps::ignoreString(Assembler& asmr, const char* linePtr)
    23062344{
     
    25292567            AsmPseudoOps::closeScope(*this, stmtPlace, linePtr);
    25302568            break;
     2569        case ASMOP_ENUM:
     2570            AsmPseudoOps::doEnum(*this, stmtPlace, linePtr);
    25312571            break;
    25322572        case ASMOP_EQU:
     
    27592799            break;
    27602800        case ASMOP_REGVAR:
    2761             AsmPseudoOps::defRegVar(*this, stmtPlace, linePtr);
     2801            AsmPseudoOps::defRegVar(*this, linePtr);
    27622802            break;
    27632803        case ASMOP_REPT:
     
    28132853            break;
    28142854        case ASMOP_UNUSING:
    2815             AsmPseudoOps::stopUsing(*this, stmtPlace, linePtr);
     2855            AsmPseudoOps::stopUsing(*this, linePtr);
    28162856            break;
    28172857        case ASMOP_USEREG:
    2818             AsmPseudoOps::doUseReg(*this, stmtPlace, linePtr);
     2858            AsmPseudoOps::doUseReg(*this, linePtr);
    28192859            break;
    28202860        case ASMOP_USING:
    2821             AsmPseudoOps::startUsing(*this, stmtPlace, linePtr);
     2861            AsmPseudoOps::startUsing(*this, linePtr);
    28222862            break;
    28232863        case ASMOP_WARNING:
  • CLRadeonExtender/trunk/amdasm/Assembler.cpp

    r3944 r4102  
    732732          globalScope({nullptr,{std::make_pair(".", AsmSymbol(0, uint64_t(0)))}}),
    733733          currentScope(&globalScope),
    734           flags(_flags), 
     734          flags(_flags),
    735735          lineSize(0), line(nullptr),
    736736          endOfAssembly(false),
     
    770770          globalScope({nullptr,{std::make_pair(".", AsmSymbol(0, uint64_t(0)))}}),
    771771          currentScope(&globalScope),
    772           flags(_flags), 
     772          flags(_flags),
    773773          lineSize(0), line(nullptr),
    774774          endOfAssembly(false),
     
    16461646       
    16471647        // create symbol clone before setting value
    1648             cloneSymEntryIfNeeded(*res.first);
     1648        cloneSymEntryIfNeeded(*res.first);
    16491649       
    16501650        if (!res.first->second.occurrencesInExprs.empty())
  • CLRadeonExtender/trunk/doc/ClrxAsmPseudoOps.md

    r3641 r4102  
    205205Finish code of repetition.
    206206
    207 #### .ends, .endscope
     207### .ends, .endscope
    208208
    209209Close visibility's scope.
     210
     211### .enum
     212
     213Syntax: .enum [>STARTPOS,] SYMBOL,....
     214
     215Simplify defining the enumerations. For every symbol,
     216define symbol with value of enumeration counter and increase an enumeration counter.
     217Defined symbols can not be assigned later. Optional STARTPOS sets enumeration counter
     218to STARTPOS value. Every scope has own enumeration counter. This features simplify
     219joining enumerations with scopes.
     220
     221Examples:
     222
     223```
     224.enum OK,BADFD,FATAL        # define OK=0, BADFD=1, FATAL=2
     225.enum >8, BitOne,BitTwo     # define BitOne=8, BitTwo=9
     226.enum HALO                  # define HALO=10
     227.scope Result
     228    # enum counter is zero in this scope
     229    .enum NONE,FULL,INVALID   # NONE=0, FULL=1, INVALID=2
     230.ends
     231```
    210232
    211233### .equ, .set
  • CLRadeonExtender/trunk/tests/amdasm/AsmBasicsCases2.cpp

    r3820 r4102  
    23342334        }, true, "", ""
    23352335    },
     2336    {   // 81 - use enums
     2337        R"ffDXD(.enum sym1,sym2,sym6,xxx
     2338        .enum >1?100:0 ,  ala,joan,beta
     2339       
     2340        .scope Error
     2341            .enum OK
     2342            .enum BADFD
     2343            .enum BADIP
     2344        .ends
     2345        .scope Result
     2346            .enum NONE
     2347            .enum INCOMPLETE
     2348            .enum FULL
     2349        .ends
     2350)ffDXD",
     2351        BinaryFormat::AMD, GPUDeviceType::CAPE_VERDE, false, { }, { },
     2352        {
     2353            { ".", 0, 0, 0, true, false, false, 0, 0 },
     2354            { "Error::BADFD", 1, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2355            { "Error::BADIP", 2, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2356            { "Error::OK", 0, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2357            { "Result::FULL", 2, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2358            { "Result::INCOMPLETE", 1, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2359            { "Result::NONE", 0, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2360            { "ala", 100, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2361            { "beta", 102, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2362            { "joan", 101, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2363            { "sym1", 0, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2364            { "sym2", 1, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2365            { "sym6", 2, ASMSECT_ABS, 0, true, true, false, 0, 0 },
     2366            { "xxx", 3, ASMSECT_ABS, 0, true, true, false, 0, 0 }
     2367        }, true, "", ""
     2368    },
     2369    {   // 82 - use enums - errors
     2370        R"ffDXD(mydef = 1
     2371        .enum mydef,mydef2
     2372        .enum >xxx, doOne, doSecond
     2373)ffDXD",
     2374        BinaryFormat::AMD, GPUDeviceType::CAPE_VERDE, false, { }, { },
     2375        {
     2376            { ".", 0, 0, 0, true, false, false, 0, 0 },
     2377            { "mydef", 1, ASMSECT_ABS, 0, true, false, false, 0, 0 },
     2378            { "mydef2", 0, ASMSECT_ABS, 0, true, true, false, 0, 0 }
     2379        }, false,
     2380        "test.s:2:15: Error: Symbol 'mydef' is already defined\n"
     2381        "test.s:3:16: Error: Expression have unresolved symbol 'xxx'\n",
     2382        ""
     2383    },
    23362384    { nullptr }
    23372385};
Note: See TracChangeset for help on using the changeset viewer.