[llvm-branch-commits] [llvm] 454f32e - [ms] [llvm-ml] Support macro function invocations in expressions

2020-11-23 Thread Eric Astor via llvm-branch-commits

Author: Eric Astor
Date: 2020-11-23T14:16:28-05:00
New Revision: 454f32e4d572a85693d99bbb61513c63a84a1388

URL: 
https://github.com/llvm/llvm-project/commit/454f32e4d572a85693d99bbb61513c63a84a1388
DIFF: 
https://github.com/llvm/llvm-project/commit/454f32e4d572a85693d99bbb61513c63a84a1388.diff

LOG: [ms] [llvm-ml] Support macro function invocations in expressions

Accept macro function definitions, and apply them when invoked in operand 
position.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D89734

Added: 
llvm/test/tools/llvm-ml/macro_function.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 9cdd2eb2cc93..d717cadf4e4a 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -108,6 +108,9 @@ struct ParseStatementInfo {
   /// Was there an error parsing the inline assembly?
   bool ParseError = false;
 
+  /// The value associated with a macro exit.
+  Optional ExitValue;
+
   SmallVectorImpl *AsmRewrites = nullptr;
 
   ParseStatementInfo() = delete;
@@ -368,6 +371,7 @@ class MasmParser : public MCAsmParser {
   /// This is the current buffer index we're lexing from as managed by the
   /// SourceMgr object.
   unsigned CurBuffer;
+  std::vector EndStatementAtEOFStack;
 
   AsmCond TheCondState;
   std::vector TheCondStack;
@@ -539,8 +543,6 @@ class MasmParser : public MCAsmParser {
   bool parseCurlyBlockScope(SmallVectorImpl& AsmStrRewrites);
   bool parseCppHashLineFilenameComment(SMLoc L);
 
-  void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
-ArrayRef Parameters);
   bool expandMacro(raw_svector_ostream &OS, StringRef Body,
ArrayRef Parameters,
ArrayRef A,
@@ -553,7 +555,15 @@ class MasmParser : public MCAsmParser {
   ///
   /// \param M The macro.
   /// \param NameLoc Instantiation location.
-  bool handleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc);
+  bool handleMacroEntry(
+  const MCAsmMacro *M, SMLoc NameLoc,
+  AsmToken::TokenKind ArgumentEndTok = AsmToken::EndOfStatement);
+
+  /// Handle invocation of macro function.
+  ///
+  /// \param M The macro.
+  /// \param NameLoc Invocation location.
+  bool handleMacroInvocation(const MCAsmMacro *M, SMLoc NameLoc);
 
   /// Handle exit from macro instantiation.
   void handleMacroExit();
@@ -593,7 +603,8 @@ class MasmParser : public MCAsmParser {
   ///
   /// \param InBuffer If not 0, should be the known buffer id that contains the
   /// location.
-  void jumpToLoc(SMLoc Loc, unsigned InBuffer = 0);
+  void jumpToLoc(SMLoc Loc, unsigned InBuffer = 0,
+ bool EndStatementAtEOF = true);
 
   /// Parse up to a token of kind \p EndTok and return the contents from the
   /// current token up to (but not including) this token; the current token on
@@ -901,7 +912,7 @@ class MasmParser : public MCAsmParser {
 
   // macro directives
   bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
-  bool parseDirectiveExitMacro(StringRef Directive);
+  bool parseDirectiveExitMacro(StringRef Directive, std::string &Value);
   bool parseDirectiveEndMacro(StringRef Directive);
   bool parseDirectiveMacro(StringRef Name, SMLoc NameLoc);
 
@@ -1011,6 +1022,7 @@ MasmParser::MasmParser(SourceMgr &SM, MCContext &Ctx, 
MCStreamer &Out,
   // Set our own handler which calls the saved handler.
   SrcMgr.setDiagHandler(DiagHandler, this);
   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
+  EndStatementAtEOFStack.push_back(true);
 
   // Initialize the platform / file format parser.
   switch (Ctx.getObjectFileInfo()->getObjectFileType()) {
@@ -1080,13 +1092,15 @@ bool MasmParser::enterIncludeFile(const std::string 
&Filename) {
 
   CurBuffer = NewBuf;
   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
+  EndStatementAtEOFStack.push_back(true);
   return false;
 }
 
-void MasmParser::jumpToLoc(SMLoc Loc, unsigned InBuffer) {
+void MasmParser::jumpToLoc(SMLoc Loc, unsigned InBuffer,
+   bool EndStatementAtEOF) {
   CurBuffer = InBuffer ? InBuffer : SrcMgr.FindBufferContainingLoc(Loc);
   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer(),
-  Loc.getPointer());
+  Loc.getPointer(), EndStatementAtEOF);
 }
 
 const AsmToken &MasmParser::Lex() {
@@ -1115,6 +1129,7 @@ const AsmToken &MasmParser::Lex() {
 getTok().getEndLoc());
   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer(), nullptr,
   /*EndStatementAtEOF=*/false);
+  EndStatementAtEOFStack.push_back(false);
   tok = &Lexer.Lex();
 } else {
   break;
@@ -1141,9 +1156,12 @@ const AsmToken &MasmParser::Lex() {
 // include stack.
 SMLoc ParentIncl

[llvm-branch-commits] [llvm] 1e41e22 - [ms] [llvm-ml] Support purging macro definitions

2020-11-23 Thread Eric Astor via llvm-branch-commits

Author: Eric Astor
Date: 2020-11-23T15:03:13-05:00
New Revision: 1e41e22323a33d7b7977e48ff6ec243e46860257

URL: 
https://github.com/llvm/llvm-project/commit/1e41e22323a33d7b7977e48ff6ec243e46860257
DIFF: 
https://github.com/llvm/llvm-project/commit/1e41e22323a33d7b7977e48ff6ec243e46860257.diff

LOG: [ms] [llvm-ml] Support purging macro definitions

Support MASM's PURGE directive.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D89735

Added: 


Modified: 
llvm/lib/MC/MCParser/COFFMasmParser.cpp
llvm/lib/MC/MCParser/MasmParser.cpp
llvm/test/tools/llvm-ml/macro.test

Removed: 




diff  --git a/llvm/lib/MC/MCParser/COFFMasmParser.cpp 
b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
index 61d69ee4e7e8..aacce928c141 100644
--- a/llvm/lib/MC/MCParser/COFFMasmParser.cpp
+++ b/llvm/lib/MC/MCParser/COFFMasmParser.cpp
@@ -118,9 +118,7 @@ class COFFMasmParser : public MCAsmParserExtension {
 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>("title");
 
 // Macro directives
-// exitm
 // goto
-// purge
 
 // Miscellaneous directives
 addDirectiveHandler<&COFFMasmParser::ParseDirectiveAlias>("alias");
@@ -153,9 +151,6 @@ class COFFMasmParser : public MCAsmParserExtension {
 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(".mmx");
 addDirectiveHandler<&COFFMasmParser::IgnoreDirective>(".xmm");
 
-// Repeat blocks directives
-// goto
-
 // Scope directives
 // comm
 // externdef

diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp 
b/llvm/lib/MC/MCParser/MasmParser.cpp
index d717cadf4e4a..9b63148c6860 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -734,7 +734,7 @@ class MasmParser : public MCAsmParser {
 DK_MACRO,
 DK_EXITM,
 DK_ENDM,
-DK_PURGEM,
+DK_PURGE,
 DK_ERR,
 DK_ERRB,
 DK_ERRNB,
@@ -2311,7 +2311,7 @@ bool MasmParser::parseStatement(ParseStatementInfo &Info,
 case DK_ENDM:
   Info.ExitValue = "";
   return parseDirectiveEndMacro(IDVal);
-case DK_PURGEM:
+case DK_PURGE:
   return parseDirectivePurgeMacro(IDLoc);
 case DK_END:
   return parseDirectiveEnd(IDLoc);
@@ -5544,23 +5544,27 @@ bool MasmParser::parseDirectiveEndMacro(StringRef 
Directive) {
 }
 
 /// parseDirectivePurgeMacro
-/// ::= .purgem
+/// ::= purge identifier ( , identifier )*
 bool MasmParser::parseDirectivePurgeMacro(SMLoc DirectiveLoc) {
   StringRef Name;
-  SMLoc Loc;
-  if (parseTokenLoc(Loc) ||
-  check(parseIdentifier(Name), Loc,
-"expected identifier in '.purgem' directive") ||
-  parseToken(AsmToken::EndOfStatement,
- "unexpected token in '.purgem' directive"))
-return true;
+  while (true) {
+SMLoc NameLoc;
+if (parseTokenLoc(NameLoc) ||
+check(parseIdentifier(Name), NameLoc,
+  "expected identifier in 'purge' directive"))
+  return true;
 
-  if (!getContext().lookupMacro(Name))
-return Error(DirectiveLoc, "macro '" + Name + "' is not defined");
+DEBUG_WITH_TYPE("asm-macros", dbgs()
+  << "Un-defining macro: " << Name << 
"\n");
+if (!getContext().lookupMacro(Name))
+  return Error(NameLoc, "macro '" + Name + "' is not defined");
+getContext().undefineMacro(Name);
+
+if (!parseOptionalToken(AsmToken::Comma))
+  break;
+parseOptionalToken(AsmToken::EndOfStatement);
+  }
 
-  getContext().undefineMacro(Name);
-  DEBUG_WITH_TYPE("asm-macros", dbgs()
-<< "Un-defining macro: " << Name << "\n");
   return false;
 }
 
@@ -6322,7 +6326,7 @@ void MasmParser::initializeDirectiveKindMap() {
   DirectiveKindMap["macro"] = DK_MACRO;
   DirectiveKindMap["exitm"] = DK_EXITM;
   DirectiveKindMap["endm"] = DK_ENDM;
-  // DirectiveKindMap[".purgem"] = DK_PURGEM;
+  DirectiveKindMap["purge"] = DK_PURGE;
   DirectiveKindMap[".err"] = DK_ERR;
   DirectiveKindMap[".errb"] = DK_ERRB;
   DirectiveKindMap[".errnb"] = DK_ERRNB;

diff  --git a/llvm/test/tools/llvm-ml/macro.test 
b/llvm/test/tools/llvm-ml/macro.test
index 255cd485e36b..3a356c0abe3e 100644
--- a/llvm/test/tools/llvm-ml/macro.test
+++ b/llvm/test/tools/llvm-ml/macro.test
@@ -134,4 +134,23 @@ local_symbol_test PROC
 ; CHECK-NEXT: jmp "??0001"
 local_symbol_test ENDP
 
+PURGE ambiguous_substitution_macro, local_symbol_macro,
+  optional_parameter_macro
+
+; Redefinition
+local_symbol_macro MACRO
+  LOCAL b
+b: xor eax, eax
+   jmp b
+ENDM
+
+purge_test PROC
+; CHECK-LABEL: purge_test:
+
+  local_symbol_macro
+; CHECK: "??0002":
+; CHECK-NEXT: xor eax, eax
+; CHECK-NEXT: jmp "??0002"
+purge_test ENDP
+
 END



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 35828b8 - [ms] [llvm-ml] Implement the expression expansion operator

2020-11-25 Thread Eric Astor via llvm-branch-commits

Author: Eric Astor
Date: 2020-11-25T16:11:00-05:00
New Revision: 35828b84a5232df020d6de250c3c268e2ccaaf11

URL: 
https://github.com/llvm/llvm-project/commit/35828b84a5232df020d6de250c3c268e2ccaaf11
DIFF: 
https://github.com/llvm/llvm-project/commit/35828b84a5232df020d6de250c3c268e2ccaaf11.diff

LOG: [ms] [llvm-ml] Implement the expression expansion operator

In text-item contexts, %expr expands to a string containing the results of 
evaluating `expr`.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D89736

Added: 


Modified: 
llvm/lib/MC/MCParser/MasmParser.cpp
llvm/test/tools/llvm-ml/macro_function.test

Removed: 




diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp 
b/llvm/lib/MC/MCParser/MasmParser.cpp
index 9b63148c6860..8b5d4b85a58b 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -912,7 +912,8 @@ class MasmParser : public MCAsmParser {
 
   // macro directives
   bool parseDirectivePurgeMacro(SMLoc DirectiveLoc);
-  bool parseDirectiveExitMacro(StringRef Directive, std::string &Value);
+  bool parseDirectiveExitMacro(SMLoc DirectiveLoc, StringRef Directive,
+   std::string &Value);
   bool parseDirectiveEndMacro(StringRef Directive);
   bool parseDirectiveMacro(StringRef Name, SMLoc NameLoc);
 
@@ -2307,7 +2308,7 @@ bool MasmParser::parseStatement(ParseStatementInfo &Info,
   return parseDirectiveCFIWindowSave();
 case DK_EXITM:
   Info.ExitValue = "";
-  return parseDirectiveExitMacro(IDVal, *Info.ExitValue);
+  return parseDirectiveExitMacro(IDLoc, IDVal, *Info.ExitValue);
 case DK_ENDM:
   Info.ExitValue = "";
   return parseDirectiveEndMacro(IDVal);
@@ -3207,7 +3208,7 @@ bool MasmParser::parseDirectiveEquate(StringRef IDVal, 
StringRef Name,
   // Accept a text-list, not just one text-item.
   auto parseItem = [&]() -> bool {
 if (parseTextItem(Value))
-  return true;
+  return TokError("expected text item");
 Var.TextValue += Value;
 return false;
   };
@@ -3283,8 +3284,38 @@ bool MasmParser::parseAngleBracketString(std::string 
&Data) {
 
 /// textItem ::= textLiteral | textMacroID | % constExpr
 bool MasmParser::parseTextItem(std::string &Data) {
-  // TODO(epastor): Support textMacroID and % expansion of expressions.
-  return parseAngleBracketString(Data);
+  switch (getTok().getKind()) {
+  default:
+return true;
+  case AsmToken::Percent: {
+int64_t Res;
+if (parseToken(AsmToken::Percent) || parseAbsoluteExpression(Res))
+  return true;
+Data = std::to_string(Res);
+return false;
+  }
+  case AsmToken::Less:
+  case AsmToken::LessEqual:
+  case AsmToken::LessLess:
+  case AsmToken::LessGreater:
+return parseAngleBracketString(Data);
+  case AsmToken::Identifier: {
+StringRef ID;
+if (parseIdentifier(ID))
+  return true;
+
+auto it = Variables.find(ID);
+if (it == Variables.end())
+  return true;
+
+const Variable &Var = it->second;
+if (!Var.IsText)
+  return true;
+Data = Var.TextValue;
+return false;
+  }
+  }
+  llvm_unreachable("unhandled token kind");
 }
 
 /// parseDirectiveAscii:
@@ -5503,11 +5534,13 @@ bool MasmParser::parseDirectiveMacro(StringRef Name, 
SMLoc NameLoc) {
 
 /// parseDirectiveExitMacro
 /// ::= "exitm" [textitem]
-bool MasmParser::parseDirectiveExitMacro(StringRef Directive,
+bool MasmParser::parseDirectiveExitMacro(SMLoc DirectiveLoc,
+ StringRef Directive,
  std::string &Value) {
-  if (getTok().isNot(AsmToken::EndOfStatement)) {
-parseTextItem(Value);
-  }
+  SMLoc EndLoc = getTok().getLoc();
+  if (getTok().isNot(AsmToken::EndOfStatement) && parseTextItem(Value))
+return Error(EndLoc,
+ "unable to parse text item in '" + Directive + "' directive");
   eatToEndOfStatement();
 
   if (!isInsideMacroInstantiation())
@@ -5740,7 +5773,7 @@ bool MasmParser::parseDirectiveIf(SMLoc DirectiveLoc, 
DirectiveKind DirKind) {
 }
 
 /// parseDirectiveIfb
-/// ::= .ifb string
+/// ::= .ifb textitem
 bool MasmParser::parseDirectiveIfb(SMLoc DirectiveLoc, bool ExpectBlank) {
   TheCondStack.push_back(TheCondState);
   TheCondState.TheCond = AsmCond::IfCond;
@@ -5750,7 +5783,7 @@ bool MasmParser::parseDirectiveIfb(SMLoc DirectiveLoc, 
bool ExpectBlank) {
   } else {
 std::string Str;
 if (parseTextItem(Str))
-  return TokError("expected string parameter for 'ifb' directive");
+  return TokError("expected text item parameter for 'ifb' directive");
 
 if (parseToken(AsmToken::EndOfStatement,
"unexpected token in 'ifb' directive"))
@@ -5764,14 +5797,15 @@ bool MasmParser::parseDirectiveIfb(SMLoc DirectiveLoc, 
bool ExpectBlank) {
 }
 
 /// parseDirectiveIfidn
-///   ::= ifidn string1, string2
-boo

[llvm-branch-commits] [llvm] abef659 - [ms] [llvm-ml] Implement the statement expansion operator

2020-11-30 Thread Eric Astor via llvm-branch-commits

Author: Eric Astor
Date: 2020-11-30T14:33:24-05:00
New Revision: abef659a45fff4147f8f0ffd1d0f6600185e4a4e

URL: 
https://github.com/llvm/llvm-project/commit/abef659a45fff4147f8f0ffd1d0f6600185e4a4e
DIFF: 
https://github.com/llvm/llvm-project/commit/abef659a45fff4147f8f0ffd1d0f6600185e4a4e.diff

LOG: [ms] [llvm-ml] Implement the statement expansion operator

If prefaced with a %, expand text macros and macro functions in any statement.

Also, prevent expanding text macros in the message of an ECHO directive unless 
expanded explicitly by the statement expansion operator.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D89740

Added: 
llvm/test/tools/llvm-ml/expansion.test

Modified: 
llvm/include/llvm/MC/MCAsmMacro.h
llvm/lib/MC/MCParser/MasmParser.cpp

Removed: 




diff  --git a/llvm/include/llvm/MC/MCAsmMacro.h 
b/llvm/include/llvm/MC/MCAsmMacro.h
index 1177853fec96..e3d6a858132d 100644
--- a/llvm/include/llvm/MC/MCAsmMacro.h
+++ b/llvm/include/llvm/MC/MCAsmMacro.h
@@ -144,13 +144,15 @@ struct MCAsmMacro {
   StringRef Body;
   MCAsmMacroParameters Parameters;
   std::vector Locals;
+  bool IsFunction = false;
 
 public:
   MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P)
   : Name(N), Body(B), Parameters(std::move(P)) {}
   MCAsmMacro(StringRef N, StringRef B, MCAsmMacroParameters P,
- std::vector L)
-  : Name(N), Body(B), Parameters(std::move(P)), Locals(std::move(L)) {}
+ std::vector L, bool F)
+  : Name(N), Body(B), Parameters(std::move(P)), Locals(std::move(L)),
+IsFunction(F) {}
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   void dump() const { dump(dbgs()); }

diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp 
b/llvm/lib/MC/MCParser/MasmParser.cpp
index 8b5d4b85a58b..709f1ea1173d 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -579,6 +579,9 @@ class MasmParser : public MCAsmParser {
   AsmToken::TokenKind EndTok = AsmToken::EndOfStatement);
 
   void printMacroInstantiations();
+
+  bool expandStatement(SMLoc Loc);
+
   void printMessage(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Msg,
 SMRange Range = None) const {
 ArrayRef Ranges(Range);
@@ -608,15 +611,15 @@ class MasmParser : public MCAsmParser {
 
   /// Parse up to a token of kind \p EndTok and return the contents from the
   /// current token up to (but not including) this token; the current token on
-  /// exit will be either this kind or EOF.
-  StringRef parseStringTo(AsmToken::TokenKind EndTok);
+  /// exit will be either this kind or EOF. Reads through instantiated macro
+  /// functions and text macros.
+  SmallVector parseStringRefsTo(AsmToken::TokenKind EndTok);
+  std::string parseStringTo(AsmToken::TokenKind EndTok);
 
   /// Parse up to the end of statement and return the contents from the current
   /// token until the end of the statement; the current token on exit will be
   /// either the EndOfStatement or EOF.
-  StringRef parseStringToEndOfStatement() override {
-return parseStringTo(AsmToken::EndOfStatement);
-  }
+  StringRef parseStringToEndOfStatement() override;
 
   bool parseTextItem(std::string &Data);
 
@@ -1119,8 +1122,11 @@ const AsmToken &MasmParser::Lex() {
   const AsmToken *tok = &Lexer.Lex();
 
   while (tok->is(AsmToken::Identifier)) {
-auto it = Variables.find(tok->getIdentifier());
+auto it = Variables.find(tok->getIdentifier().lower());
+const llvm::MCAsmMacro *M =
+getContext().lookupMacro(tok->getIdentifier().lower());
 if (it != Variables.end() && it->second.IsText) {
+  // This is a textmacro; expand it in place.
   std::unique_ptr Instantiation =
   MemoryBuffer::getMemBufferCopy(it->second.TextValue,
  "");
@@ -1132,6 +1138,15 @@ const AsmToken &MasmParser::Lex() {
   /*EndStatementAtEOF=*/false);
   EndStatementAtEOFStack.push_back(false);
   tok = &Lexer.Lex();
+} else if (M && M->IsFunction && Lexer.peekTok().is(AsmToken::LParen)) {
+  // This is a macro function invocation; expand it in place.
+  const AsmToken MacroTok = *tok;
+  tok = &Lexer.Lex();
+  if (handleMacroInvocation(M, MacroTok.getLoc())) {
+Lexer.UnLex(AsmToken(AsmToken::Error, MacroTok.getIdentifier()));
+tok = &Lexer.Lex();
+  }
+  continue;
 } else {
   break;
 }
@@ -1221,7 +1236,12 @@ bool MasmParser::Run(bool NoInitialTextSection, bool 
NoFinalize) {
   }
 
   // While we have input, parse each statement.
-  while (Lexer.isNot(AsmToken::Eof)) {
+  while (Lexer.isNot(AsmToken::Eof) ||
+ SrcMgr.getParentIncludeLoc(CurBuffer) != SMLoc()) {
+// Skip through the EOF at the end of an inclusion.
+if (Lexer.is(AsmToken::Eof))
+  Lex();
+
 ParseStatementInfo Info(&AsmStr

[llvm-branch-commits] [llvm] e5c17b2 - [ms] [llvm-ml] Test macro function invocations in arbitrary positions

2020-11-30 Thread Eric Astor via llvm-branch-commits

Author: Eric Astor
Date: 2020-11-30T15:13:23-05:00
New Revision: e5c17b2deea5620dcc736a9dad5def219f86e4da

URL: 
https://github.com/llvm/llvm-project/commit/e5c17b2deea5620dcc736a9dad5def219f86e4da
DIFF: 
https://github.com/llvm/llvm-project/commit/e5c17b2deea5620dcc736a9dad5def219f86e4da.diff

LOG: [ms] [llvm-ml] Test macro function invocations in arbitrary positions

Differential Revision: https://reviews.llvm.org/D89741

Added: 


Modified: 
llvm/test/tools/llvm-ml/macro_function.test

Removed: 




diff  --git a/llvm/test/tools/llvm-ml/macro_function.test 
b/llvm/test/tools/llvm-ml/macro_function.test
index 98b3f25aabc8..94164b5c60a3 100644
--- a/llvm/test/tools/llvm-ml/macro_function.test
+++ b/llvm/test/tools/llvm-ml/macro_function.test
@@ -103,4 +103,14 @@ expr_recursive_test PROC
   ret
 expr_recursive_test ENDP
 
+custom_strcat MACRO arg1, arg2
+  EXITM 
+ENDM
+
+expand_as_directive_test custom_strcat(P, ROC)
+; CHECK-LABEL: expand_as_directive_test:
+
+  ret
+expand_as_directive_test ENDP
+
 end



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 8fee2ee - [ms] [llvm-ml] Introduce command-line compatibility for ml.exe and ml64.exe

2020-12-01 Thread Eric Astor via llvm-branch-commits

Author: Eric Astor
Date: 2020-12-01T17:43:44-05:00
New Revision: 8fee2ee9a689276eaea61d4c3f124aa80a81b6f7

URL: 
https://github.com/llvm/llvm-project/commit/8fee2ee9a689276eaea61d4c3f124aa80a81b6f7
DIFF: 
https://github.com/llvm/llvm-project/commit/8fee2ee9a689276eaea61d4c3f124aa80a81b6f7.diff

LOG: [ms] [llvm-ml] Introduce command-line compatibility for ml.exe and ml64.exe

Switch to OptParser for command-line handling

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D90058

Added: 
llvm/test/tools/llvm-ml/alias.asm
llvm/test/tools/llvm-ml/alias_errors.asm
llvm/test/tools/llvm-ml/basic_data.asm
llvm/test/tools/llvm-ml/builtin_types.asm
llvm/test/tools/llvm-ml/dot_operator.asm
llvm/test/tools/llvm-ml/expansion.asm
llvm/test/tools/llvm-ml/feat00.asm
llvm/test/tools/llvm-ml/feat00_override.asm
llvm/test/tools/llvm-ml/line_continuations.asm
llvm/test/tools/llvm-ml/macro.asm
llvm/test/tools/llvm-ml/macro_errors.asm
llvm/test/tools/llvm-ml/macro_function.asm
llvm/test/tools/llvm-ml/named_operators.asm
llvm/test/tools/llvm-ml/proc.asm
llvm/test/tools/llvm-ml/proc_frame.asm
llvm/test/tools/llvm-ml/radix.asm
llvm/test/tools/llvm-ml/radix_errors.asm
llvm/test/tools/llvm-ml/repeat_directives.asm
llvm/test/tools/llvm-ml/rip-relative-addressing.asm
llvm/test/tools/llvm-ml/run.asm
llvm/test/tools/llvm-ml/size_inference.asm
llvm/test/tools/llvm-ml/strings.asm
llvm/test/tools/llvm-ml/strings_errors.asm
llvm/test/tools/llvm-ml/struct.asm
llvm/test/tools/llvm-ml/struct_alignment.asm
llvm/test/tools/llvm-ml/struct_errors.asm
llvm/test/tools/llvm-ml/type_operators.asm
llvm/test/tools/llvm-ml/variable.asm
llvm/tools/llvm-ml/Opts.td

Modified: 
llvm/test/tools/llvm-ml/basic.test
llvm/test/tools/llvm-ml/lit.local.cfg
llvm/tools/llvm-ml/CMakeLists.txt
llvm/tools/llvm-ml/llvm-ml.cpp

Removed: 
llvm/test/tools/llvm-ml/alias.test
llvm/test/tools/llvm-ml/alias_errors.test
llvm/test/tools/llvm-ml/basic_data.test
llvm/test/tools/llvm-ml/builtin_types.test
llvm/test/tools/llvm-ml/dot_operator.test
llvm/test/tools/llvm-ml/expansion.test
llvm/test/tools/llvm-ml/feat00.test
llvm/test/tools/llvm-ml/feat00_override.test
llvm/test/tools/llvm-ml/line_continuations.test
llvm/test/tools/llvm-ml/macro.test
llvm/test/tools/llvm-ml/macro_errors.test
llvm/test/tools/llvm-ml/macro_function.test
llvm/test/tools/llvm-ml/named_operators.test
llvm/test/tools/llvm-ml/proc.test
llvm/test/tools/llvm-ml/proc_frame.test
llvm/test/tools/llvm-ml/radix.test
llvm/test/tools/llvm-ml/radix_errors.test
llvm/test/tools/llvm-ml/repeat_directives.test
llvm/test/tools/llvm-ml/rip-relative-addressing.test
llvm/test/tools/llvm-ml/run.test
llvm/test/tools/llvm-ml/size_inference.test
llvm/test/tools/llvm-ml/strings.test
llvm/test/tools/llvm-ml/strings_errors.test
llvm/test/tools/llvm-ml/struct.test
llvm/test/tools/llvm-ml/struct_alignment.test
llvm/test/tools/llvm-ml/struct_errors.test
llvm/test/tools/llvm-ml/type_operators.test
llvm/test/tools/llvm-ml/variable.test



diff  --git a/llvm/test/tools/llvm-ml/alias.test 
b/llvm/test/tools/llvm-ml/alias.asm
similarity index 96%
rename from llvm/test/tools/llvm-ml/alias.test
rename to llvm/test/tools/llvm-ml/alias.asm
index 2daaecdbbcc0..bd21f2b01c01 100644
--- a/llvm/test/tools/llvm-ml/alias.test
+++ b/llvm/test/tools/llvm-ml/alias.asm
@@ -1,4 +1,4 @@
-; RUN: llvm-ml -filetype=obj %s | llvm-readobj --syms - | FileCheck %s
+; RUN: llvm-ml %s /Fo - | llvm-readobj --syms - | FileCheck %s
 
 .code
 

diff  --git a/llvm/test/tools/llvm-ml/alias_errors.test 
b/llvm/test/tools/llvm-ml/alias_errors.asm
similarity index 87%
rename from llvm/test/tools/llvm-ml/alias_errors.test
rename to llvm/test/tools/llvm-ml/alias_errors.asm
index 9d51b2a993ac..7c30b8e261a2 100644
--- a/llvm/test/tools/llvm-ml/alias_errors.test
+++ b/llvm/test/tools/llvm-ml/alias_errors.asm
@@ -1,4 +1,4 @@
-; RUN: not llvm-ml -filetype=asm %s 2>&1 | FileCheck %s
+; RUN: not llvm-ml -filetype=s %s /Fo /dev/null 2>&1 | FileCheck %s
 
 .code
 

diff  --git a/llvm/test/tools/llvm-ml/basic.test 
b/llvm/test/tools/llvm-ml/basic.test
index 30aa860f2b90..960eb47f6cc5 100644
--- a/llvm/test/tools/llvm-ml/basic.test
+++ b/llvm/test/tools/llvm-ml/basic.test
@@ -1,3 +1,3 @@
-# RUN: not llvm-ml %t.blah -o /dev/null 2>&1 | FileCheck --check-prefix=ENOENT 
%s
+# RUN: not llvm-ml %t.blah.asm /Fo /dev/null 2>&1 | FileCheck 
--check-prefix=ENOENT %s
 
-# ENOENT: {{.*}}.blah: {{[Nn]}}o such file or directory
+# ENOENT: {{.*}}.blah.asm: {{[Nn]}}o such file or directory

diff  --git a/llvm/test/tools/llvm-ml/basic_data.test 
b/llvm/test/tools/llvm-ml/basic_data.asm
similarity index 92%
rename from llvm/test/tools/llvm-ml/basic_data.test
rename to l

[llvm-branch-commits] [llvm] c64037b - [ms] [llvm-ml] Support command-line defines

2020-12-01 Thread Eric Astor via llvm-branch-commits

Author: Eric Astor
Date: 2020-12-01T18:06:05-05:00
New Revision: c64037b784aeae63b1863ee1abd5601c2c6a8102

URL: 
https://github.com/llvm/llvm-project/commit/c64037b784aeae63b1863ee1abd5601c2c6a8102
DIFF: 
https://github.com/llvm/llvm-project/commit/c64037b784aeae63b1863ee1abd5601c2c6a8102.diff

LOG: [ms] [llvm-ml] Support command-line defines

Enable command-line defines as textmacros

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D90059

Added: 
llvm/test/tools/llvm-ml/command_line_defines.asm

Modified: 
llvm/include/llvm/MC/MCParser/MCAsmParser.h
llvm/lib/MC/MCParser/MasmParser.cpp
llvm/tools/llvm-ml/Opts.td
llvm/tools/llvm-ml/llvm-ml.cpp

Removed: 




diff  --git a/llvm/include/llvm/MC/MCParser/MCAsmParser.h 
b/llvm/include/llvm/MC/MCParser/MCAsmParser.h
index 2040810eac14..391a6b0b575e 100644
--- a/llvm/include/llvm/MC/MCParser/MCAsmParser.h
+++ b/llvm/include/llvm/MC/MCParser/MCAsmParser.h
@@ -184,6 +184,8 @@ class MCAsmParser {
 
   virtual bool isParsingMasm() const { return false; }
 
+  virtual bool defineMacro(StringRef Name, StringRef Value) { return true; }
+
   virtual bool lookUpField(StringRef Name, AsmFieldInfo &Info) const {
 return true;
   }

diff  --git a/llvm/lib/MC/MCParser/MasmParser.cpp 
b/llvm/lib/MC/MCParser/MasmParser.cpp
index 709f1ea1173d..63aebbc5a7ba 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -501,6 +501,8 @@ class MasmParser : public MCAsmParser {
 
   bool isParsingMasm() const override { return true; }
 
+  bool defineMacro(StringRef Name, StringRef Value) override;
+
   bool lookUpField(StringRef Name, AsmFieldInfo &Info) const override;
   bool lookUpField(StringRef Base, StringRef Member,
AsmFieldInfo &Info) const override;
@@ -6905,6 +6907,19 @@ static int rewritesSort(const AsmRewrite *AsmRewriteA,
   llvm_unreachable("Unstable rewrite sort.");
 }
 
+bool MasmParser::defineMacro(StringRef Name, StringRef Value) {
+  Variable &Var = Variables[Name.lower()];
+  if (Var.Name.empty()) {
+Var.Name = Name;
+  } else if (!Var.Redefinable) {
+return TokError("invalid variable redefinition");
+  }
+  Var.Redefinable = true;
+  Var.IsText = true;
+  Var.TextValue = Value.str();
+  return false;
+}
+
 bool MasmParser::lookUpField(StringRef Name, AsmFieldInfo &Info) const {
   const std::pair BaseMember = Name.split('.');
   const StringRef Base = BaseMember.first, Member = BaseMember.second;

diff  --git a/llvm/test/tools/llvm-ml/command_line_defines.asm 
b/llvm/test/tools/llvm-ml/command_line_defines.asm
new file mode 100644
index ..51b02e6ebb4a
--- /dev/null
+++ b/llvm/test/tools/llvm-ml/command_line_defines.asm
@@ -0,0 +1,38 @@
+; RUN: llvm-ml -filetype=s %s /Fo - /DT1=test1 /D T2=test2 | FileCheck %s
+
+.code
+
+t1:
+  ret
+; CHECK-NOT: t1:
+; CHECK-LABEL: test1:
+; CHECK-NOT: t1:
+
+t2:
+  ret
+; CHECK-NOT: t2:
+; CHECK-LABEL: test2:
+; CHECK-NOT: t2:
+
+t3:
+ifdef t1
+  xor eax, eax
+endif
+  ret
+; CHECK-LABEL: t3:
+; CHECK: xor eax, eax
+; CHECK: ret
+
+t4:
+ifdef undefined
+  xor eax, eax
+elseifdef t2
+  xor ebx, ebx
+endif
+  ret
+; CHECK-LABEL: t4:
+; CHECK-NOT: xor eax, eax
+; CHECK: xor ebx, ebx
+; CHECK: ret
+
+end

diff  --git a/llvm/tools/llvm-ml/Opts.td b/llvm/tools/llvm-ml/Opts.td
index ed52bb4771ba..4c2757b05722 100644
--- a/llvm/tools/llvm-ml/Opts.td
+++ b/llvm/tools/llvm-ml/Opts.td
@@ -31,6 +31,9 @@ def help : MLFlag<"?">,
HelpText<"Display available options">;
 def help_long : MLFlag<"help">, Alias;
 def assemble_only : MLFlag<"c">, HelpText<"Assemble only; do not link">;
+def define : MLJoinedOrSeparate<"D">, MetaVarName<"=">,
+ HelpText<"Define  to  (or blank if  "
+  "omitted)">;
 def output_file : MLJoinedOrSeparate<"Fo">, HelpText<"Names the output file">;
 def include_path : MLJoinedOrSeparate<"I">,
HelpText<"Sets path for include files">;
@@ -72,7 +75,6 @@ def coff_object_file : UnsupportedFlag<"coff">, HelpText<"">;
 def preserve_identifier_case : UnsupportedFlag<"Cp">, HelpText<"">;
 def uppercase_identifiers : UnsupportedFlag<"Cu">, HelpText<"">;
 def preserve_extern_case : UnsupportedFlag<"Cx">, HelpText<"">;
-def define : UnsupportedJoinedOrSeparate<"D">, HelpText<"">;
 def output_preprocessed : UnsupportedFlag<"EP">, HelpText<"">;
 def errorreport : UnsupportedJoined<"ERRORREPORT">, HelpText<"">;
 def stacksize : UnsupportedSeparate<"F">, HelpText<"">;

diff  --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp
index ac03ef826c58..1733dcd47281 100644
--- a/llvm/tools/llvm-ml/llvm-ml.cpp
+++ b/llvm/tools/llvm-ml/llvm-ml.cpp
@@ -147,6 +147,17 @@ static int AssembleInput(StringRef ProgName, const Target 
*TheTarget,
   Parser->getLexer().setLexMasmHexFloats(true);
   Parser->getLexer().setLexMasmStrings(true);
 
+  auto Defines = InputArgs.getA