blob: 4f53de8fb581696eef6be4369746b94de1adb2e1 [file] [log] [blame]
Chris Lattnerb9740462005-07-01 22:44:09 +00001//===-- 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"
Nate Begemanb62a4c82005-07-08 00:23:26 +000022#include <set>
23
Chris Lattnerb9740462005-07-01 22:44:09 +000024
25namespace llvm {
26namespace x86 {
27
28extern Statistic<> EmittedInsts;
29
30struct X86SharedAsmPrinter : public AsmPrinter {
31 X86SharedAsmPrinter(std::ostream &O, TargetMachine &TM)
32 : AsmPrinter(O, TM), forCygwin(false), forDarwin(false) { }
33
34 bool doInitialization(Module &M);
35 void printConstantPool(MachineConstantPool *MCP);
36 bool doFinalization(Module &M);
37
38 bool forCygwin;
39 bool forDarwin;
40
Nate Begemanb62a4c82005-07-08 00:23:26 +000041 // Necessary for Darwin to print out the apprioriate types of linker stubs
42 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
43
Chris Lattnerb9740462005-07-01 22:44:09 +000044 inline static bool isScale(const MachineOperand &MO) {
45 return MO.isImmediate() &&
46 (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
47 MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
48 }
49
50 inline static bool isMem(const MachineInstr *MI, unsigned Op) {
51 if (MI->getOperand(Op).isFrameIndex()) return true;
52 if (MI->getOperand(Op).isConstantPoolIndex()) return true;
53 return Op+4 <= MI->getNumOperands() &&
54 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
55 MI->getOperand(Op+2).isRegister() && (MI->getOperand(Op+3).isImmediate()||
56 MI->getOperand(Op+3).isGlobalAddress());
57 }
58
59 // SwitchSection - Switch to the specified section of the executable if we are
60 // not already in it!
61 inline static void SwitchSection(std::ostream &OS, std::string &CurSection,
62 const char *NewSection) {
63 if (CurSection != NewSection) {
64 CurSection = NewSection;
65 if (!CurSection.empty())
66 OS << "\t" << NewSection << "\n";
67 }
68 }
69};
70
71} // end namespace x86
72} // end namespace llvm
73
74#endif