[llvm] r198028 - [Sparc] Add MCInstPrinter implementation for SPARC.

Venkatraman Govindaraju venkatra at cs.wisc.edu
Wed Dec 25 15:43:40 PST 2013


Author: venkatra
Date: Wed Dec 25 17:43:39 2013
New Revision: 198028

URL: http://llvm.org/viewvc/llvm-project?rev=198028&view=rev
Log:
[Sparc] Add MCInstPrinter implementation for SPARC.

Added:
    llvm/trunk/lib/Target/Sparc/InstPrinter/
    llvm/trunk/lib/Target/Sparc/InstPrinter/CMakeLists.txt
    llvm/trunk/lib/Target/Sparc/InstPrinter/LLVMBuild.txt
    llvm/trunk/lib/Target/Sparc/InstPrinter/Makefile
    llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp
    llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.h
Modified:
    llvm/trunk/lib/Target/Sparc/CMakeLists.txt
    llvm/trunk/lib/Target/Sparc/LLVMBuild.txt
    llvm/trunk/lib/Target/Sparc/Makefile

Modified: llvm/trunk/lib/Target/Sparc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/CMakeLists.txt?rev=198028&r1=198027&r2=198028&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/CMakeLists.txt (original)
+++ llvm/trunk/lib/Target/Sparc/CMakeLists.txt Wed Dec 25 17:43:39 2013
@@ -27,3 +27,4 @@ add_llvm_target(SparcCodeGen
 
 add_subdirectory(TargetInfo)
 add_subdirectory(MCTargetDesc)
+add_subdirectory(InstPrinter)

Added: llvm/trunk/lib/Target/Sparc/InstPrinter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/InstPrinter/CMakeLists.txt?rev=198028&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Sparc/InstPrinter/CMakeLists.txt (added)
+++ llvm/trunk/lib/Target/Sparc/InstPrinter/CMakeLists.txt Wed Dec 25 17:43:39 2013
@@ -0,0 +1,3 @@
+add_llvm_library(LLVMSparcAsmPrinter
+  SparcInstPrinter.cpp
+  )

Added: llvm/trunk/lib/Target/Sparc/InstPrinter/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/InstPrinter/LLVMBuild.txt?rev=198028&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Sparc/InstPrinter/LLVMBuild.txt (added)
+++ llvm/trunk/lib/Target/Sparc/InstPrinter/LLVMBuild.txt Wed Dec 25 17:43:39 2013
@@ -0,0 +1,23 @@
+;===- ./lib/Target/Sparc/InstPrinter/LLVMBuild.txt -------------*- Conf -*--===;
+;
+;                     The LLVM Compiler Infrastructure
+;
+; This file is distributed under the University of Illinois Open Source
+; License. See LICENSE.TXT for details.
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+;   http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Library
+name = SparcAsmPrinter
+parent = Sparc
+required_libraries = MC Support
+add_to_library_groups = Sparc

Added: llvm/trunk/lib/Target/Sparc/InstPrinter/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/InstPrinter/Makefile?rev=198028&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Sparc/InstPrinter/Makefile (added)
+++ llvm/trunk/lib/Target/Sparc/InstPrinter/Makefile Wed Dec 25 17:43:39 2013
@@ -0,0 +1,16 @@
+##===- lib/Target/Sparc/InstPrinter/Makefile ---------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../../../..
+LIBRARYNAME = LLVMSparcAsmPrinter
+
+# Hack: we need to include 'main'  target directory to grab private headers
+CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
+
+include $(LEVEL)/Makefile.common

Added: llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp?rev=198028&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp (added)
+++ llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp Wed Dec 25 17:43:39 2013
@@ -0,0 +1,95 @@
+//===-- SparcInstPrinter.cpp - Convert Sparc MCInst to assembly syntax -----==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This class prints an Sparc MCInst to a .s file.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "asm-printer"
+#include "SparcInstPrinter.h"
+
+#include "Sparc.h"
+#include "MCTargetDesc/SparcBaseInfo.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/Support/raw_ostream.h"
+using namespace llvm;
+
+#define GET_INSTRUCTION_NAME
+// Uncomment the following line once we are ready to use MCAsmWriter.
+//#include "SparcGenAsmWriter.inc"
+
+void SparcInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const
+{
+  OS << '%' << StringRef(getRegisterName(RegNo)).lower();
+}
+
+void SparcInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
+                               StringRef Annot)
+{
+  printInstruction(MI, O);
+  printAnnotation(O, Annot);
+}
+
+void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
+                                    raw_ostream &O)
+{
+  const MCOperand &MO = MI->getOperand (opNum);
+
+  if (MO.isReg()) {
+    printRegName(O, MO.getReg());
+    return ;
+  }
+
+  if (MO.isImm()) {
+    O << (int)MO.getImm();
+    return;
+  }
+
+  assert(MO.isExpr() && "Unknown operand kind in printOperand");
+  MO.getExpr()->print(O);
+}
+
+void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum,
+                                      raw_ostream &O, const char *Modifier)
+{
+  printOperand(MI, opNum, O);
+
+  // If this is an ADD operand, emit it like normal operands.
+  if (Modifier && !strcmp(Modifier, "arith")) {
+    O << ", ";
+    printOperand(MI, opNum+1, O);
+    return;
+  }
+  const MCOperand &MO = MI->getOperand(opNum+1);
+
+  if (MO.isReg() && MO.getReg() == SP::G0)
+    return;   // don't print "+%g0"
+  if (MO.isImm() && MO.getImm() == 0)
+    return;   // don't print "+0"
+
+  O << "+";
+
+  printOperand(MI, opNum+1, O);
+}
+
+void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum,
+                                     raw_ostream &O)
+{
+  int CC = (int)MI->getOperand(opNum).getImm();
+  O << SPARCCondCodeToString((SPCC::CondCodes)CC);
+}
+
+bool SparcInstPrinter::printGetPCX(const MCInst *MI, unsigned opNum,
+                                  raw_ostream &O)
+{
+  assert(0 && "FIXME: Implement SparcInstPrinter::printGetPCX.");
+  return true;
+}

Added: llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.h?rev=198028&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.h (added)
+++ llvm/trunk/lib/Target/Sparc/InstPrinter/SparcInstPrinter.h Wed Dec 25 17:43:39 2013
@@ -0,0 +1,46 @@
+//===-- SparcInstPrinter.h - Convert Sparc MCInst to assembly syntax ------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This class prints an Sparc MCInst to a .s file.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SparcINSTPRINTER_H
+#define SparcINSTPRINTER_H
+
+#include "llvm/MC/MCInstPrinter.h"
+
+namespace llvm {
+
+class MCOperand;
+
+class SparcInstPrinter : public MCInstPrinter {
+public:
+ SparcInstPrinter(const MCAsmInfo &MAI,
+                  const MCInstrInfo &MII,
+                  const MCRegisterInfo &MRI)
+   : MCInstPrinter(MAI, MII, MRI) {}
+
+  virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
+  virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
+
+  // Autogenerated by tblgen.
+  void printInstruction(const MCInst *MI, raw_ostream &O);
+  static const char *getRegisterName(unsigned RegNo);
+
+  void printOperand(const MCInst *MI, int opNum, raw_ostream &OS);
+  void printMemOperand(const MCInst *MI, int opNum, raw_ostream &OS,
+                       const char *Modifier = 0);
+  void printCCOperand(const MCInst *MI, int opNum, raw_ostream &OS);
+  bool printGetPCX(const MCInst *MI, unsigned OpNo, raw_ostream &OS);
+
+};
+} // end namespace llvm
+
+#endif

Modified: llvm/trunk/lib/Target/Sparc/LLVMBuild.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/LLVMBuild.txt?rev=198028&r1=198027&r2=198028&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/LLVMBuild.txt (original)
+++ llvm/trunk/lib/Target/Sparc/LLVMBuild.txt Wed Dec 25 17:43:39 2013
@@ -16,7 +16,7 @@
 ;===------------------------------------------------------------------------===;
 
 [common]
-subdirectories = MCTargetDesc TargetInfo
+subdirectories = InstPrinter MCTargetDesc TargetInfo
 
 [component_0]
 type = TargetGroup
@@ -29,6 +29,6 @@ has_jit = 1
 type = Library
 name = SparcCodeGen
 parent = Sparc
-required_libraries = AsmPrinter CodeGen Core MC SelectionDAG SparcDesc
-                     SparcInfo Support Target
+required_libraries = AsmPrinter CodeGen Core MC SelectionDAG SparcAsmPrinter
+                     SparcDesc SparcInfo Support Target
 add_to_library_groups = Sparc

Modified: llvm/trunk/lib/Target/Sparc/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/Makefile?rev=198028&r1=198027&r2=198028&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/Makefile (original)
+++ llvm/trunk/lib/Target/Sparc/Makefile Wed Dec 25 17:43:39 2013
@@ -17,7 +17,7 @@ BUILT_SOURCES = SparcGenRegisterInfo.inc
 		SparcGenSubtargetInfo.inc SparcGenCallingConv.inc \
 		SparcGenCodeEmitter.inc
 
-DIRS = TargetInfo MCTargetDesc
+DIRS = InstPrinter TargetInfo MCTargetDesc
 
 include $(LEVEL)/Makefile.common
 





More information about the llvm-commits mailing list