@@ -282,15 +282,17 @@ std::vector<std::string> RISCVISAInfo::toFeatures(bool AddAllExtensions,
282
282
return Features;
283
283
}
284
284
285
- static Error getStringErrorForInvalidExt (StringRef ExtName) {
285
+ static Error getError (const Twine &Message) {
286
+ return createStringError (errc::invalid_argument, Message);
287
+ }
288
+
289
+ static Error getErrorForInvalidExt (StringRef ExtName) {
286
290
if (ExtName.size () == 1 ) {
287
- return createStringError (errc::invalid_argument,
288
- " unsupported standard user-level extension '" +
289
- ExtName + " '" );
291
+ return getError (" unsupported standard user-level extension '" + ExtName +
292
+ " '" );
290
293
}
291
- return createStringError (errc::invalid_argument,
292
- " unsupported " + getExtensionTypeDesc (ExtName) +
293
- " '" + ExtName + " '" );
294
+ return getError (" unsupported " + getExtensionTypeDesc (ExtName) + " '" +
295
+ ExtName + " '" );
294
296
}
295
297
296
298
// Extensions may have a version number, and may be separated by
@@ -315,21 +317,18 @@ static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
315
317
316
318
// Expected 'p' to be followed by minor version number.
317
319
if (MinorStr.empty ()) {
318
- return createStringError (
319
- errc::invalid_argument,
320
- " minor version number missing after 'p' for extension '" + Ext + " '" );
320
+ return getError (" minor version number missing after 'p' for extension '" +
321
+ Ext + " '" );
321
322
}
322
323
}
323
324
324
325
if (!MajorStr.empty () && MajorStr.getAsInteger (10 , Major))
325
- return createStringError (
326
- errc::invalid_argument,
327
- " Failed to parse major version number for extension '" + Ext + " '" );
326
+ return getError (" Failed to parse major version number for extension '" +
327
+ Ext + " '" );
328
328
329
329
if (!MinorStr.empty () && MinorStr.getAsInteger (10 , Minor))
330
- return createStringError (
331
- errc::invalid_argument,
332
- " Failed to parse minor version number for extension '" + Ext + " '" );
330
+ return getError (" Failed to parse minor version number for extension '" +
331
+ Ext + " '" );
333
332
334
333
ConsumeLength = MajorStr.size ();
335
334
@@ -340,24 +339,21 @@ static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
340
339
// subsequent characters (i.e. must either end string or be followed by
341
340
// an underscore).
342
341
if (Ext.size () > 1 && In.size ())
343
- return createStringError (
344
- errc::invalid_argument,
342
+ return getError (
345
343
" multi-character extensions must be separated by underscores" );
346
344
347
345
// If experimental extension, require use of current version number
348
346
if (auto ExperimentalExtension = isExperimentalExtension (Ext)) {
349
347
if (!EnableExperimentalExtension)
350
- return createStringError (errc::invalid_argument,
351
- " requires '-menable-experimental-extensions' "
352
- " for experimental extension '" +
353
- Ext + " '" );
348
+ return getError (" requires '-menable-experimental-extensions' "
349
+ " for experimental extension '" +
350
+ Ext + " '" );
354
351
355
352
if (ExperimentalExtensionVersionCheck &&
356
353
(MajorStr.empty () && MinorStr.empty ()))
357
- return createStringError (
358
- errc::invalid_argument,
354
+ return getError (
359
355
" experimental extension requires explicit version number `" + Ext +
360
- " `" );
356
+ " `" );
361
357
362
358
auto SupportedVers = *ExperimentalExtension;
363
359
if (ExperimentalExtensionVersionCheck &&
@@ -368,7 +364,7 @@ static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
368
364
Error += " for experimental extension '" + Ext.str () +
369
365
" ' (this compiler supports " + utostr (SupportedVers.Major ) +
370
366
" ." + utostr (SupportedVers.Minor ) + " )" ;
371
- return createStringError (errc::invalid_argument, Error);
367
+ return getError ( Error);
372
368
}
373
369
return Error::success ();
374
370
}
@@ -392,13 +388,13 @@ static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
392
388
return Error::success ();
393
389
394
390
if (!RISCVISAInfo::isSupportedExtension (Ext))
395
- return getStringErrorForInvalidExt (Ext);
391
+ return getErrorForInvalidExt (Ext);
396
392
397
- std::string Error = " unsupported version number " + std::string ( MajorStr);
393
+ std::string Error = " unsupported version number " + MajorStr. str ( );
398
394
if (!MinorStr.empty ())
399
395
Error += " ." + MinorStr.str ();
400
396
Error += " for extension '" + Ext.str () + " '" ;
401
- return createStringError (errc::invalid_argument, Error);
397
+ return getError ( Error);
402
398
}
403
399
404
400
llvm::Expected<std::unique_ptr<RISCVISAInfo>>
@@ -439,8 +435,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
439
435
// RISC-V ISA strings must be [a-z0-9_]
440
436
if (!llvm::all_of (
441
437
Arch, [](char C) { return isDigit (C) || isLower (C) || C == ' _' ; }))
442
- return createStringError (errc::invalid_argument,
443
- " string may only contain [a-z0-9_]" );
438
+ return getError (" string may only contain [a-z0-9_]" );
444
439
445
440
// Must start with a valid base ISA name.
446
441
unsigned XLen = 0 ;
@@ -450,8 +445,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
450
445
XLen = 64 ;
451
446
452
447
if (XLen == 0 || Arch.empty () || (Arch[0 ] != ' i' && Arch[0 ] != ' e' ))
453
- return createStringError (errc::invalid_argument,
454
- " arch string must begin with valid base ISA" );
448
+ return getError (" arch string must begin with valid base ISA" );
455
449
456
450
std::unique_ptr<RISCVISAInfo> ISAInfo (new RISCVISAInfo (XLen));
457
451
@@ -461,8 +455,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
461
455
while (!Arch.empty ()) {
462
456
if (Arch[0 ] == ' _' ) {
463
457
if (Arch.size () == 1 || Arch[1 ] == ' _' )
464
- return createStringError (errc::invalid_argument,
465
- " extension name missing after separator '_'" );
458
+ return getError (" extension name missing after separator '_'" );
466
459
Arch = Arch.drop_front ();
467
460
}
468
461
@@ -473,12 +466,10 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
473
466
StringRef Prefix, MinorVersionStr;
474
467
std::tie (Prefix, MinorVersionStr) = Ext.rsplit (' p' );
475
468
if (MinorVersionStr.empty ())
476
- return createStringError (errc::invalid_argument,
477
- " extension lacks version in expected format" );
469
+ return getError (" extension lacks version in expected format" );
478
470
unsigned MajorVersion, MinorVersion;
479
471
if (MinorVersionStr.getAsInteger (10 , MinorVersion))
480
- return createStringError (errc::invalid_argument,
481
- " failed to parse minor version number" );
472
+ return getError (" failed to parse minor version number" );
482
473
483
474
// Split Prefix into the extension name and the major version number
484
475
// (the trailing digits of Prefix).
@@ -489,32 +480,27 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
489
480
--VersionStart;
490
481
}
491
482
if (VersionStart == Prefix.size ())
492
- return createStringError (errc::invalid_argument,
493
- " extension lacks version in expected format" );
483
+ return getError (" extension lacks version in expected format" );
494
484
495
485
if (VersionStart == 0 )
496
- return createStringError (errc::invalid_argument,
497
- " missing extension name" );
486
+ return getError (" missing extension name" );
498
487
499
488
StringRef ExtName = Prefix.slice (0 , VersionStart);
500
489
StringRef MajorVersionStr = Prefix.slice (VersionStart, StringRef::npos);
501
490
if (MajorVersionStr.getAsInteger (10 , MajorVersion))
502
- return createStringError (errc::invalid_argument,
503
- " failed to parse major version number" );
491
+ return getError (" failed to parse major version number" );
504
492
505
493
if ((ExtName[0 ] == ' z' || ExtName[0 ] == ' s' || ExtName[0 ] == ' x' ) &&
506
494
(ExtName.size () == 1 || isDigit (ExtName[1 ])))
507
- return createStringError (errc::invalid_argument,
508
- " '" + Twine (ExtName[0 ]) +
509
- " ' must be followed by a letter" );
495
+ return getError (" '" + Twine (ExtName[0 ]) +
496
+ " ' must be followed by a letter" );
510
497
511
498
if (!ISAInfo->Exts
512
499
.emplace (
513
500
ExtName.str (),
514
501
RISCVISAUtils::ExtensionVersion{MajorVersion, MinorVersion})
515
502
.second )
516
- return createStringError (errc::invalid_argument,
517
- " duplicate extension '" + ExtName + " '" );
503
+ return getError (" duplicate extension '" + ExtName + " '" );
518
504
}
519
505
ISAInfo->updateImpliedLengths ();
520
506
return std::move (ISAInfo);
@@ -526,8 +512,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
526
512
// RISC-V ISA strings must be [a-z0-9_]
527
513
if (!llvm::all_of (
528
514
Arch, [](char C) { return isDigit (C) || isLower (C) || C == ' _' ; }))
529
- return createStringError (errc::invalid_argument,
530
- " string may only contain [a-z0-9_]" );
515
+ return getError (" string may only contain [a-z0-9_]" );
531
516
532
517
// ISA string must begin with rv32, rv64, or a profile.
533
518
unsigned XLen = 0 ;
@@ -548,10 +533,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
548
533
FoundProfile = (I != std::begin (SupportedExperimentalProfiles) &&
549
534
Arch.starts_with (std::prev (I)->Name ));
550
535
if (FoundProfile && !EnableExperimentalExtension) {
551
- return createStringError (errc::invalid_argument,
552
- " requires '-menable-experimental-extensions' "
553
- " for profile '" +
554
- std::prev (I)->Name + " '" );
536
+ return getError (" requires '-menable-experimental-extensions' "
537
+ " for profile '" +
538
+ std::prev (I)->Name + " '" );
555
539
}
556
540
}
557
541
if (FoundProfile) {
@@ -560,9 +544,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
560
544
StringRef ArchWithoutProfile = Arch.drop_front (I->Name .size ());
561
545
if (!ArchWithoutProfile.empty ()) {
562
546
if (ArchWithoutProfile.front () != ' _' )
563
- return createStringError (
564
- errc::invalid_argument,
565
- " additional extensions must be after separator '_'" );
547
+ return getError (" additional extensions must be after separator '_'" );
566
548
NewArch += ArchWithoutProfile.str ();
567
549
}
568
550
return parseArchString (NewArch, EnableExperimentalExtension,
@@ -571,8 +553,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
571
553
}
572
554
573
555
if (XLen == 0 || Arch.empty ())
574
- return createStringError (
575
- errc::invalid_argument,
556
+ return getError (
576
557
" string must begin with rv32{i,e,g}, rv64{i,e,g}, or a supported "
577
558
" profile name" );
578
559
@@ -592,9 +573,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
592
573
// First letter should be 'e', 'i' or 'g'.
593
574
switch (Baseline) {
594
575
default :
595
- return createStringError (errc::invalid_argument,
596
- " first letter after \' rv" + Twine (XLen) +
597
- " \' should be 'e', 'i' or 'g'" );
576
+ return getError (" first letter after \' rv" + Twine (XLen) +
577
+ " \' should be 'e', 'i' or 'g'" );
598
578
case ' e' :
599
579
case ' i' :
600
580
// Baseline is `i` or `e`
@@ -609,8 +589,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
609
589
case ' g' :
610
590
// g expands to extensions in RISCVGImplications.
611
591
if (Arch.size () > 1 && isDigit (Arch[1 ]))
612
- return createStringError (errc::invalid_argument,
613
- " version not supported for 'g'" );
592
+ return getError (" version not supported for 'g'" );
614
593
615
594
// Versions for g are disallowed, and this was checked for previously.
616
595
ConsumeLength = 0 ;
@@ -634,8 +613,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
634
613
while (!Exts.empty ()) {
635
614
if (Exts.front () == ' _' ) {
636
615
if (Exts.size () == 1 || Exts[1 ] == ' _' )
637
- return createStringError (errc::invalid_argument,
638
- " extension name missing after separator '_'" );
616
+ return getError (" extension name missing after separator '_'" );
639
617
Exts = Exts.drop_front ();
640
618
}
641
619
@@ -669,12 +647,10 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
669
647
670
648
assert (!Type.empty () && " Empty type?" );
671
649
if (Name.size () == Type.size ())
672
- return createStringError (errc::invalid_argument,
673
- Desc + " name missing after '" + Type + " '" );
650
+ return getError (Desc + " name missing after '" + Type + " '" );
674
651
} else {
675
- return createStringError (errc::invalid_argument,
676
- " invalid standard user-level extension '" +
677
- Twine (Ext.front ()) + " '" );
652
+ return getError (" invalid standard user-level extension '" +
653
+ Twine (Ext.front ()) + " '" );
678
654
}
679
655
680
656
unsigned Major, Minor, ConsumeLength;
@@ -688,8 +664,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
688
664
689
665
// Check if duplicated extension.
690
666
if (SeenExtMap.contains (Name.str ()))
691
- return createStringError (errc::invalid_argument,
692
- " duplicated " + Desc + " '" + Name + " '" );
667
+ return getError (" duplicated " + Desc + " '" + Name + " '" );
693
668
694
669
SeenExtMap[Name.str ()] = {Major, Minor};
695
670
} while (!Ext.empty ());
@@ -700,7 +675,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
700
675
const std::string &ExtName = SeenExtAndVers.first ;
701
676
702
677
if (!RISCVISAInfo::isSupportedExtension (ExtName))
703
- return getStringErrorForInvalidExt (ExtName);
678
+ return getErrorForInvalidExt (ExtName);
704
679
ISAInfo->Exts [ExtName] = SeenExtAndVers.second ;
705
680
}
706
681
@@ -718,60 +693,49 @@ Error RISCVISAInfo::checkDependency() {
718
693
bool HasZcmt = Exts.count (" zcmt" ) != 0 ;
719
694
720
695
if (HasI && HasE)
721
- return createStringError (errc::invalid_argument,
722
- " 'I' and 'E' extensions are incompatible" );
696
+ return getError (" 'I' and 'E' extensions are incompatible" );
723
697
724
698
if (HasF && HasZfinx)
725
- return createStringError (errc::invalid_argument,
726
- " 'f' and 'zfinx' extensions are incompatible" );
699
+ return getError (" 'f' and 'zfinx' extensions are incompatible" );
727
700
728
701
if (HasZvl && !HasVector)
729
- return createStringError (
730
- errc::invalid_argument,
702
+ return getError (
731
703
" 'zvl*b' requires 'v' or 'zve*' extension to also be specified" );
732
704
733
705
if (Exts.count (" zvbb" ) && !HasVector)
734
- return createStringError (
735
- errc::invalid_argument,
706
+ return getError (
736
707
" 'zvbb' requires 'v' or 'zve*' extension to also be specified" );
737
708
738
709
if (Exts.count (" zvbc" ) && !Exts.count (" zve64x" ))
739
- return createStringError (
740
- errc::invalid_argument,
710
+ return getError (
741
711
" 'zvbc' requires 'v' or 'zve64*' extension to also be specified" );
742
712
743
713
if ((Exts.count (" zvkb" ) || Exts.count (" zvkg" ) || Exts.count (" zvkned" ) ||
744
714
Exts.count (" zvknha" ) || Exts.count (" zvksed" ) || Exts.count (" zvksh" )) &&
745
715
!HasVector)
746
- return createStringError (
747
- errc::invalid_argument,
716
+ return getError (
748
717
" 'zvk*' requires 'v' or 'zve*' extension to also be specified" );
749
718
750
719
if (Exts.count (" zvknhb" ) && !Exts.count (" zve64x" ))
751
- return createStringError (
752
- errc::invalid_argument,
720
+ return getError (
753
721
" 'zvknhb' requires 'v' or 'zve64*' extension to also be specified" );
754
722
755
723
if ((HasZcmt || Exts.count (" zcmp" )) && Exts.count (" d" ) &&
756
724
(HasC || Exts.count (" zcd" )))
757
- return createStringError (
758
- errc::invalid_argument,
759
- Twine (" '" ) + (HasZcmt ? " zcmt" : " zcmp" ) +
760
- " ' extension is incompatible with '" + (HasC ? " c" : " zcd" ) +
761
- " ' extension when 'd' extension is enabled" );
725
+ return getError (Twine (" '" ) + (HasZcmt ? " zcmt" : " zcmp" ) +
726
+ " ' extension is incompatible with '" +
727
+ (HasC ? " c" : " zcd" ) +
728
+ " ' extension when 'd' extension is enabled" );
762
729
763
730
if (XLen != 32 && Exts.count (" zcf" ))
764
- return createStringError (errc::invalid_argument,
765
- " 'zcf' is only supported for 'rv32'" );
731
+ return getError (" 'zcf' is only supported for 'rv32'" );
766
732
767
733
if (Exts.count (" zacas" ) && !(Exts.count (" a" ) || Exts.count (" zaamo" )))
768
- return createStringError (
769
- errc::invalid_argument,
734
+ return getError (
770
735
" 'zacas' requires 'a' or 'zaamo' extension to also be specified" );
771
736
772
737
if (Exts.count (" zabha" ) && !(Exts.count (" a" ) || Exts.count (" zaamo" )))
773
- return createStringError (
774
- errc::invalid_argument,
738
+ return getError (
775
739
" 'zabha' requires 'a' or 'zaamo' extension to also be specified" );
776
740
777
741
return Error::success ();
0 commit comments