Skip to content

Commit b901b6a

Browse files
committed
Revert "[ms] [llvm-ml] Add support for .radix directive, and accept all radix specifiers"
This reverts commit 5dd1b6d.
1 parent 7a3c643 commit b901b6a

File tree

7 files changed

+22
-288
lines changed

7 files changed

+22
-288
lines changed

llvm/include/llvm/MC/MCParser/MCAsmLexer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class MCAsmLexer {
5050
bool AllowAtInIdentifier;
5151
bool IsAtStartOfStatement = true;
5252
bool LexMasmIntegers = false;
53-
unsigned DefaultRadix = 10;
5453
AsmCommentConsumer *CommentConsumer = nullptr;
5554

5655
MCAsmLexer();
@@ -144,9 +143,6 @@ class MCAsmLexer {
144143
bool getAllowAtInIdentifier() { return AllowAtInIdentifier; }
145144
void setAllowAtInIdentifier(bool v) { AllowAtInIdentifier = v; }
146145

147-
unsigned getDefaultRadix() const { return DefaultRadix; }
148-
void setDefaultRadix(unsigned Radix) { DefaultRadix = Radix; }
149-
150146
void setCommentConsumer(AsmCommentConsumer *CommentConsumer) {
151147
this->CommentConsumer = CommentConsumer;
152148
}

llvm/lib/MC/MCParser/AsmLexer.cpp

Lines changed: 21 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/ADT/StringSwitch.h"
1919
#include "llvm/MC/MCAsmInfo.h"
2020
#include "llvm/MC/MCParser/MCAsmLexer.h"
21-
#include "llvm/Support/Compiler.h"
2221
#include "llvm/Support/SMLoc.h"
2322
#include "llvm/Support/SaveAndRestore.h"
2423
#include <cassert>
@@ -272,35 +271,13 @@ static unsigned doHexLookAhead(const char *&CurPtr, unsigned DefaultRadix,
272271
return DefaultRadix;
273272
}
274273

275-
static const char *findLastDigit(const char *CurPtr, unsigned DefaultRadix) {
276-
while (hexDigitValue(*CurPtr) < DefaultRadix) {
277-
++CurPtr;
278-
}
279-
return CurPtr;
280-
}
281-
282274
static AsmToken intToken(StringRef Ref, APInt &Value)
283275
{
284276
if (Value.isIntN(64))
285277
return AsmToken(AsmToken::Integer, Ref, Value);
286278
return AsmToken(AsmToken::BigNum, Ref, Value);
287279
}
288280

289-
static std::string radixName(unsigned Radix) {
290-
switch (Radix) {
291-
case 2:
292-
return "binary";
293-
case 8:
294-
return "octal";
295-
case 10:
296-
return "decimal";
297-
case 16:
298-
return "hexadecimal";
299-
default:
300-
return "base-" + std::to_string(Radix);
301-
}
302-
}
303-
304281
/// LexDigit: First character is [0-9].
305282
/// Local Label: [0-9][:]
306283
/// Forward/Backward Label: [0-9][fb]
@@ -309,108 +286,45 @@ static std::string radixName(unsigned Radix) {
309286
/// Hex integer: 0x[0-9a-fA-F]+ or [0x]?[0-9][0-9a-fA-F]*[hH]
310287
/// Decimal integer: [1-9][0-9]*
311288
AsmToken AsmLexer::LexDigit() {
312-
// MASM-flavor binary integer: [01]+[yY] (if DefaultRadix < 16, [bByY])
313-
// MASM-flavor octal integer: [0-7]+[oOqQ]
314-
// MASM-flavor decimal integer: [0-9]+[tT] (if DefaultRadix < 16, [dDtT])
289+
// MASM-flavor binary integer: [01]+[bB]
315290
// MASM-flavor hexadecimal integer: [0-9][0-9a-fA-F]*[hH]
316291
if (LexMasmIntegers && isdigit(CurPtr[-1])) {
317-
const char *FirstNonBinary =
318-
(CurPtr[-1] != '0' && CurPtr[-1] != '1') ? CurPtr - 1 : nullptr;
319-
const char *FirstNonDecimal =
320-
(CurPtr[-1] < '0' || CurPtr[-1] > '9') ? CurPtr - 1 : nullptr;
292+
const char *FirstNonBinary = (CurPtr[-1] != '0' && CurPtr[-1] != '1') ?
293+
CurPtr - 1 : nullptr;
321294
const char *OldCurPtr = CurPtr;
322295
while (isHexDigit(*CurPtr)) {
323-
switch (*CurPtr) {
324-
default:
325-
if (!FirstNonDecimal) {
326-
FirstNonDecimal = CurPtr;
327-
}
328-
LLVM_FALLTHROUGH;
329-
case '9':
330-
case '8':
331-
case '7':
332-
case '6':
333-
case '5':
334-
case '4':
335-
case '3':
336-
case '2':
337-
if (!FirstNonBinary) {
338-
FirstNonBinary = CurPtr;
339-
}
340-
break;
341-
case '1':
342-
case '0':
343-
break;
344-
}
345-
++CurPtr;
346-
}
347-
if (*CurPtr == '.') {
348-
// MASM float literals (other than hex floats) always contain a ".", and
349-
// are always written in decimal.
296+
if (*CurPtr != '0' && *CurPtr != '1' && !FirstNonBinary)
297+
FirstNonBinary = CurPtr;
350298
++CurPtr;
351-
return LexFloatLiteral();
352299
}
353300

354301
unsigned Radix = 0;
355302
if (*CurPtr == 'h' || *CurPtr == 'H') {
356303
// hexadecimal number
357304
++CurPtr;
358305
Radix = 16;
359-
} else if (*CurPtr == 't' || *CurPtr == 'T') {
360-
// decimal number
361-
++CurPtr;
362-
Radix = 10;
363-
} else if (*CurPtr == 'o' || *CurPtr == 'O' || *CurPtr == 'q' ||
364-
*CurPtr == 'Q') {
365-
// octal number
366-
++CurPtr;
367-
Radix = 8;
368-
} else if (*CurPtr == 'y' || *CurPtr == 'Y') {
369-
// binary number
370-
++CurPtr;
371-
Radix = 2;
372-
} else if (FirstNonDecimal && FirstNonDecimal + 1 == CurPtr &&
373-
DefaultRadix < 14 &&
374-
(*FirstNonDecimal == 'd' || *FirstNonDecimal == 'D')) {
375-
Radix = 10;
376306
} else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
377-
DefaultRadix < 12 &&
378-
(*FirstNonBinary == 'b' || *FirstNonBinary == 'B')) {
307+
(*FirstNonBinary == 'b' || *FirstNonBinary == 'B'))
379308
Radix = 2;
380-
}
381309

382-
if (Radix) {
310+
if (Radix == 2 || Radix == 16) {
383311
StringRef Result(TokStart, CurPtr - TokStart);
384312
APInt Value(128, 0, true);
385313

386314
if (Result.drop_back().getAsInteger(Radix, Value))
387-
return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
315+
return ReturnError(TokStart, Radix == 2 ? "invalid binary number" :
316+
"invalid hexdecimal number");
388317

389318
// MSVC accepts and ignores type suffices on integer literals.
390319
SkipIgnoredIntegerSuffix(CurPtr);
391320

392321
return intToken(Result, Value);
393-
}
322+
}
394323

395-
// default-radix integers, or floating point numbers, fall through
324+
// octal/decimal integers, or floating point numbers, fall through
396325
CurPtr = OldCurPtr;
397326
}
398327

399-
// MASM default-radix integers: [0-9a-fA-F]+
400-
// (All other integer literals have a radix specifier.)
401-
if (LexMasmIntegers) {
402-
CurPtr = findLastDigit(CurPtr, 16);
403-
StringRef Result(TokStart, CurPtr - TokStart);
404-
405-
APInt Value(128, 0, true);
406-
if (Result.getAsInteger(DefaultRadix, Value)) {
407-
return ReturnError(TokStart,
408-
"invalid " + radixName(DefaultRadix) + " number");
409-
}
410-
411-
return intToken(Result, Value);
412-
}
413-
414328
// Decimal integer: [1-9][0-9]*
415329
if (CurPtr[-1] != '0' || CurPtr[0] == '.') {
416330
unsigned Radix = doHexLookAhead(CurPtr, 10, LexMasmIntegers);
@@ -425,9 +339,13 @@ AsmToken AsmLexer::LexDigit() {
425339
StringRef Result(TokStart, CurPtr - TokStart);
426340

427341
APInt Value(128, 0, true);
428-
if (Result.getAsInteger(Radix, Value)) {
429-
return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
430-
}
342+
if (Result.getAsInteger(Radix, Value))
343+
return ReturnError(TokStart, !isHex ? "invalid decimal number" :
344+
"invalid hexdecimal number");
345+
346+
// Consume the [hH].
347+
if (LexMasmIntegers && Radix == 16)
348+
++CurPtr;
431349

432350
// The darwin/x86 (and x86-64) assembler accepts and ignores type
433351
// suffices on integer literals.
@@ -498,9 +416,11 @@ AsmToken AsmLexer::LexDigit() {
498416
// Either octal or hexadecimal.
499417
APInt Value(128, 0, true);
500418
unsigned Radix = doHexLookAhead(CurPtr, 8, LexMasmIntegers);
419+
bool isHex = Radix == 16;
501420
StringRef Result(TokStart, CurPtr - TokStart);
502421
if (Result.getAsInteger(Radix, Value))
503-
return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
422+
return ReturnError(TokStart, !isHex ? "invalid octal number" :
423+
"invalid hexdecimal number");
504424

505425
// Consume the [hH].
506426
if (Radix == 16)

llvm/lib/MC/MCParser/COFFMasmParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class COFFMasmParser : public MCAsmParserExtension {
132132
// option
133133
// popcontext
134134
// pushcontext
135+
// .radix
135136
// .safeseh
136137

137138
// Procedure directives

llvm/lib/MC/MCParser/MasmParser.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,6 @@ class MasmParser : public MCAsmParser {
732732
DK_SAVEREG,
733733
DK_SAVEXMM128,
734734
DK_SETFRAME,
735-
DK_RADIX,
736735
};
737736

738737
/// Maps directive name --> DirectiveKind enum, for directives parsed by this
@@ -965,9 +964,6 @@ class MasmParser : public MCAsmParser {
965964
// ".erre" or ".errnz", depending on ExpectZero.
966965
bool parseDirectiveErrorIfe(SMLoc DirectiveLoc, bool ExpectZero);
967966

968-
// ".radix"
969-
bool parseDirectiveRadix(SMLoc DirectiveLoc);
970-
971967
// "echo"
972968
bool parseDirectiveEcho();
973969

@@ -2288,8 +2284,6 @@ bool MasmParser::parseStatement(ParseStatementInfo &Info,
22882284
return parseDirectiveErrorIfe(IDLoc, true);
22892285
case DK_ERRNZ:
22902286
return parseDirectiveErrorIfe(IDLoc, false);
2291-
case DK_RADIX:
2292-
return parseDirectiveRadix(IDLoc);
22932287
case DK_ECHO:
22942288
return parseDirectiveEcho();
22952289
}
@@ -6349,7 +6343,6 @@ void MasmParser::initializeDirectiveKindMap() {
63496343
DirectiveKindMap[".savereg"] = DK_SAVEREG;
63506344
DirectiveKindMap[".savexmm128"] = DK_SAVEXMM128;
63516345
DirectiveKindMap[".setframe"] = DK_SETFRAME;
6352-
DirectiveKindMap[".radix"] = DK_RADIX;
63536346
// DirectiveKindMap[".altmacro"] = DK_ALTMACRO;
63546347
// DirectiveKindMap[".noaltmacro"] = DK_NOALTMACRO;
63556348
DirectiveKindMap["db"] = DK_DB;
@@ -6591,22 +6584,6 @@ bool MasmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) {
65916584
return false;
65926585
}
65936586

6594-
bool MasmParser::parseDirectiveRadix(SMLoc DirectiveLoc) {
6595-
const SMLoc Loc = getLexer().getLoc();
6596-
StringRef RadixString = parseStringToEndOfStatement().trim();
6597-
unsigned Radix;
6598-
if (RadixString.getAsInteger(10, Radix)) {
6599-
return Error(Loc,
6600-
"radix must be a decimal number in the range 2 to 16; was " +
6601-
RadixString);
6602-
}
6603-
if (Radix < 2 || Radix > 16)
6604-
return Error(Loc, "radix must be in the range 2 to 16; was " +
6605-
std::to_string(Radix));
6606-
getLexer().setDefaultRadix(Radix);
6607-
return false;
6608-
}
6609-
66106587
bool MasmParser::parseDirectiveEcho() {
66116588
StringRef Message = parseStringToEndOfStatement();
66126589
Lex(); // eat end of statement

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,9 +1662,6 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
16621662
if ((Done = SM.isValidEndState()))
16631663
break;
16641664
return Error(Tok.getLoc(), "unknown token in expression");
1665-
case AsmToken::Error:
1666-
return Error(getLexer().getErrLoc(), getLexer().getErr());
1667-
break;
16681665
case AsmToken::EndOfStatement:
16691666
Done = true;
16701667
break;

llvm/test/tools/llvm-ml/radix.test

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)