@@ -430,17 +430,17 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
430
430
" string must be lowercase" );
431
431
}
432
432
// Must start with a valid base ISA name.
433
- unsigned XLen;
434
- if (Arch.starts_with ( " rv32i " ) || Arch. starts_with ( " rv32e " ))
433
+ unsigned XLen = 0 ;
434
+ if (Arch.consume_front ( " rv32 " ))
435
435
XLen = 32 ;
436
- else if (Arch.starts_with ( " rv64i " ) || Arch. starts_with ( " rv64e " ))
436
+ else if (Arch.consume_front ( " rv64 " ))
437
437
XLen = 64 ;
438
- else
438
+
439
+ if (XLen == 0 || Arch.empty () || (Arch[0 ] != ' i' && Arch[0 ] != ' e' ))
439
440
return createStringError (errc::invalid_argument,
440
441
" arch string must begin with valid base ISA" );
442
+
441
443
std::unique_ptr<RISCVISAInfo> ISAInfo (new RISCVISAInfo (XLen));
442
- // Discard rv32/rv64 prefix.
443
- Arch = Arch.substr (4 );
444
444
445
445
// Each extension is of the form ${name}${major_version}p${minor_version}
446
446
// and separated by _. Split by _ and then extract the name and version
@@ -616,36 +616,39 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
616
616
ExperimentalExtensionVersionCheck, IgnoreUnknown);
617
617
}
618
618
619
- bool HasRV64 = Arch.starts_with (" rv64" );
620
619
// ISA string must begin with rv32 or rv64.
621
- if (!(Arch.starts_with (" rv32" ) || HasRV64) || (Arch.size () < 5 )) {
620
+ unsigned XLen = 0 ;
621
+ if (Arch.consume_front (" rv32" ))
622
+ XLen = 32 ;
623
+ else if (Arch.consume_front (" rv64" ))
624
+ XLen = 64 ;
625
+
626
+ if (XLen == 0 || Arch.empty ())
622
627
return createStringError (
623
628
errc::invalid_argument,
624
629
" string must begin with rv32{i,e,g} or rv64{i,e,g}" );
625
- }
626
630
627
- unsigned XLen = HasRV64 ? 64 : 32 ;
628
631
std::unique_ptr<RISCVISAInfo> ISAInfo (new RISCVISAInfo (XLen));
629
632
MapVector<std::string, RISCVISAUtils::ExtensionVersion,
630
633
std::map<std::string, unsigned >>
631
634
SeenExtMap;
632
635
633
636
// The canonical order specified in ISA manual.
634
637
// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
635
- char Baseline = Arch[ 4 ] ;
638
+ char Baseline = Arch. front () ;
636
639
637
640
// First letter should be 'e', 'i' or 'g'.
638
641
switch (Baseline) {
639
642
default :
640
643
return createStringError (errc::invalid_argument,
641
- " first letter after \' " + Arch. slice ( 0 , 4 ) +
644
+ " first letter after \' rv " + Twine (XLen ) +
642
645
" \' should be 'e', 'i' or 'g'" );
643
646
case ' e' :
644
647
case ' i' :
645
648
break ;
646
649
case ' g' :
647
650
// g expands to extensions in RISCVGImplications.
648
- if (Arch.size () > 5 && isDigit (Arch[5 ]))
651
+ if (Arch.size () > 1 && isDigit (Arch[1 ]))
649
652
return createStringError (errc::invalid_argument,
650
653
" version not supported for 'g'" );
651
654
break ;
@@ -655,8 +658,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
655
658
return createStringError (errc::invalid_argument,
656
659
" extension name missing after separator '_'" );
657
660
658
- // Skip rvxxx
659
- StringRef Exts = Arch.substr ( 5 );
661
+ // Skip baseline.
662
+ StringRef Exts = Arch.drop_front ( 1 );
660
663
661
664
unsigned Major, Minor, ConsumeLength;
662
665
if (Baseline == ' g' ) {
0 commit comments