Skip to content

Commit 0989367

Browse files
petechouigcbot
authored andcommitted
Make vISA able to handle STRLIT symbol in FADDR..
This change makes vISA to encode FADDR symbol as a STRLIT in .visaasm when needed and updates parser to accept IdentOrStringLit in FADDR.
1 parent e8f25ba commit 0989367

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

visa/CISA.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,8 +2128,8 @@ BranchInstruction: Predicate BRANCH_OP ExecSize IdentOrStringLit
21282128
$1, $3.emask, $3.exec_size,
21292129
$4.cisa_gen_opnd, (unsigned)$5, (unsigned)$6, CISAlineno);
21302130
}
2131-
// 1 2 3
2132-
| FADDR IDENT VecDstOperand_G_I
2131+
// 1 2 3
2132+
| FADDR IdentOrStringLit VecDstOperand_G_I
21332133
{
21342134
pBuilder->CISA_create_faddr_instruction($2, $3.cisa_gen_opnd, CISAlineno);
21352135
}

visa/IsaDisassembly.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,19 @@ static void encodeStringLiteral(std::stringstream &ss, const char *str) {
384384
ss << '"';
385385
}
386386

387+
// Return true if str matches IDENT: [[:alpha:]_][[:alnum:]_]*
388+
static bool isIdentifier(const char *str) {
389+
if (str == nullptr || *str == '\0')
390+
return false;
391+
if (!std::isalpha((unsigned char)str[0]) && str[0] != '_')
392+
return false;
393+
for (size_t i = 1; str[i] != '\0'; i++) {
394+
if (!std::isalnum((unsigned char)str[i]) && str[i] != '_')
395+
return false;
396+
}
397+
return true;
398+
}
399+
387400
std::string printAttributes(
388401
const print_format_provider_t* header,
389402
const int attr_count,
@@ -1053,7 +1066,12 @@ static std::string printInstructionControlFlow(
10531066
case ISA_FADDR:
10541067
{
10551068
/// symbol name in string
1056-
sstr << header->getString(getPrimitiveOperand<uint16_t>(inst, i++));
1069+
const char* sym = header->getString(getPrimitiveOperand<uint16_t>(inst, i++));
1070+
if (isIdentifier(sym)) {
1071+
sstr << sym;
1072+
} else {
1073+
encodeStringLiteral(sstr, sym);
1074+
}
10571075
/// dst
10581076
sstr << printOperand(header, inst, i++, opt);
10591077
break;

0 commit comments

Comments
 (0)