From cab8aac049bb3e597a9b575bafcc67281b6702f8 Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@sandoe.co.uk>
Date: Mon, 26 Dec 2016 14:16:22 +0000
Subject: [PATCH] [llvm,Darwin,ppc] Allow $ as PC value.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Support the same syntax variants as “cctools as”.  We only need to succeed in parsing, but do some limited checking too.
---
 .../PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp     |  6 +++++-
 .../test/MC/PowerPC/darwin-accept-dollar-pc.s | 20 +++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/MC/PowerPC/darwin-accept-dollar-pc.s

diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
index fb7bf23509c..7fbef776e63 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCAsmInfo.cpp
@@ -24,8 +24,12 @@ PPCMCAsmInfoDarwin::PPCMCAsmInfoDarwin(bool is64Bit, const Triple& T) {
   }
   IsLittleEndian = false;
 
-  SeparatorString = "@";
+  // Use the same comment and separator markers as cctools.
   CommentString = ";";
+  SeparatorString = "@";
+  // ... and PC.
+  DollarIsPC = true;
+
   ExceptionsType = ExceptionHandling::DwarfCFI;
 
   if (!is64Bit)
diff --git a/llvm/test/MC/PowerPC/darwin-accept-dollar-pc.s b/llvm/test/MC/PowerPC/darwin-accept-dollar-pc.s
new file mode 100644
index 00000000000..e5619d45509
--- /dev/null
+++ b/llvm/test/MC/PowerPC/darwin-accept-dollar-pc.s
@@ -0,0 +1,20 @@
+# RUN:llvm-mc -triple=powerpc-apple-darwin -filetype=obj %s | llvm-objdump -s - | \
+# RUN:        FileCheck %s --check-prefix=CHECK
+# RUN:llvm-mc -triple=powerpc64-apple-darwin -filetype=obj %s | llvm-objdump -s - | \
+# RUN:        FileCheck %s --check-prefix=CHECK
+
+# This checks that we correctly accept both '.' and '$' as representing "current
+# PC".  In principle, it would be enough to pass parsing, but we might as well
+# check for correct output too.
+
+	.text
+
+Lfoo:
+	.long 5
+	.long .-Lfoo
+	.long $-Lfoo
+	.long Lfoo-$
+	.long Lfoo-.
+
+# CHECK: 00000005 00000004 00000008 fffffff4
+
