@@ -494,40 +494,66 @@ static SILLinkage resolveSILLinkage(llvm::Optional<SILLinkage> linkage,
494
494
}
495
495
}
496
496
497
- // Returns false if no optional exists. Returns true on both success and
498
- // failure. On success, the Result string is nonempty. If the optional is
499
- // assigned to an integer value, \p value contains the parsed value. Otherwise,
500
- // value is set to the maximum uint64_t.
501
- static bool parseSILOptional (StringRef &Result, uint64_t &value, SourceLoc &Loc,
502
- SILParser &SP) {
503
- if (!SP.P .consumeIf (tok::l_square))
504
- return false ;
497
+ namespace {
505
498
506
- value = ~ uint64_t( 0 ) ;
499
+ using SILOptionalAttrValue = std::optional<std::variant< uint64_t , StringRef>> ;
507
500
508
- Identifier Id;
509
- if (SP.parseSILIdentifier (Id, Loc, diag::expected_in_attribute_list))
501
+ } // namespace
502
+
503
+ // / Returns false if no optional exists. Returns true on both success and
504
+ // / failure. On success, the Result string is nonempty. If the optional is
505
+ // / assigned to an integer value using an equal, \p value contains the parsed
506
+ // / value. Otherwise, value is set to the maximum uint64_t.
507
+ // /
508
+ // / Example: [alignment=$NUM]
509
+ static bool parseSILOptional (StringRef &parsedName, SourceLoc &parsedNameLoc,
510
+ SILOptionalAttrValue &parsedValue,
511
+ SourceLoc &parsedValueLoc, SILParser &parser) {
512
+ if (!parser.P .consumeIf (tok::l_square))
513
+ return false ;
514
+
515
+ Identifier parsedNameId;
516
+ if (parser.parseSILIdentifier (parsedNameId, parsedNameLoc,
517
+ diag::expected_in_attribute_list))
510
518
return true ;
519
+ parsedName = parsedNameId.str ();
511
520
512
- if (SP.P .consumeIf (tok::equal)) {
513
- if (SP.parseInteger (value, diag::expected_in_attribute_list))
514
- return true ;
521
+ uint64_t parsedIntValue = ~uint64_t (0 );
522
+ Identifier parsedStringId;
523
+ if (parser.P .consumeIf (tok::equal)) {
524
+ auto currentTok = parser.P .Tok ;
525
+ parsedValueLoc = currentTok.getLoc ();
526
+
527
+ if (currentTok.is (tok::integer_literal)) {
528
+ if (parser.parseInteger (parsedIntValue,
529
+ diag::expected_in_attribute_list)) {
530
+ return true ;
531
+ }
532
+ parsedValue = parsedIntValue;
533
+ } else {
534
+ if (parser.parseSILIdentifier (parsedStringId, parsedValueLoc,
535
+ diag::expected_in_attribute_list)) {
536
+ return true ;
537
+ }
538
+ parsedValue = parsedStringId.str ();
539
+ }
515
540
}
516
- if (SP.P .parseToken (tok::r_square, diag::expected_in_attribute_list))
541
+
542
+ if (parser.P .parseToken (tok::r_square, diag::expected_in_attribute_list))
517
543
return true ;
518
544
519
- Result = Id.str ();
520
545
return true ;
521
546
}
522
547
523
548
static bool parseSILOptional (StringRef &Result, SourceLoc &Loc, SILParser &SP) {
524
- uint64_t value;
525
- return parseSILOptional (Result, value, Loc, SP);
549
+ SILOptionalAttrValue value;
550
+ SourceLoc valueLoc;
551
+ return parseSILOptional (Result, Loc, value, valueLoc, SP);
526
552
}
527
553
528
- static bool parseSILOptional (StringRef &Result , SILParser &SP) {
529
- SourceLoc Loc ;
530
- return parseSILOptional (Result, Loc , SP);
554
+ static bool parseSILOptional (StringRef &attrName , SILParser &SP) {
555
+ SourceLoc attrLoc ;
556
+ return parseSILOptional (attrName, attrLoc , SP);
531
557
}
532
558
533
559
// / Parse an option attribute ('[' Expected ']')?
@@ -4056,8 +4082,9 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
4056
4082
bool isStrict = false ;
4057
4083
bool isInvariant = false ;
4058
4084
llvm::MaybeAlign alignment;
4059
- uint64_t parsedValue = 0 ;
4060
- while (parseSILOptional (attr, parsedValue, ToLoc, *this )) {
4085
+ SILOptionalAttrValue parsedValue;
4086
+ SourceLoc parsedValueLoc;
4087
+ while (parseSILOptional (attr, ToLoc, parsedValue, parsedValueLoc, *this )) {
4061
4088
if (attr.empty ())
4062
4089
return true ;
4063
4090
@@ -4068,7 +4095,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
4068
4095
isInvariant = true ;
4069
4096
4070
4097
if (attr.equals (" align" ))
4071
- alignment = llvm::Align (parsedValue);
4098
+ alignment = llvm::Align (std::get< uint64_t >(* parsedValue) );
4072
4099
}
4073
4100
4074
4101
if (parseSILType (Ty) || parseSILDebugLocation (InstLoc, B))
0 commit comments