[llvm] a3ec4a3 - [ms] [llvm-ml] Allow use of locally-defined variables in expressions
Eric Astor via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 11:00:34 PDT 2020
Author: Eric Astor
Date: 2020-09-07T14:00:14-04:00
New Revision: a3ec4a3158f3a60c16ac1e3550667866fe1d4171
URL: https://github.com/llvm/llvm-project/commit/a3ec4a3158f3a60c16ac1e3550667866fe1d4171
DIFF: https://github.com/llvm/llvm-project/commit/a3ec4a3158f3a60c16ac1e3550667866fe1d4171.diff
LOG: [ms] [llvm-ml] Allow use of locally-defined variables in expressions
MASM allows variables defined by equate statements to be used in expressions.
Reviewed By: thakis
Differential Revision: https://reviews.llvm.org/D86946
Added:
llvm/test/tools/llvm-ml/variable.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 333eef2f698f..4d62174f7e5e 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -3076,6 +3076,11 @@ bool MasmParser::parseDirectiveEquate(StringRef IDVal, StringRef Name,
SMLoc EndLoc, StartLoc = Lexer.getLoc();
if (parseExpression(Expr, EndLoc))
return addErrorSuffix(" in '" + Twine(IDVal) + "' directive");
+ MCSymbol *Sym = getContext().getOrCreateSymbol(Var.Name);
+ Sym->setRedefinable(Var.Redefinable);
+ Sym->setVariableValue(Expr);
+ Sym->setExternal(false);
+
if (Expr->evaluateAsAbsolute(Var.NumericValue,
getStreamer().getAssemblerPtr()))
return false;
diff --git a/llvm/test/tools/llvm-ml/variable.test b/llvm/test/tools/llvm-ml/variable.test
new file mode 100644
index 000000000000..4e89d67bd59d
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/variable.test
@@ -0,0 +1,13 @@
+# RUN: llvm-ml -filetype=asm %s | FileCheck %s
+
+.data
+t1_value equ 1 or 2
+
+t1 BYTE t1_value DUP (0)
+; CHECK: t1:
+; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .byte 0
+; CHECK-NEXT: .byte 0
+; CHECK-NOT: .byte 0
+
+END
More information about the llvm-commits
mailing list