23 #ifndef __CLRX_ASMDEFS_H__ 24 #define __CLRX_ASMDEFS_H__ 26 #include <CLRX/Config.h> 31 #include <unordered_map> 49 enum : AsmExprTargetType
69 GCNTGT_SMEMOFFSETVEGA,
154 cxuint onceDefined:1;
171 refCount(1), sectionId(
ASMSECT_ABS), info(0), other(0), hasValue(false),
172 onceDefined(_onceDefined), resolving(false), base(false), snapshot(false),
173 regRange(false), value(0), size(0), expression(nullptr)
177 refCount(1), sectionId(
ASMSECT_ABS), info(0), other(0), hasValue(false),
178 onceDefined(_onceDefined), resolving(false), base(_base),
179 snapshot(false), regRange(false), value(0), size(0), expression(expr)
182 explicit AsmSymbol(cxuint _sectionId, uint64_t _value,
bool _onceDefined =
false) :
183 refCount(1), sectionId(_sectionId), info(0), other(0), hasValue(true),
184 onceDefined(_onceDefined), resolving(false), base(false), snapshot(false),
185 regRange(false), value(_value), size(0), expression(nullptr)
192 { occurrencesInExprs.push_back({expr, argIndex, opIndex}); }
194 void removeOccurrenceInExpr(
AsmExpression* expr,
size_t argIndex,
size_t opIndex);
196 void clearOccurrencesInExpr();
201 {
return hasValue || expression!=
nullptr; }
229 : type(_type), sectionId(_sectionId), offset(_offset)
280 class TempSymbolSnapshotMap;
285 bool relativeSymOccurs;
288 std::unique_ptr<LineCol[]> messagePositions;
289 std::unique_ptr<AsmExprArg[]> args;
294 pos.
lineNo = messagePositions[msgPosIndex].lineNo;
295 pos.
colNo = messagePositions[msgPosIndex].colNo;
299 static bool makeSymbolSnapshot(
Assembler& assembler,
300 TempSymbolSnapshotMap* snapshotMap,
const AsmSymbolEntry& symEntry,
301 AsmSymbolEntry*& outSymEntry,
const AsmSourcePos* topParentSourcePos);
304 void setParams(
size_t symOccursNum,
bool relativeSymOccurs,
305 size_t _opsNum,
const AsmExprOp* ops,
size_t opPosNum,
const LineCol* opPos,
306 size_t argsNum,
const AsmExprArg* args,
bool baseExpr =
false);
310 size_t opsNum,
size_t opPosNum,
size_t argsNum,
bool baseExpr =
false);
313 size_t opsNum,
const AsmExprOp* ops,
size_t opPosNum,
315 bool baseExpr =
false);
321 {
return ops.empty(); }
328 { target = _target; }
338 {
return evaluate(assembler, 0, ops.size(), value, sectionId); }
349 bool evaluate(
Assembler& assembler,
size_t opStart,
size_t opEnd,
350 uint64_t& value, cxuint& sectionId)
const;
361 bool makeBase =
false,
bool dontResolveSymbolsLater =
false);
372 bool makeBase =
false,
bool dontResolveSymbolsLater =
false);
376 {
return (AsmExprOp::FIRST_ARG <= op && op <= AsmExprOp::LAST_ARG); }
388 {
return symOccursNum; }
391 {
return relativeSymOccurs; }
394 {
return --symOccursNum!=0; }
404 {
return args.get(); }
407 {
return sourcePos; }
410 size_t toTop(
size_t opIndex)
const;
413 static bool makeSymbolSnapshot(
Assembler& assembler,
const AsmSymbolEntry& symEntry,
414 AsmSymbolEntry*& outSymEntry,
const AsmSourcePos* parentExprSourcePos);
419 if (base)
delete expression;
420 clearOccurrencesInExpr();
435 uint64_t value, cxuint sectionId)
438 args[occurrence.
argIndex].relValue.value = value;
439 args[occurrence.
argIndex].relValue.sectionId = sectionId;
441 relativeSymOccurs =
true;
456 GCNFIELD_SMRD_SOFFSET,
469 GCNFIELD_VINTRP_VSRC0,
470 GCNFIELD_VINTRP_VDST,
478 GCNFIELD_M_VDATALAST,
489 GCNFIELD_FLAT_VDSTLAST,
490 GCNFIELD_DPPSDWA_SRC0,
491 GCNFIELD_DPPSDWA_SSRC0,
512 {
return regVar == r2.
regVar && index == r2.
index; }
515 {
return regVar == r2.
regVar && index == r2.
index; }
591 typedef std::unordered_map<CString, RefPtr<const AsmMacro> >
AsmMacroMap;
596 typedef std::unordered_map<CString, AsmScope*>
AsmScopeMap;
609 std::unordered_map<AsmScope*, std::list<AsmScope*>::iterator>
usedScopesSet;
613 bool _temporary =
false)
614 : parent(_parent), symbolMap(_symbolMap), temporary(_temporary)
618 : parent(_parent), temporary(_temporary)
624 void startUsingScope(
AsmScope* scope);
626 void stopUsingScope(
AsmScope* scope);
631 usedScopesSet.clear();
634 void deleteSymbolsRecursively();
657 Flags _flags, uint64_t _alignment, uint64_t _size = 0)
658 : name(_name), kernelId(_kernelId), type(_type), flags(_flags),
659 alignment(_alignment), size(_size)
669 { codeFlow.push_back(entry); }
673 {
return ((flags&ASMSECT_WRITEABLE) != 0) ? content.size() : size; }
684 void openCodeRegion(
size_t offset);
686 void closeCodeRegion(
size_t offset);
696 struct hash<
CLRX::AsmSingleVReg>
704 std::hash<const CLRX::AsmRegVar*> h1;
705 std::hash<uint16_t> h2;
AsmRegVarMap regVarMap
regvar map
Definition: AsmDefs.h:603
common definitions for assembler and disassembler
size_t target
target jump addreses
Definition: AsmDefs.h:586
main class of assembler
Definition: Assembler.h:401
AsmExprTargetType type
type of target
Definition: AsmDefs.h:212
non copyable and non movable base structure (class)
Definition: Utilities.h:43
assembler expression class
Definition: AsmDefs.h:277
AsmSymbolEntry * symbol
symbol
Definition: AsmDefs.h:270
AsmSymbol(bool _onceDefined=false)
empty constructor
Definition: AsmDefs.h:170
kernel entry structure
Definition: AsmDefs.h:677
uint32_t Flags
type for declaring various flags
Definition: Utilities.h:97
std::unordered_map< CString, AsmRegVar > AsmRegVarMap
regvar map
Definition: AsmDefs.h:519
AsmExpression * expression
expression of symbol (if not resolved)
Definition: AsmDefs.h:162
bool operator==(const AsmExprSymbolOccurrence &b) const
comparison operator
Definition: AsmDefs.h:139
cxuint kernelId
kernel id (optional)
Definition: AsmDefs.h:643
AsmRegVarMap::value_type AsmRegVarEntry
regvar entry
Definition: AsmDefs.h:521
target is 32-bit word
Definition: AsmDefs.h:54
target is 64-bit word
Definition: AsmDefs.h:55
AsmSymbolEntry * symbol
symbol entry (if ASMXTGT_SYMBOL)
Definition: AsmDefs.h:215
target for assembler expression
Definition: AsmDefs.h:210
cxbyte rwFlags
1 - read, 2 - write
Definition: AsmDefs.h:552
~AsmSymbol()
destructor
Definition: AsmDefs.h:417
size_t operator()(const CLRX::AsmSingleVReg &r1) const
a calling operator
Definition: AsmDefs.h:702
AsmExprOp
assembler expression operator
Definition: AsmDefs.h:80
assembler section
Definition: AsmDefs.h:640
AsmExprTarget()
empty constructor
Definition: AsmDefs.h:225
for internal usage
Definition: AsmDefs.h:529
size_t offset
offset in section
Definition: AsmDefs.h:535
code flow entry
Definition: AsmDefs.h:56
static AsmExprTarget symbolTarget(AsmSymbolEntry *entry)
make symbol target for expression
Definition: AsmDefs.h:233
assembler scope for symbol, macros, regvars
Definition: AsmDefs.h:599
Regvar info structure.
Definition: AsmDefs.h:498
cxbyte info
ELF symbol info.
Definition: AsmDefs.h:151
cxuint type
scalar/vector/other
Definition: AsmDefs.h:500
std::vector< AsmCodeFlowEntry > codeFlow
code flow info
Definition: AsmDefs.h:651
const AsmExprTarget & getTarget() const
get targer of expression
Definition: AsmDefs.h:384
uint16_t rstart
register start
Definition: AsmDefs.h:549
signed (arithmetic) shift right
void addCodeFlowEntry(const AsmCodeFlowEntry &entry)
add code flow entry to this section
Definition: AsmDefs.h:668
static bool isUnaryOp(AsmExprOp op)
return true if is unary op
Definition: AsmDefs.h:378
uint16_t index
index of regvar array
Definition: AsmDefs.h:508
AsmSourcePos sourcePos
source position of definition
Definition: AsmDefs.h:680
size_t getSymOccursNum() const
get number of symbol occurrences in expression
Definition: AsmDefs.h:387
std::list< AsmScope * > usedScopes
list of used scope in this scope
Definition: AsmDefs.h:606
assembler symbol occurrence in expression
Definition: AsmDefs.h:132
regvar usage (internal)
Definition: AsmDefs.h:546
std::unordered_map< CString, AsmScope * > AsmScopeMap
type definition of scope's map
Definition: AsmDefs.h:593
cxuint sectionId
section id
Definition: AsmDefs.h:150
void addOccurrenceInExpr(AsmExpression *expr, size_t argIndex, size_t opIndex)
adds occurrence in expression
Definition: AsmDefs.h:191
ColNo colNo
column number
Definition: AsmSource.h:157
AsmSymbol(cxuint _sectionId, uint64_t _value, bool _onceDefined=false)
constructor with value and section id
Definition: AsmDefs.h:182
void stopUsingScopes()
remove all usings
Definition: AsmDefs.h:628
cxuint RelocType
relocation type
Definition: Commons.h:32
void setTarget(AsmExprTarget _target)
set target of expression
Definition: AsmDefs.h:327
for internal usage
Definition: AsmDefs.h:528
std::unordered_map< AsmScope *, std::list< AsmScope * >::iterator > usedScopesSet
set of used scopes in this scope
Definition: AsmDefs.h:609
size_t cflowId
cflow index of destination
Definition: AsmDefs.h:220
return from procedure
Definition: AsmDefs.h:577
AsmScope * parent
parent scope
Definition: AsmDefs.h:601
line and column
Definition: AsmSource.h:44
bool isEmpty() const
return true if expression is empty
Definition: AsmDefs.h:320
std::unordered_map< CString, AsmSymbol > AsmSymbolMap
assembler symbol map
Definition: AsmDefs.h:205
AsmScope(AsmScope *_parent, const AsmSymbolMap &_symbolMap, bool _temporary=false)
constructor
Definition: AsmDefs.h:612
cxuint sectionId
sectionId
Definition: AsmDefs.h:430
LineNo lineNo
line number of top-most source
Definition: AsmSource.h:156
size_t offset
offset of relocation
Definition: AsmDefs.h:267
AsmRegField regField
place in instruction
Definition: AsmDefs.h:551
absolute section id
Definition: AsmFormats.h:79
uint64_t value
value of symbol
Definition: AsmDefs.h:159
AsmExprTarget(AsmExprTargetType _type, cxuint _sectionId, size_t _offset)
constructor to create custom target
Definition: AsmDefs.h:228
single regvar id
Definition: AsmDefs.h:505
cxbyte rwFlags
1 - read, 2 - write, other flags
Definition: AsmDefs.h:560
uint16_t rend
register end
Definition: AsmDefs.h:550
assembler relocation
Definition: AsmDefs.h:264
cxbyte rwFlags
1 - read, 2 - write
Definition: AsmDefs.h:540
bool temporary
true if temporary
Definition: AsmDefs.h:605
size_t opIndex
operator index
Definition: AsmDefs.h:136
const char * name
name of kernel
Definition: AsmDefs.h:679
AsmSectionType
assembler section type
Definition: AsmFormats.h:46
cxbyte rwFlags
rw flags and others
Definition: AsmDefs.h:568
internal structure for regusage
Definition: AsmDefs.h:564
std::unordered_map< CString, RefPtr< const AsmMacro > > AsmMacroMap
assembler macro map
Definition: AsmDefs.h:591
main namespace
Definition: AsmDefs.h:38
AsmSymbolEntry * symbol
if symbol
Definition: AsmDefs.h:426
absolute symbol without defined value
void substituteOccurrence(AsmExprSymbolOccurrence occurrence, uint64_t value, cxuint sectionId=ASMSECT_ABS)
substitute occurrence in expression by value
Definition: AsmDefs.h:434
const AsmRegVar * regVar
regvar
Definition: AsmDefs.h:507
uint16_t rstart
register start
Definition: AsmDefs.h:566
static bool isArg(AsmExprOp op)
return true if is argument op
Definition: AsmDefs.h:375
bool unrefSymOccursNum()
unreference symbol occurrences in expression (used internally)
Definition: AsmDefs.h:393
bool operator!=(const AsmSingleVReg &r2) const
not equal operator
Definition: AsmDefs.h:514
internal structure for regusage
Definition: AsmDefs.h:557
static bool isBinaryOp(AsmExprOp op)
return true if is binary op
Definition: AsmDefs.h:381
code end
Definition: AsmDefs.h:579
target is byte
Definition: AsmDefs.h:52
uint64_t size
size of symbol
Definition: AsmDefs.h:160
size_t getSize() const
get section's size
Definition: AsmDefs.h:672
AsmScope(AsmScope *_parent=nullptr, bool _temporary=false)
constructor
Definition: AsmDefs.h:617
cxbyte AsmExprTargetType
expression target type (one byte)
Definition: AsmDefs.h:47
AsmCodeFlowType type
type of code flow entry
Definition: AsmDefs.h:587
uint16_t rend
register end
Definition: AsmDefs.h:538
uint64_t size
section size
Definition: AsmDefs.h:647
std::vector< AsmExprSymbolOccurrence > occurrencesInExprs
Definition: AsmDefs.h:167
target is 16-bit word
Definition: AsmDefs.h:53
std::vector< cxbyte > content
content of section
Definition: AsmDefs.h:648
AsmSymbolMap::value_type AsmSymbolEntry
assembler symbol entry
Definition: AsmDefs.h:207
Flags flags
section flags
Definition: AsmDefs.h:645
const AsmRegVar * regVar
if null, then usage of called register
Definition: AsmDefs.h:548
target is symbol
Definition: AsmDefs.h:51
uint64_t value
value
Definition: AsmDefs.h:427
AsmRegField regField
place in instruction
Definition: AsmDefs.h:559
cxuint refCount
reference counter (for internal use only)
Definition: AsmDefs.h:149
uint16_t rend
register end
Definition: AsmDefs.h:567
size_t offset
offset of destination
Definition: AsmDefs.h:219
uint16_t size
in regs
Definition: AsmDefs.h:501
size_t offset
offset where is this entry
Definition: AsmDefs.h:585
size_t argIndex
argument index
Definition: AsmDefs.h:135
cxuint sectionId
section id where relocation is present
Definition: AsmDefs.h:266
cxuint sectionId
section id of destination
Definition: AsmDefs.h:217
utilities for other libraries and programs
const Array< AsmExprOp > & getOps() const
get operators list
Definition: AsmDefs.h:400
std::unique_ptr< ISAUsageHandler > usageHandler
usage handler
Definition: AsmDefs.h:650
AsmSection(const char *_name, cxuint _kernelId, AsmSectionType _type, Flags _flags, uint64_t _alignment, uint64_t _size=0)
constructor
Definition: AsmDefs.h:656
RelocType type
relocation type
Definition: AsmDefs.h:268
uint64_t alignment
section alignment
Definition: AsmDefs.h:646
static AsmExprTarget dataTarget(cxuint sectionId, size_t offset)
make n-bit word target for expression
Definition: AsmDefs.h:252
const AsmRegVar * regVar
if null, then usage of called register
Definition: AsmDefs.h:536
AsmSymbolMap symbolMap
symbol map
Definition: AsmDefs.h:602
AsmScopeMap scopeMap
scope map
Definition: AsmDefs.h:604
code start
Definition: AsmDefs.h:578
AsmSectionType type
type of section
Definition: AsmDefs.h:644
regvar usage in code
Definition: AsmDefs.h:533
uint16_t rstart
register start
Definition: AsmDefs.h:537
call of procedure
Definition: AsmDefs.h:576
AsmSymbol(AsmExpression *expr, bool _onceDefined=false, bool _base=false)
constructor with expression
Definition: AsmDefs.h:176
for internal usage (regtype)
Definition: AsmDefs.h:527
static AsmExprTarget codeFlowTarget(cxuint sectionId, size_t cflowIndex)
make code flow target for expression
Definition: AsmDefs.h:241
register will be read
Definition: AsmDefs.h:524
cxbyte align
register alignment
Definition: AsmDefs.h:553
code flow entry
Definition: AsmDefs.h:583
cxbyte other
ELF symbol other.
Definition: AsmDefs.h:152
jump
Definition: AsmDefs.h:574
std::vector< std::pair< size_t, size_t > > codeRegions
code regions
Definition: AsmDefs.h:681
const char * name
section name
Definition: AsmDefs.h:642
an assembler sources handling
AsmCodeFlowType
code flow type
Definition: AsmDefs.h:572
cxuint relSectionId
section for which relocation is defined
Definition: AsmDefs.h:271
assembler symbol structure
Definition: AsmDefs.h:147
bool useRegMode
if RVU from useReg pseudo-ops
Definition: AsmDefs.h:542
bool isDefined() const
return true if symbol defined (have value or expression)
Definition: AsmDefs.h:200
register will be written
Definition: AsmDefs.h:525
cxbyte AsmRegField
type of register field
Definition: AsmDefs.h:445
const AsmExprArg * getArgs() const
get argument list
Definition: AsmDefs.h:403
ISA (register and regvar) Usage handler.
Definition: Assembler.h:62
size_t hasRelativeSymOccurs() const
get number of symbol occurrences in expression
Definition: AsmDefs.h:390
AsmRegField regField
place in instruction
Definition: AsmDefs.h:539
uint64_t addend
addend
Definition: AsmDefs.h:273
conditional jump
Definition: AsmDefs.h:575
AsmExpression * expression
target expression pointer
Definition: AsmDefs.h:134
bool evaluate(Assembler &assembler, uint64_t &value, cxuint §ionId) const
try to evaluate expression
Definition: AsmDefs.h:337
assembler expression argument
Definition: AsmDefs.h:424
access mask
Definition: AsmDefs.h:526
cxbyte align
register alignment
Definition: AsmDefs.h:541
bool operator==(const AsmSingleVReg &r2) const
equal operator
Definition: AsmDefs.h:511
CLRX::AsmSingleVReg argument_type
argument type
Definition: AsmDefs.h:698
const AsmSourcePos & getSourcePos() const
get source position
Definition: AsmDefs.h:406
assembler source position
Definition: AsmSource.h:152
std::size_t result_type
result type
Definition: AsmDefs.h:699