@@ -3064,11 +3064,11 @@ const Init *Record::getValueInit(StringRef FieldName) const {
3064
3064
}
3065
3065
3066
3066
StringRef Record::getValueAsString (StringRef FieldName) const {
3067
- std::optional<StringRef> S = getValueAsOptionalString (FieldName);
3068
- if (!S )
3069
- PrintFatalError ( getLoc (), " Record ` " + getName () +
3070
- " ' does not have a field named `" + FieldName + " '! \n " );
3071
- return *S ;
3067
+ const Init *I = getValueInit (FieldName);
3068
+ if (const auto *SI = dyn_cast<StringInit>(I) )
3069
+ return SI-> getValue ();
3070
+ PrintFatalError ( getLoc (), " Record ` " + getName () + " ', field `" + FieldName +
3071
+ " ' exists but does not have a string value " ) ;
3072
3072
}
3073
3073
3074
3074
std::optional<StringRef>
@@ -3088,24 +3088,16 @@ Record::getValueAsOptionalString(StringRef FieldName) const {
3088
3088
}
3089
3089
3090
3090
const BitsInit *Record::getValueAsBitsInit (StringRef FieldName) const {
3091
- const RecordVal *R = getValue (FieldName);
3092
- if (!R || !R->getValue ())
3093
- PrintFatalError (getLoc (), " Record `" + getName () +
3094
- " ' does not have a field named `" + FieldName + " '!\n " );
3095
-
3096
- if (const auto *BI = dyn_cast<BitsInit>(R->getValue ()))
3091
+ const Init *I = getValueInit (FieldName);
3092
+ if (const auto *BI = dyn_cast<BitsInit>(I))
3097
3093
return BI;
3098
3094
PrintFatalError (getLoc (), " Record `" + getName () + " ', field `" + FieldName +
3099
3095
" ' exists but does not have a bits value" );
3100
3096
}
3101
3097
3102
3098
const ListInit *Record::getValueAsListInit (StringRef FieldName) const {
3103
- const RecordVal *R = getValue (FieldName);
3104
- if (!R || !R->getValue ())
3105
- PrintFatalError (getLoc (), " Record `" + getName () +
3106
- " ' does not have a field named `" + FieldName + " '!\n " );
3107
-
3108
- if (const auto *LI = dyn_cast<ListInit>(R->getValue ()))
3099
+ const Init *I = getValueInit (FieldName);
3100
+ if (const auto *LI = dyn_cast<ListInit>(I))
3109
3101
return LI;
3110
3102
PrintFatalError (getLoc (), " Record `" + getName () + " ', field `" + FieldName +
3111
3103
" ' exists but does not have a list value" );
@@ -3127,17 +3119,13 @@ Record::getValueAsListOfDefs(StringRef FieldName) const {
3127
3119
}
3128
3120
3129
3121
int64_t Record::getValueAsInt (StringRef FieldName) const {
3130
- const RecordVal *R = getValue (FieldName);
3131
- if (!R || !R->getValue ())
3132
- PrintFatalError (getLoc (), " Record `" + getName () +
3133
- " ' does not have a field named `" + FieldName + " '!\n " );
3134
-
3135
- if (const auto *II = dyn_cast<IntInit>(R->getValue ()))
3122
+ const Init *I = getValueInit (FieldName);
3123
+ if (const auto *II = dyn_cast<IntInit>(I))
3136
3124
return II->getValue ();
3137
- PrintFatalError (getLoc (), Twine ( " Record ` " ) + getName () + " ', field ` " +
3138
- FieldName +
3139
- " ' exists but does not have an int value: " +
3140
- R-> getValue () ->getAsString ());
3125
+ PrintFatalError (
3126
+ getLoc (),
3127
+ Twine ( " Record ` " ) + getName () + " ', field ` " + FieldName +
3128
+ " ' exists but does not have an int value: " + I ->getAsString ());
3141
3129
}
3142
3130
3143
3131
std::vector<int64_t >
@@ -3173,67 +3161,47 @@ Record::getValueAsListOfStrings(StringRef FieldName) const {
3173
3161
}
3174
3162
3175
3163
const Record *Record::getValueAsDef (StringRef FieldName) const {
3176
- const RecordVal *R = getValue (FieldName);
3177
- if (!R || !R->getValue ())
3178
- PrintFatalError (getLoc (), " Record `" + getName () +
3179
- " ' does not have a field named `" + FieldName + " '!\n " );
3180
-
3181
- if (const auto *DI = dyn_cast<DefInit>(R->getValue ()))
3164
+ const Init *I = getValueInit (FieldName);
3165
+ if (const auto *DI = dyn_cast<DefInit>(I))
3182
3166
return DI->getDef ();
3183
3167
PrintFatalError (getLoc (), " Record `" + getName () + " ', field `" +
3184
3168
FieldName + " ' does not have a def initializer!" );
3185
3169
}
3186
3170
3187
3171
const Record *Record::getValueAsOptionalDef (StringRef FieldName) const {
3188
- const RecordVal *R = getValue (FieldName);
3189
- if (!R || !R->getValue ())
3190
- PrintFatalError (getLoc (), " Record `" + getName () +
3191
- " ' does not have a field named `" + FieldName + " '!\n " );
3192
-
3193
- if (const auto *DI = dyn_cast<DefInit>(R->getValue ()))
3172
+ const Init *I = getValueInit (FieldName);
3173
+ if (const auto *DI = dyn_cast<DefInit>(I))
3194
3174
return DI->getDef ();
3195
- if (isa<UnsetInit>(R-> getValue () ))
3175
+ if (isa<UnsetInit>(I ))
3196
3176
return nullptr ;
3197
3177
PrintFatalError (getLoc (), " Record `" + getName () + " ', field `" +
3198
3178
FieldName + " ' does not have either a def initializer or '?'!" );
3199
3179
}
3200
3180
3201
3181
bool Record::getValueAsBit (StringRef FieldName) const {
3202
- const RecordVal *R = getValue (FieldName);
3203
- if (!R || !R->getValue ())
3204
- PrintFatalError (getLoc (), " Record `" + getName () +
3205
- " ' does not have a field named `" + FieldName + " '!\n " );
3206
-
3207
- if (const auto *BI = dyn_cast<BitInit>(R->getValue ()))
3182
+ const Init *I = getValueInit (FieldName);
3183
+ if (const auto *BI = dyn_cast<BitInit>(I))
3208
3184
return BI->getValue ();
3209
3185
PrintFatalError (getLoc (), " Record `" + getName () + " ', field `" +
3210
3186
FieldName + " ' does not have a bit initializer!" );
3211
3187
}
3212
3188
3213
3189
bool Record::getValueAsBitOrUnset (StringRef FieldName, bool &Unset) const {
3214
- const RecordVal *R = getValue (FieldName);
3215
- if (!R || !R->getValue ())
3216
- PrintFatalError (getLoc (), " Record `" + getName () +
3217
- " ' does not have a field named `" + FieldName.str () + " '!\n " );
3218
-
3219
- if (isa<UnsetInit>(R->getValue ())) {
3190
+ const Init *I = getValueInit (FieldName);
3191
+ if (isa<UnsetInit>(I)) {
3220
3192
Unset = true ;
3221
3193
return false ;
3222
3194
}
3223
3195
Unset = false ;
3224
- if (const auto *BI = dyn_cast<BitInit>(R-> getValue () ))
3196
+ if (const auto *BI = dyn_cast<BitInit>(I ))
3225
3197
return BI->getValue ();
3226
3198
PrintFatalError (getLoc (), " Record `" + getName () + " ', field `" +
3227
3199
FieldName + " ' does not have a bit initializer!" );
3228
3200
}
3229
3201
3230
3202
const DagInit *Record::getValueAsDag (StringRef FieldName) const {
3231
- const RecordVal *R = getValue (FieldName);
3232
- if (!R || !R->getValue ())
3233
- PrintFatalError (getLoc (), " Record `" + getName () +
3234
- " ' does not have a field named `" + FieldName + " '!\n " );
3235
-
3236
- if (const auto *DI = dyn_cast<DagInit>(R->getValue ()))
3203
+ const Init *I = getValueInit (FieldName);
3204
+ if (const auto *DI = dyn_cast<DagInit>(I))
3237
3205
return DI;
3238
3206
PrintFatalError (getLoc (), " Record `" + getName () + " ', field `" +
3239
3207
FieldName + " ' does not have a dag initializer!" );
0 commit comments