@@ -272,6 +272,22 @@ static Error reportError(const Twine &Message) {
272
272
return createStringError (inconvertibleErrorCode (), Message);
273
273
}
274
274
275
+ static Error createSpecFormatError (Twine Format) {
276
+ return createStringError (" malformed specification, must be of the form \" " +
277
+ Format + " \" " );
278
+ }
279
+
280
+ // / Attempts to parse an address space component of a specification.
281
+ static Error parseAddrSpace (StringRef Str, unsigned &AddrSpace) {
282
+ if (Str.empty ())
283
+ return createStringError (" address space component cannot be empty" );
284
+
285
+ if (!to_integer (Str, AddrSpace, 10 ) || !isUInt<24 >(AddrSpace))
286
+ return createStringError (" address space must be a 24-bit integer" );
287
+
288
+ return Error::success ();
289
+ }
290
+
275
291
// / Checked version of split, to ensure mandatory subparts.
276
292
static Error split (StringRef Str, char Separator,
277
293
std::pair<StringRef, StringRef> &Split) {
@@ -313,6 +329,26 @@ static Error getAddrSpace(StringRef R, unsigned &AddrSpace) {
313
329
}
314
330
315
331
Error DataLayout::parseSpecification (StringRef Spec) {
332
+ // The "ni" specifier is the only two-character specifier. Handle it first.
333
+ if (Spec.starts_with (" ni" )) {
334
+ // ni:<address space>[:<address space>]...
335
+ StringRef Rest = Spec.drop_front (2 );
336
+
337
+ // Drop the first ':', then split the rest of the string the usual way.
338
+ if (!Rest.consume_front (" :" ))
339
+ return createSpecFormatError (" ni:<address space>[:<address space>]..." );
340
+
341
+ for (StringRef Str : split (Rest, ' :' )) {
342
+ unsigned AddrSpace;
343
+ if (Error Err = parseAddrSpace (Str, AddrSpace))
344
+ return Err;
345
+ if (AddrSpace == 0 )
346
+ return createStringError (" address space 0 cannot be non-integral" );
347
+ NonIntegralAddressSpaces.push_back (AddrSpace);
348
+ }
349
+ return Error::success ();
350
+ }
351
+
316
352
// Split at ':'.
317
353
std::pair<StringRef, StringRef> Split;
318
354
if (Error Err = ::split (Spec, ' :' , Split))
@@ -322,22 +358,6 @@ Error DataLayout::parseSpecification(StringRef Spec) {
322
358
StringRef &Tok = Split.first ; // Current token.
323
359
StringRef &Rest = Split.second ; // The rest of the string.
324
360
325
- if (Tok == " ni" ) {
326
- do {
327
- if (Error Err = ::split (Rest, ' :' , Split))
328
- return Err;
329
- Rest = Split.second ;
330
- unsigned AS;
331
- if (Error Err = getInt (Split.first , AS))
332
- return Err;
333
- if (AS == 0 )
334
- return reportError (" Address space 0 can never be non-integral" );
335
- NonIntegralAddressSpaces.push_back (AS);
336
- } while (!Rest.empty ());
337
-
338
- return Error::success ();
339
- }
340
-
341
361
char SpecifierChar = Tok.front ();
342
362
Tok = Tok.substr (1 );
343
363
0 commit comments