[PATCH] D44256: Allow targets to specify syntax of assignment in assembler output

Krzysztof Parzyszek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 8 09:40:34 PST 2018


kparzysz created this revision.
kparzysz added a reviewer: rafael.

The function EmitAssignment would simply print "x = y" for an assignment of y to x. On Hexagon "x = y" is a syntax used in most instructions, and is not treated as a directive.


Repository:
  rL LLVM

https://reviews.llvm.org/D44256

Files:
  include/llvm/MC/MCAsmInfo.h
  lib/MC/MCAsmInfo.cpp
  lib/MC/MCAsmStreamer.cpp
  lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp
  test/MC/Hexagon/assign.s


Index: test/MC/Hexagon/assign.s
===================================================================
--- /dev/null
+++ test/MC/Hexagon/assign.s
@@ -0,0 +1,7 @@
+# RUN: llvm-mc -arch=hexagon %s -filetype=asm -o - | FileCheck %s
+
+# Check that the assignment is printed using ".set".
+# CHECK: .set x, y
+
+.set x, y
+
Index: lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp
===================================================================
--- lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp
+++ lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp
@@ -28,6 +28,8 @@
   LCOMMDirectiveAlignmentType = LCOMM::ByteAlignment;
   InlineAsmStart = "# InlineAsm Start";
   InlineAsmEnd = "# InlineAsm End";
+  AssignmentDirective = ".set";
+  AssignmentOperator = ", ";
   ZeroDirective = "\t.space\t";
   AscizDirective = "\t.string\t";
 
Index: lib/MC/MCAsmStreamer.cpp
===================================================================
--- lib/MC/MCAsmStreamer.cpp
+++ lib/MC/MCAsmStreamer.cpp
@@ -528,8 +528,11 @@
 }
 
 void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
+  StringRef Dir = MAI->getAssignmentDirective();
+  if (!Dir.empty())
+    OS << Dir << ' ';
   Symbol->print(OS, MAI);
-  OS << " = ";
+  OS << MAI->getAssignmentOperator();
   Value->print(OS, MAI);
 
   EmitEOL();
Index: lib/MC/MCAsmInfo.cpp
===================================================================
--- lib/MC/MCAsmInfo.cpp
+++ lib/MC/MCAsmInfo.cpp
@@ -29,6 +29,8 @@
   LinkerPrivateGlobalPrefix = "";
   InlineAsmStart = "APP";
   InlineAsmEnd = "NO_APP";
+  AssignmentDirective = "";
+  AssignmentOperator = " = ";
   Code16Directive = ".code16";
   Code32Directive = ".code32";
   Code64Directive = ".code64";
Index: include/llvm/MC/MCAsmInfo.h
===================================================================
--- include/llvm/MC/MCAsmInfo.h
+++ include/llvm/MC/MCAsmInfo.h
@@ -128,6 +128,12 @@
   /// a plain private symbol should be used.  Defaults to "".
   StringRef LinkerPrivateGlobalPrefix;
 
+  /// For an assignment x = y, generate it as:
+  ///   AssignmentDirective x AssignmentOperator y
+  /// The default directive is empty and the default operator is '='.
+  const char *AssignmentDirective;
+  const char *AssignmentOperator;
+
   /// If these are nonempty, they contain a directive to emit before and after
   /// an inline assembly statement.  Defaults to "#APP\n", "#NO_APP\n"
   const char *InlineAsmStart;
@@ -486,6 +492,9 @@
     return getPrivateGlobalPrefix();
   }
 
+  const char *getAssignmentDirective() const { return AssignmentDirective; }
+  const char *getAssignmentOperator() const { return AssignmentOperator; }
+
   const char *getInlineAsmStart() const { return InlineAsmStart; }
   const char *getInlineAsmEnd() const { return InlineAsmEnd; }
   const char *getCode16Directive() const { return Code16Directive; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44256.137593.patch
Type: text/x-patch
Size: 2875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180308/1b3ad0f3/attachment.bin>


More information about the llvm-commits mailing list