[llvm] e52e7ad - [ms] [llvm-ml] Add support for bitwise named operators (AND, NOT, OR) in MASM
Eric Astor via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 10:58:01 PDT 2020
Author: Eric Astor
Date: 2020-09-07T13:57:54-04:00
New Revision: e52e7ad54defa3a95040b680beff2824c9c6fbb7
URL: https://github.com/llvm/llvm-project/commit/e52e7ad54defa3a95040b680beff2824c9c6fbb7
DIFF: https://github.com/llvm/llvm-project/commit/e52e7ad54defa3a95040b680beff2824c9c6fbb7.diff
LOG: [ms] [llvm-ml] Add support for bitwise named operators (AND, NOT, OR) in MASM
Add support for expressions of the form '1 or 2', etc.
Reviewed By: thakis
Differential Revision: https://reviews.llvm.org/D86944
Added:
llvm/test/tools/llvm-ml/named_bitwise_operators.test
Modified:
llvm/lib/MC/MCParser/MasmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index 45165ffe3cac..94cef83bc405 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -1314,7 +1314,7 @@ bool MasmParser::parseBracketExpr(const MCExpr *&Res, SMLoc &EndLoc) {
/// primaryexpr ::= symbol
/// primaryexpr ::= number
/// primaryexpr ::= '.'
-/// primaryexpr ::= ~,+,- primaryexpr
+/// primaryexpr ::= ~,+,-,'not' primaryexpr
bool MasmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
SMLoc FirstTokenLoc = getLexer().getLoc();
AsmToken::TokenKind FirstTokenKind = Lexer.getKind();
@@ -1352,6 +1352,13 @@ bool MasmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) {
return Error(FirstTokenLoc, "invalid token in expression");
}
}
+ // Parse named bitwise negation.
+ if (Identifier.equals_lower("not")) {
+ if (parsePrimaryExpr(Res, EndLoc))
+ return true;
+ Res = MCUnaryExpr::createNot(Res, getContext(), FirstTokenLoc);
+ return false;
+ }
// Parse symbol variant.
std::pair<StringRef, StringRef> Split;
if (!MAI.useParensForSymbolVariant()) {
@@ -1772,8 +1779,18 @@ bool MasmParser::parseBinOpRHS(unsigned Precedence, const MCExpr *&Res,
SMLoc &EndLoc) {
SMLoc StartLoc = Lexer.getLoc();
while (true) {
+ AsmToken::TokenKind TokKind = Lexer.getKind();
+ if (Lexer.getKind() == AsmToken::Identifier) {
+ StringRef Identifier = Lexer.getTok().getString();
+ if (Identifier.equals_lower("and"))
+ TokKind = AsmToken::Amp;
+ else if (Identifier.equals_lower("not"))
+ TokKind = AsmToken::Exclaim;
+ else if (Identifier.equals_lower("or"))
+ TokKind = AsmToken::Pipe;
+ }
MCBinaryExpr::Opcode Kind = MCBinaryExpr::Add;
- unsigned TokPrec = getBinOpPrecedence(Lexer.getKind(), Kind);
+ unsigned TokPrec = getBinOpPrecedence(TokKind, Kind);
// If the next token is lower precedence than we are allowed to eat, return
// successfully with what we ate already.
@@ -3229,7 +3246,7 @@ bool MasmParser::parseScalarInitializer(unsigned Size,
Lex();
} else {
const MCExpr *Value;
- if (checkForValidSection() || parseExpression(Value))
+ if (parseExpression(Value))
return true;
if (getTok().is(AsmToken::Identifier) &&
getTok().getString().equals_lower("dup")) {
@@ -3449,6 +3466,9 @@ bool MasmParser::parseRealInstList(const fltSemantics &Semantics,
// Initialize real data values.
bool MasmParser::emitRealValues(const fltSemantics &Semantics) {
+ if (checkForValidSection())
+ return true;
+
SmallVector<APInt, 1> ValuesAsInt;
if (parseRealInstList(Semantics, ValuesAsInt))
return true;
@@ -3468,8 +3488,7 @@ bool MasmParser::addRealField(StringRef Name, const fltSemantics &Semantics) {
Field.SizeOf = 0;
- if (checkForValidSection() ||
- parseRealInstList(Semantics, RealInfo.AsIntValues))
+ if (parseRealInstList(Semantics, RealInfo.AsIntValues))
return true;
Field.Type = RealInfo.AsIntValues.back().getBitWidth() / 8;
@@ -3486,9 +3505,6 @@ bool MasmParser::addRealField(StringRef Name, const fltSemantics &Semantics) {
/// ::= (real4 | real8) [ expression (, expression)* ]
bool MasmParser::parseDirectiveRealValue(StringRef IDVal,
const fltSemantics &Semantics) {
- if (checkForValidSection())
- return true;
-
if (StructInProgress.empty()) {
// Initialize data value.
if (emitRealValues(Semantics))
@@ -3504,9 +3520,6 @@ bool MasmParser::parseDirectiveRealValue(StringRef IDVal,
bool MasmParser::parseDirectiveNamedRealValue(StringRef IDVal,
const fltSemantics &Semantics,
StringRef Name, SMLoc NameLoc) {
- if (checkForValidSection())
- return true;
-
if (StructInProgress.empty()) {
// Initialize named data value.
MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
diff --git a/llvm/test/tools/llvm-ml/named_bitwise_operators.test b/llvm/test/tools/llvm-ml/named_bitwise_operators.test
new file mode 100644
index 000000000000..f122dbe842d0
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/named_bitwise_operators.test
@@ -0,0 +1,20 @@
+; RUN: llvm-ml -filetype=asm %s | FileCheck %s
+
+.data
+
+t1 BYTE NOT 1
+; CHECK: t1:
+; CHECK-NEXT: .byte -2
+
+t2 BYTE 1 OR 2
+; CHECK: t2:
+; CHECK-NEXT: .byte 3
+
+t3 BYTE 6 AND 10
+; CHECK: t3:
+; CHECK-NEXT: .byte 2
+
+.code
+xor eax, eax
+
+END
More information about the llvm-commits
mailing list