@@ -500,24 +500,6 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
500
500
return std::move (ISAInfo);
501
501
}
502
502
503
- static Error splitExtsByUnderscore (StringRef Exts,
504
- std::vector<std::string> &SplitExts) {
505
- SmallVector<StringRef, 8 > Split;
506
- if (Exts.empty ())
507
- return Error::success ();
508
-
509
- Exts.split (Split, " _" );
510
-
511
- for (auto Ext : Split) {
512
- if (Ext.empty ())
513
- return createStringError (errc::invalid_argument,
514
- " extension name missing after separator '_'" );
515
-
516
- SplitExts.push_back (Ext.str ());
517
- }
518
- return Error::success ();
519
- }
520
-
521
503
static Error processMultiLetterExtension (
522
504
StringRef RawExt,
523
505
MapVector<std::string, RISCVISAUtils::ExtensionVersion,
@@ -714,20 +696,25 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
714
696
Exts = Exts.drop_front (ConsumeLength);
715
697
Exts.consume_front (" _" );
716
698
717
- std::vector<std::string> SplitExts;
718
- if (auto E = splitExtsByUnderscore (Exts, SplitExts))
719
- return std::move (E);
699
+ SmallVector<StringRef, 8 > SplitExts;
700
+ // Only split if the string is not empty. Otherwise the split will push an
701
+ // empty string into the vector.
702
+ if (!Exts.empty ())
703
+ Exts.split (SplitExts, ' _' );
704
+
705
+ for (auto Ext : SplitExts) {
706
+ if (Ext.empty ())
707
+ return createStringError (errc::invalid_argument,
708
+ " extension name missing after separator '_'" );
720
709
721
- for (auto &Ext : SplitExts) {
722
- StringRef CurrExt = Ext;
723
- while (!CurrExt.empty ()) {
724
- if (RISCVISAUtils::AllStdExts.contains (CurrExt.front ())) {
710
+ do {
711
+ if (RISCVISAUtils::AllStdExts.contains (Ext.front ())) {
725
712
if (auto E = processSingleLetterExtension (
726
- CurrExt , SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
713
+ Ext , SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
727
714
ExperimentalExtensionVersionCheck))
728
715
return std::move (E);
729
- } else if (CurrExt .front () == ' z' || CurrExt .front () == ' s' ||
730
- CurrExt .front () == ' x' ) {
716
+ } else if (Ext .front () == ' z' || Ext .front () == ' s' ||
717
+ Ext .front () == ' x' ) {
731
718
// Handle other types of extensions other than the standard
732
719
// general purpose and standard user-level extensions.
733
720
// Parse the ISA string containing non-standard user-level
@@ -737,7 +724,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
737
724
// version number (major, minor) and are separated by a single
738
725
// underscore '_'. We do not enforce a canonical order for them.
739
726
if (auto E = processMultiLetterExtension (
740
- CurrExt , SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
727
+ Ext , SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
741
728
ExperimentalExtensionVersionCheck))
742
729
return std::move (E);
743
730
// Multi-letter extension must be seperate following extension with
@@ -747,9 +734,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
747
734
// FIXME: Could it be ignored by IgnoreUnknown?
748
735
return createStringError (errc::invalid_argument,
749
736
" invalid standard user-level extension '" +
750
- Twine (CurrExt .front ()) + " '" );
737
+ Twine (Ext .front ()) + " '" );
751
738
}
752
- }
739
+ } while (!Ext. empty ());
753
740
}
754
741
755
742
// Check all Extensions are supported.
0 commit comments