Refactor X86AsmPrinter.cpp into multiple files. Patch contributed
[oota-llvm.git] / lib / Target / X86 / X86AsmPrinter.h
1 //===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file the shared super class printer that converts from our internal
11 // representation of machine-dependent LLVM code to Intel and AT&T format
12 // assembly language.  This printer is the output mechanism used by `llc'.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef X86ASMPRINTER_H
17 #define X86ASMPRINTER_H
18
19 #include "X86.h"
20 #include "llvm/CodeGen/AsmPrinter.h"
21 #include "llvm/ADT/Statistic.h"
22
23 namespace llvm {
24 namespace x86 {
25
26 extern Statistic<> EmittedInsts;
27
28 struct X86SharedAsmPrinter : public AsmPrinter {
29   X86SharedAsmPrinter(std::ostream &O, TargetMachine &TM)
30     : AsmPrinter(O, TM), forCygwin(false), forDarwin(false) { }
31
32   bool doInitialization(Module &M);
33   void printConstantPool(MachineConstantPool *MCP);
34   bool doFinalization(Module &M);
35
36   bool forCygwin;
37   bool forDarwin;
38
39   inline static bool isScale(const MachineOperand &MO) {
40     return MO.isImmediate() &&
41           (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
42           MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
43   }
44
45   inline static bool isMem(const MachineInstr *MI, unsigned Op) {
46     if (MI->getOperand(Op).isFrameIndex()) return true;
47     if (MI->getOperand(Op).isConstantPoolIndex()) return true;
48     return Op+4 <= MI->getNumOperands() &&
49       MI->getOperand(Op  ).isRegister() && isScale(MI->getOperand(Op+1)) &&
50       MI->getOperand(Op+2).isRegister() && (MI->getOperand(Op+3).isImmediate()||
51       MI->getOperand(Op+3).isGlobalAddress());
52   }
53
54   // SwitchSection - Switch to the specified section of the executable if we are
55   // not already in it!
56   inline static void SwitchSection(std::ostream &OS, std::string &CurSection,
57                                    const char *NewSection) {
58     if (CurSection != NewSection) {
59       CurSection = NewSection;
60       if (!CurSection.empty())
61         OS << "\t" << NewSection << "\n";
62     }
63   }
64 };
65
66 } // end namespace x86
67 } // end namespace llvm
68
69 #endif