2009-09-14 09:43:38 +08:00
|
|
|
//===-- MCInstPrinter.cpp - Convert an MCInst to target assembly syntax ---===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
2010-02-12 06:39:10 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2012-02-07 13:05:23 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-06 02:13:19 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2011-09-16 02:36:29 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-09-14 09:43:38 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
MCInstPrinter::~MCInstPrinter() {
|
2009-10-06 02:43:19 +08:00
|
|
|
}
|
2010-02-12 06:39:10 +08:00
|
|
|
|
|
|
|
/// getOpcodeName - Return the name of the specified opcode enum (e.g.
|
|
|
|
/// "MOV32ri") or empty if we can't resolve it.
|
|
|
|
StringRef MCInstPrinter::getOpcodeName(unsigned Opcode) const {
|
2012-04-02 16:32:38 +08:00
|
|
|
return MII.getName(Opcode);
|
2010-02-12 06:39:10 +08:00
|
|
|
}
|
2011-03-06 02:43:32 +08:00
|
|
|
|
2011-06-02 10:34:55 +08:00
|
|
|
void MCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
|
2012-02-07 13:05:23 +08:00
|
|
|
llvm_unreachable("Target should implement this");
|
2011-03-06 02:43:32 +08:00
|
|
|
}
|
2011-09-16 02:36:29 +08:00
|
|
|
|
2011-09-16 07:38:46 +08:00
|
|
|
void MCInstPrinter::printAnnotation(raw_ostream &OS, StringRef Annot) {
|
2011-09-21 08:25:23 +08:00
|
|
|
if (!Annot.empty()) {
|
|
|
|
if (CommentStream)
|
2011-10-05 06:44:48 +08:00
|
|
|
(*CommentStream) << Annot;
|
2011-09-21 08:25:23 +08:00
|
|
|
else
|
2011-10-05 06:44:48 +08:00
|
|
|
OS << " " << MAI.getCommentString() << " " << Annot;
|
2011-09-21 08:25:23 +08:00
|
|
|
}
|
2011-09-16 02:36:29 +08:00
|
|
|
}
|
2012-10-24 06:52:52 +08:00
|
|
|
|
|
|
|
/// Utility functions to make adding mark ups simpler.
|
|
|
|
StringRef MCInstPrinter::markup(StringRef s) const {
|
|
|
|
if (getUseMarkup())
|
|
|
|
return s;
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
StringRef MCInstPrinter::markup(StringRef a, StringRef b) const {
|
|
|
|
if (getUseMarkup())
|
|
|
|
return a;
|
|
|
|
else
|
|
|
|
return b;
|
|
|
|
}
|
2012-12-06 02:13:19 +08:00
|
|
|
|
|
|
|
/// Utility function to print immediates in decimal or hex.
|
|
|
|
format_object1<int64_t> MCInstPrinter::formatImm(const int64_t Value) const {
|
|
|
|
if (getPrintImmHex())
|
2012-12-06 02:31:11 +08:00
|
|
|
return format("0x%" PRIx64, Value);
|
2012-12-06 02:13:19 +08:00
|
|
|
else
|
2012-12-06 02:31:11 +08:00
|
|
|
return format("%" PRId64, Value);
|
2012-12-06 02:13:19 +08:00
|
|
|
}
|