@@ -430,17 +430,17 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
430430 " string must be lowercase" );
431431 }
432432 // 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 " ))
435435 XLen = 32 ;
436- else if (Arch.starts_with ( " rv64i " ) || Arch. starts_with ( " rv64e " ))
436+ else if (Arch.consume_front ( " rv64 " ))
437437 XLen = 64 ;
438- else
438+
439+ if (XLen == 0 || Arch.empty () || (Arch[0 ] != ' i' && Arch[0 ] != ' e' ))
439440 return createStringError (errc::invalid_argument,
440441 " arch string must begin with valid base ISA" );
442+
441443 std::unique_ptr<RISCVISAInfo> ISAInfo (new RISCVISAInfo (XLen));
442- // Discard rv32/rv64 prefix.
443- Arch = Arch.substr (4 );
444444
445445 // Each extension is of the form ${name}${major_version}p${minor_version}
446446 // and separated by _. Split by _ and then extract the name and version
@@ -616,36 +616,39 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
616616 ExperimentalExtensionVersionCheck, IgnoreUnknown);
617617 }
618618
619- bool HasRV64 = Arch.starts_with (" rv64" );
620619 // 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 ())
622627 return createStringError (
623628 errc::invalid_argument,
624629 " string must begin with rv32{i,e,g} or rv64{i,e,g}" );
625- }
626630
627- unsigned XLen = HasRV64 ? 64 : 32 ;
628631 std::unique_ptr<RISCVISAInfo> ISAInfo (new RISCVISAInfo (XLen));
629632 MapVector<std::string, RISCVISAUtils::ExtensionVersion,
630633 std::map<std::string, unsigned >>
631634 SeenExtMap;
632635
633636 // The canonical order specified in ISA manual.
634637 // Ref: Table 22.1 in RISC-V User-Level ISA V2.2
635- char Baseline = Arch[ 4 ] ;
638+ char Baseline = Arch. front () ;
636639
637640 // First letter should be 'e', 'i' or 'g'.
638641 switch (Baseline) {
639642 default :
640643 return createStringError (errc::invalid_argument,
641- " first letter after \' " + Arch. slice ( 0 , 4 ) +
644+ " first letter after \' rv " + Twine (XLen ) +
642645 " \' should be 'e', 'i' or 'g'" );
643646 case ' e' :
644647 case ' i' :
645648 break ;
646649 case ' g' :
647650 // g expands to extensions in RISCVGImplications.
648- if (Arch.size () > 5 && isDigit (Arch[5 ]))
651+ if (Arch.size () > 1 && isDigit (Arch[1 ]))
649652 return createStringError (errc::invalid_argument,
650653 " version not supported for 'g'" );
651654 break ;
@@ -655,8 +658,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
655658 return createStringError (errc::invalid_argument,
656659 " extension name missing after separator '_'" );
657660
658- // Skip rvxxx
659- StringRef Exts = Arch.substr ( 5 );
661+ // Skip baseline.
662+ StringRef Exts = Arch.drop_front ( 1 );
660663
661664 unsigned Major, Minor, ConsumeLength;
662665 if (Baseline == ' g' ) {
0 commit comments