@@ -107,10 +107,15 @@ class SparcAsmParser : public MCTargetAsmParser {
107
107
108
108
ParseStatus parseBranchModifiers (OperandVector &Operands);
109
109
110
+ ParseStatus parseExpression (int64_t &Val);
111
+
110
112
// Helper function for dealing with %lo / %hi in PIC mode.
111
113
const SparcMCExpr *adjustPICRelocation (SparcMCExpr::VariantKind VK,
112
114
const MCExpr *subExpr);
113
115
116
+ // Helper function to see if current token can start an expression.
117
+ bool isPossibleExpression (const AsmToken &Token);
118
+
114
119
// returns true if Tok is matched to a register and returns register in RegNo.
115
120
MCRegister matchRegisterName (const AsmToken &Tok, unsigned &RegKind);
116
121
@@ -1085,32 +1090,35 @@ ParseStatus SparcAsmParser::parseASITag(OperandVector &Operands) {
1085
1090
SMLoc E = Parser.getTok ().getEndLoc ();
1086
1091
int64_t ASIVal = 0 ;
1087
1092
1088
- if (is64Bit () && (getLexer ().getKind () == AsmToken::Hash)) {
1089
- // For now we only support named tags for 64-bit/V9 systems.
1090
- // TODO: add support for 32-bit/V8 systems.
1091
- SMLoc TagStart = getLexer ().peekTok (false ).getLoc ();
1092
- Parser.Lex (); // Eat the '#'.
1093
- auto ASIName = Parser.getTok ().getString ();
1094
- auto ASITag = SparcASITag::lookupASITagByName (ASIName);
1095
- if (!ASITag)
1096
- ASITag = SparcASITag::lookupASITagByAltName (ASIName);
1097
- Parser.Lex (); // Eat the identifier token.
1093
+ if (getLexer ().getKind () != AsmToken::Hash) {
1094
+ // If the ASI tag provided is not a named tag, then it
1095
+ // must be a constant expression.
1096
+ ParseStatus ParseExprStatus = parseExpression (ASIVal);
1097
+ if (!ParseExprStatus.isSuccess ())
1098
+ return ParseExprStatus;
1098
1099
1099
- if (!ASITag)
1100
- return Error (TagStart, " unknown ASI tag" );
1101
-
1102
- ASIVal = ASITag->Encoding ;
1103
- } else if (!getParser ().parseAbsoluteExpression (ASIVal)) {
1104
1100
if (!isUInt<8 >(ASIVal))
1105
1101
return Error (S, " invalid ASI number, must be between 0 and 255" );
1106
- } else {
1107
- return Error (
1108
- S, is64Bit ()
1109
- ? " malformed ASI tag, must be %asi, a constant integer "
1110
- " expression, or a named tag"
1111
- : " malformed ASI tag, must be a constant integer expression" );
1102
+
1103
+ Operands.push_back (SparcOperand::CreateASITag (ASIVal, S, E));
1104
+ return ParseStatus::Success;
1112
1105
}
1113
1106
1107
+ // For now we only support named tags for 64-bit/V9 systems.
1108
+ // TODO: add support for 32-bit/V8 systems.
1109
+ SMLoc TagStart = getLexer ().peekTok (false ).getLoc ();
1110
+ Parser.Lex (); // Eat the '#'.
1111
+ const StringRef ASIName = Parser.getTok ().getString ();
1112
+ const SparcASITag::ASITag *ASITag = SparcASITag::lookupASITagByName (ASIName);
1113
+ if (!ASITag)
1114
+ ASITag = SparcASITag::lookupASITagByAltName (ASIName);
1115
+ Parser.Lex (); // Eat the identifier token.
1116
+
1117
+ if (!ASITag)
1118
+ return Error (TagStart, " unknown ASI tag" );
1119
+
1120
+ ASIVal = ASITag->Encoding ;
1121
+
1114
1122
Operands.push_back (SparcOperand::CreateASITag (ASIVal, S, E));
1115
1123
return ParseStatus::Success;
1116
1124
}
@@ -1120,35 +1128,32 @@ ParseStatus SparcAsmParser::parsePrefetchTag(OperandVector &Operands) {
1120
1128
SMLoc E = Parser.getTok ().getEndLoc ();
1121
1129
int64_t PrefetchVal = 0 ;
1122
1130
1123
- switch (getLexer ().getKind ()) {
1124
- case AsmToken::LParen:
1125
- case AsmToken::Integer:
1126
- case AsmToken::Identifier:
1127
- case AsmToken::Plus:
1128
- case AsmToken::Minus:
1129
- case AsmToken::Tilde:
1130
- if (getParser ().parseAbsoluteExpression (PrefetchVal) ||
1131
- !isUInt<5 >(PrefetchVal))
1132
- return Error (S, " invalid prefetch number, must be between 0 and 31" );
1133
- break ;
1134
- case AsmToken::Hash: {
1135
- SMLoc TagStart = getLexer ().peekTok (false ).getLoc ();
1136
- Parser.Lex (); // Eat the '#'.
1137
- const StringRef PrefetchName = Parser.getTok ().getString ();
1138
- const SparcPrefetchTag::PrefetchTag *PrefetchTag =
1139
- SparcPrefetchTag::lookupPrefetchTagByName (PrefetchName);
1140
- Parser.Lex (); // Eat the identifier token.
1131
+ if (getLexer ().getKind () != AsmToken::Hash) {
1132
+ // If the prefetch tag provided is not a named tag, then it
1133
+ // must be a constant expression.
1134
+ ParseStatus ParseExprStatus = parseExpression (PrefetchVal);
1135
+ if (!ParseExprStatus.isSuccess ())
1136
+ return ParseExprStatus;
1141
1137
1142
- if (!PrefetchTag )
1143
- return Error (TagStart , " unknown prefetch tag " );
1138
+ if (!isUInt< 8 >(PrefetchVal) )
1139
+ return Error (S , " invalid prefetch number, must be between 0 and 31 " );
1144
1140
1145
- PrefetchVal = PrefetchTag->Encoding ;
1146
- break ;
1147
- }
1148
- default :
1149
- return ParseStatus::NoMatch;
1141
+ Operands.push_back (SparcOperand::CreatePrefetchTag (PrefetchVal, S, E));
1142
+ return ParseStatus::Success;
1150
1143
}
1151
1144
1145
+ SMLoc TagStart = getLexer ().peekTok (false ).getLoc ();
1146
+ Parser.Lex (); // Eat the '#'.
1147
+ const StringRef PrefetchName = Parser.getTok ().getString ();
1148
+ const SparcPrefetchTag::PrefetchTag *PrefetchTag =
1149
+ SparcPrefetchTag::lookupPrefetchTagByName (PrefetchName);
1150
+ Parser.Lex (); // Eat the identifier token.
1151
+
1152
+ if (!PrefetchTag)
1153
+ return Error (TagStart, " unknown prefetch tag" );
1154
+
1155
+ PrefetchVal = PrefetchTag->Encoding ;
1156
+
1152
1157
Operands.push_back (SparcOperand::CreatePrefetchTag (PrefetchVal, S, E));
1153
1158
return ParseStatus::Success;
1154
1159
}
@@ -1230,8 +1235,12 @@ ParseStatus SparcAsmParser::parseOperand(OperandVector &Operands,
1230
1235
// Parse an optional address-space identifier after the address.
1231
1236
// This will be either an immediate constant expression, or, on 64-bit
1232
1237
// processors, the %asi register.
1233
- if (is64Bit () && getLexer ().is (AsmToken::Percent)) {
1238
+ if (getLexer ().is (AsmToken::Percent)) {
1234
1239
SMLoc S = Parser.getTok ().getLoc ();
1240
+ if (!is64Bit ())
1241
+ return Error (
1242
+ S, " malformed ASI tag, must be a constant integer expression" );
1243
+
1235
1244
Parser.Lex (); // Eat the %.
1236
1245
const AsmToken Tok = Parser.getTok ();
1237
1246
if (Tok.is (AsmToken::Identifier) && Tok.getString () == " asi" ) {
@@ -1360,6 +1369,15 @@ ParseStatus SparcAsmParser::parseBranchModifiers(OperandVector &Operands) {
1360
1369
return ParseStatus::Success;
1361
1370
}
1362
1371
1372
+ ParseStatus SparcAsmParser::parseExpression (int64_t &Val) {
1373
+ AsmToken Tok = getLexer ().getTok ();
1374
+
1375
+ if (!isPossibleExpression (Tok))
1376
+ return ParseStatus::NoMatch;
1377
+
1378
+ return getParser ().parseAbsoluteExpression (Val);
1379
+ }
1380
+
1363
1381
#define GET_REGISTER_MATCHER
1364
1382
#include " SparcGenAsmMatcher.inc"
1365
1383
@@ -1590,6 +1608,20 @@ bool SparcAsmParser::matchSparcAsmModifiers(const MCExpr *&EVal,
1590
1608
return true ;
1591
1609
}
1592
1610
1611
+ bool SparcAsmParser::isPossibleExpression (const AsmToken &Token) {
1612
+ switch (Token.getKind ()) {
1613
+ case AsmToken::LParen:
1614
+ case AsmToken::Integer:
1615
+ case AsmToken::Identifier:
1616
+ case AsmToken::Plus:
1617
+ case AsmToken::Minus:
1618
+ case AsmToken::Tilde:
1619
+ return true ;
1620
+ default :
1621
+ return false ;
1622
+ }
1623
+ }
1624
+
1593
1625
extern " C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcAsmParser () {
1594
1626
RegisterMCAsmParser<SparcAsmParser> A (getTheSparcTarget ());
1595
1627
RegisterMCAsmParser<SparcAsmParser> B (getTheSparcV9Target ());
0 commit comments