aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MC
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-14 03:48:55 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-14 03:48:55 +0000
commitc22e0b2443afdedb6d9b225b938ad404d63cdbe6 (patch)
tree63f7975e72d90fa0fb45f05c4593608fa0550f17 /lib/MC
parent575327b77e9092074e5d18bfebfb78ce550aa2a3 (diff)
downloadexternal_llvm-c22e0b2443afdedb6d9b225b938ad404d63cdbe6.zip
external_llvm-c22e0b2443afdedb6d9b225b938ad404d63cdbe6.tar.gz
external_llvm-c22e0b2443afdedb6d9b225b938ad404d63cdbe6.tar.bz2
Update llvm-mc / MCAsmStreamer to print the instruction using the actual target
specific printer (this only works on x86, for now). - This makes it possible to do some correctness checking of the parsing and matching, since we can compare the results of 'as' on the original input, to those of 'as' on the output from llvm-mc. - In theory, we could now have an easy ATT -> Intel syntax converter. :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78986 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r--lib/MC/MCAsmStreamer.cpp64
1 files changed, 21 insertions, 43 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp
index 75390c6..ac2aabd 100644
--- a/lib/MC/MCAsmStreamer.cpp
+++ b/lib/MC/MCAsmStreamer.cpp
@@ -9,6 +9,7 @@
#include "llvm/MC/MCStreamer.h"
+#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSectionMachO.h"
@@ -23,12 +24,14 @@ namespace {
class MCAsmStreamer : public MCStreamer {
raw_ostream &OS;
+
+ AsmPrinter *Printer;
MCSection *CurSection;
public:
- MCAsmStreamer(MCContext &Context, raw_ostream &_OS)
- : MCStreamer(Context), OS(_OS), CurSection(0) {}
+ MCAsmStreamer(MCContext &Context, raw_ostream &_OS, AsmPrinter *_AsmPrinter)
+ : MCStreamer(Context), OS(_OS), Printer(_AsmPrinter), CurSection(0) {}
~MCAsmStreamer() {}
/// @name MCStreamer Interface
@@ -75,50 +78,16 @@ namespace {
}
-/// NeedsQuoting - Return true if the string \arg Str needs quoting, i.e., it
-/// does not match [a-zA-Z_.][a-zA-Z0-9_.]*.
-//
-// FIXME: This could be more permissive, do we care?
-static inline bool NeedsQuoting(const StringRef &Str) {
- if (Str.empty())
- return true;
-
- // Check that first character is in [a-zA-Z_.].
- if (!((Str[0] >= 'a' && Str[0] <= 'z') ||
- (Str[0] >= 'A' && Str[0] <= 'Z') ||
- (Str[0] == '_' || Str[0] == '.')))
- return true;
-
- // Check subsequent characters are in [a-zA-Z0-9_.].
- for (unsigned i = 1, e = Str.size(); i != e; ++i)
- if (!((Str[i] >= 'a' && Str[i] <= 'z') ||
- (Str[i] >= 'A' && Str[i] <= 'Z') ||
- (Str[i] >= '0' && Str[i] <= '9') ||
- (Str[i] == '_' || Str[i] == '.')))
- return true;
-
- return false;
-}
-
/// Allow printing symbols directly to a raw_ostream with proper quoting.
static inline raw_ostream &operator<<(raw_ostream &os, const MCSymbol *S) {
- if (NeedsQuoting(S->getName()))
- return os << '"' << S->getName() << '"';
- return os << S->getName();
+ S->print(os);
+
+ return os;
}
/// Allow printing values directly to a raw_ostream.
static inline raw_ostream &operator<<(raw_ostream &os, const MCValue &Value) {
- if (Value.getSymA()) {
- os << Value.getSymA();
- if (Value.getSymB())
- os << " - " << Value.getSymB();
- if (Value.getConstant())
- os << " + " << Value.getConstant();
- } else {
- assert(!Value.getSymB() && "Invalid machine code value!");
- os << Value.getConstant();
- }
+ Value.print(os);
return os;
}
@@ -300,7 +269,15 @@ static raw_ostream &operator<<(raw_ostream &OS, const MCOperand &Op) {
void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
assert(CurSection && "Cannot emit contents before setting section!");
- // FIXME: Implement proper printing.
+
+ // If we have an AsmPrinter, use that to print.
+ if (Printer) {
+ Printer->printMCInst(&Inst);
+ return;
+ }
+
+ // Otherwise fall back to a structural printing for now. Eventually we should
+ // always have access to the target specific printer.
OS << "MCInst("
<< "opcode=" << Inst.getOpcode() << ", "
<< "operands=[";
@@ -316,6 +293,7 @@ void MCAsmStreamer::Finish() {
OS.flush();
}
-MCStreamer *llvm::createAsmStreamer(MCContext &Context, raw_ostream &OS) {
- return new MCAsmStreamer(Context, OS);
+MCStreamer *llvm::createAsmStreamer(MCContext &Context, raw_ostream &OS,
+ AsmPrinter *AP) {
+ return new MCAsmStreamer(Context, OS, AP);
}