1 //===-- AArch64BuildAttributes.cpp - AArch64 Build Attributes -------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Support/AArch64BuildAttributes.h"
10 #include "llvm/ADT/StringSwitch.h"
11
12 using namespace llvm;
13 using namespace llvm::AArch64BuildAttributes;
14
getVendorName(unsigned Vendor)15 StringRef AArch64BuildAttributes::getVendorName(unsigned Vendor) {
16 switch (Vendor) {
17 case AEABI_FEATURE_AND_BITS:
18 return "aeabi_feature_and_bits";
19 case AEABI_PAUTHABI:
20 return "aeabi_pauthabi";
21 case VENDOR_UNKNOWN:
22 return "";
23 default:
24 assert(0 && "Vendor name error");
25 return "";
26 }
27 }
getVendorID(StringRef Vendor)28 VendorID AArch64BuildAttributes::getVendorID(StringRef Vendor) {
29 return StringSwitch<VendorID>(Vendor)
30 .Case("aeabi_feature_and_bits", AEABI_FEATURE_AND_BITS)
31 .Case("aeabi_pauthabi", AEABI_PAUTHABI)
32 .Default(VENDOR_UNKNOWN);
33 }
34
getOptionalStr(unsigned Optional)35 StringRef AArch64BuildAttributes::getOptionalStr(unsigned Optional) {
36 switch (Optional) {
37 case REQUIRED:
38 return "required";
39 case OPTIONAL:
40 return "optional";
41 case OPTIONAL_NOT_FOUND:
42 default:
43 return "";
44 }
45 }
getOptionalID(StringRef Optional)46 SubsectionOptional AArch64BuildAttributes::getOptionalID(StringRef Optional) {
47 return StringSwitch<SubsectionOptional>(Optional)
48 .Case("required", REQUIRED)
49 .Case("optional", OPTIONAL)
50 .Default(OPTIONAL_NOT_FOUND);
51 }
getSubsectionOptionalUnknownError()52 StringRef AArch64BuildAttributes::getSubsectionOptionalUnknownError() {
53 return "unknown AArch64 build attributes optionality, expected "
54 "required|optional";
55 }
56
getTypeStr(unsigned Type)57 StringRef AArch64BuildAttributes::getTypeStr(unsigned Type) {
58 switch (Type) {
59 case ULEB128:
60 return "uleb128";
61 case NTBS:
62 return "ntbs";
63 case TYPE_NOT_FOUND:
64 default:
65 return "";
66 }
67 }
getTypeID(StringRef Type)68 SubsectionType AArch64BuildAttributes::getTypeID(StringRef Type) {
69 return StringSwitch<SubsectionType>(Type)
70 .Cases("uleb128", "ULEB128", ULEB128)
71 .Cases("ntbs", "NTBS", NTBS)
72 .Default(TYPE_NOT_FOUND);
73 }
getSubsectionTypeUnknownError()74 StringRef AArch64BuildAttributes::getSubsectionTypeUnknownError() {
75 return "unknown AArch64 build attributes type, expected uleb128|ntbs";
76 }
77
getPauthABITagsStr(unsigned PauthABITag)78 StringRef AArch64BuildAttributes::getPauthABITagsStr(unsigned PauthABITag) {
79 switch (PauthABITag) {
80 case TAG_PAUTH_PLATFORM:
81 return "Tag_PAuth_Platform";
82 case TAG_PAUTH_SCHEMA:
83 return "Tag_PAuth_Schema";
84 case PAUTHABI_TAG_NOT_FOUND:
85 default:
86 return "";
87 }
88 }
89
getPauthABITagsID(StringRef PauthABITag)90 PauthABITags AArch64BuildAttributes::getPauthABITagsID(StringRef PauthABITag) {
91 return StringSwitch<PauthABITags>(PauthABITag)
92 .Case("Tag_PAuth_Platform", TAG_PAUTH_PLATFORM)
93 .Case("Tag_PAuth_Schema", TAG_PAUTH_SCHEMA)
94 .Default(PAUTHABI_TAG_NOT_FOUND);
95 }
96
97 StringRef
getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag)98 AArch64BuildAttributes::getFeatureAndBitsTagsStr(unsigned FeatureAndBitsTag) {
99 switch (FeatureAndBitsTag) {
100 case TAG_FEATURE_BTI:
101 return "Tag_Feature_BTI";
102 case TAG_FEATURE_PAC:
103 return "Tag_Feature_PAC";
104 case TAG_FEATURE_GCS:
105 return "Tag_Feature_GCS";
106 case FEATURE_AND_BITS_TAG_NOT_FOUND:
107 default:
108 return "";
109 }
110 }
111
112 FeatureAndBitsTags
getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag)113 AArch64BuildAttributes::getFeatureAndBitsTagsID(StringRef FeatureAndBitsTag) {
114 return StringSwitch<FeatureAndBitsTags>(FeatureAndBitsTag)
115 .Case("Tag_Feature_BTI", TAG_FEATURE_BTI)
116 .Case("Tag_Feature_PAC", TAG_FEATURE_PAC)
117 .Case("Tag_Feature_GCS", TAG_FEATURE_GCS)
118 .Default(FEATURE_AND_BITS_TAG_NOT_FOUND);
119 }
120