Changeset 3785 in CLRX


Ignore:
Timestamp:
Feb 13, 2018, 10:27:52 PM (16 months ago)
Author:
matszpk
Message:

CLRadeonExtender: Asm: Fixed stupid and old bug: replacement of unevaluated symbol value by value assignment causes
resolving symbol by using new value instead keeping old expression to resolve later.

Location:
CLRadeonExtender/trunk
Files:
4 edited

Legend:

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

    r3764 r3785  
    168168    cxuint snapshot:1;          ///< if symbol is snapshot
    169169    cxuint regRange:1;          ///< if symbol is register range
     170    cxuint detached:1;
    170171    uint64_t value;         ///< value of symbol
    171172    uint64_t size;          ///< size of symbol
     
    182183            refCount(1), sectionId(ASMSECT_ABS), info(0), other(0), hasValue(false),
    183184            onceDefined(_onceDefined), resolving(false), base(false), snapshot(false),
    184             regRange(false), value(0), size(0), expression(nullptr)
     185            regRange(false), detached(false), value(0), size(0), expression(nullptr)
    185186    { }
    186187    /// constructor with expression
     
    188189            refCount(1), sectionId(ASMSECT_ABS), info(0), other(0), hasValue(false),
    189190            onceDefined(_onceDefined), resolving(false), base(_base),
    190             snapshot(false), regRange(false), value(0), size(0), expression(expr)
     191            snapshot(false), regRange(false), detached(false),
     192            value(0), size(0), expression(expr)
    191193    { }
    192194    /// constructor with value and section id
     
    194196            refCount(1), sectionId(_sectionId), info(0), other(0), hasValue(true),
    195197            onceDefined(_onceDefined), resolving(false), base(false), snapshot(false),
    196             regRange(false), value(_value), size(0), expression(nullptr)
     198            regRange(false), detached(false), value(_value), size(0), expression(nullptr)
    197199    { }
    198200    /// destructor
     
    444446    void substituteOccurrence(AsmExprSymbolOccurrence occurrence, uint64_t value,
    445447                  cxuint sectionId = ASMSECT_ABS);
     448    /// replace symbol in expression
     449    void replaceOccurrenceSymbol(AsmExprSymbolOccurrence occurrence,
     450                    AsmSymbolEntry* newSymEntry);
    446451    /// get operators list
    447452    const Array<AsmExprOp>& getOps() const
     
    496501    if (sectionId != ASMSECT_ABS)
    497502        relativeSymOccurs = true;
     503}
     504
     505inline void AsmExpression::replaceOccurrenceSymbol(AsmExprSymbolOccurrence occurrence,
     506                    AsmSymbolEntry* newSymEntry)
     507{
     508    args[occurrence.argIndex].symbol = newSymEntry;
    498509}
    499510
  • CLRadeonExtender/trunk/CLRX/amdasm/Assembler.h

    r3764 r3785  
    654654   
    655655    bool resolveExprTarget(const AsmExpression* expr, uint64_t value, cxuint sectionId);
     656   
     657    void createTempSymEntryIfNeeded(AsmSymbolEntry& symEntry);
    656658   
    657659protected:
  • CLRadeonExtender/trunk/amdasm/Assembler.cpp

    r3773 r3785  
    13911391}
    13921392
     1393void Assembler::createTempSymEntryIfNeeded(AsmSymbolEntry& symEntry)
     1394{
     1395    if (symEntry.second.expression != nullptr &&
     1396                symEntry.second.expression->getSymOccursNum()!=0)
     1397    {   // create new symbol with this expression
     1398        std::unique_ptr<AsmSymbolEntry> newSymEntry(new AsmSymbolEntry(symEntry.first,
     1399                AsmSymbol(symEntry.second.expression, symEntry.second.onceDefined,
     1400                          symEntry.second.base)));
     1401        symEntry.second.expression->setTarget(
     1402                    AsmExprTarget::symbolTarget(newSymEntry.get()));
     1403        // replace in expression occurrences
     1404        for (const AsmExprSymbolOccurrence& occur: symEntry.second.occurrencesInExprs)
     1405            occur.expression->replaceOccurrenceSymbol(occur, newSymEntry.get());
     1406        newSymEntry->second.occurrencesInExprs = symEntry.second.occurrencesInExprs;
     1407        symEntry.second.occurrencesInExprs.clear();
     1408        newSymEntry->second.detached = true;
     1409        symbolSnapshots.insert(newSymEntry.release());
     1410    }
     1411}
     1412
    13931413bool Assembler::setSymbol(AsmSymbolEntry& symEntry, uint64_t value, cxuint sectionId)
    13941414{
     1415    createTempSymEntryIfNeeded(symEntry);
    13951416    symEntry.second.value = value;
    13961417    symEntry.second.expression = nullptr;
     
    14731494                            continue;
    14741495                        curSymEntry.second.resolving = true;
     1496                        curSymEntry.second.expression = nullptr;
    14751497                    }
    14761498                    // otherwise we ignore circular dependencies
     
    14881510            entry.first->second.occurrencesInExprs.clear();
    14891511            if (entry.first->second.snapshot && --(entry.first->second.refCount) == 0)
     1512            {
     1513                symbolSnapshots.erase(entry.first);
     1514                delete entry.first; // delete this symbol snapshot
     1515                entry.first = nullptr;
     1516            }
     1517            if (entry.first!=nullptr && entry.first->second.detached)
    14901518            {
    14911519                symbolSnapshots.erase(entry.first);
     
    16491677    if (tryLater) // set expression
    16501678    {
     1679        createTempSymEntryIfNeeded(symEntry);
    16511680        expr->setTarget(AsmExprTarget::symbolTarget(&symEntry));
    16521681        if (expr->getSymOccursNum() == 0)
  • CLRadeonExtender/trunk/tests/amdasm/AsmBasicsCases1.cpp

    r3575 r3785  
    24332433        "test.s:6:13: Error: Unknown instruction\n", ""
    24342434    },
     2435    /* 66 - evaluate old expressions of symbols */
     2436    {
     2437        R"ffDXD(.int aa0
     2438aa1=aa2
     2439aa0=aa1
     2440aa1=bb2
     2441bb0=aa1
     2442aa1=3
     2443aa2=6
     2444bb2=11)ffDXD",
     2445        BinaryFormat::AMD, GPUDeviceType::CAPE_VERDE, false, { },
     2446        { { nullptr, ASMKERN_GLOBAL, AsmSectionType::DATA,
     2447            { 0x06, 0x00, 0x00, 0x00 } } },
     2448        {
     2449            { ".", 4U, 0, 0U, true, false, false, 0, 0 },
     2450            { "aa0", 6U, ASMSECT_ABS, 0U, true, false, false, 0, 0 },
     2451            { "aa1", 3U, ASMSECT_ABS, 0U, true, false, false, 0, 0 },
     2452            { "aa2", 6U, ASMSECT_ABS, 0U, true, false, false, 0, 0 },
     2453            { "bb0", 11U, ASMSECT_ABS, 0U, true, false, false, 0, 0 },
     2454            { "bb2", 11U, ASMSECT_ABS, 0U, true, false, false, 0, 0 }
     2455        },
     2456        true, "", ""
     2457    },
    24352458    { nullptr }
    24362459};
Note: See TracChangeset for help on using the changeset viewer.