blob: b27cdf067d4eaedbc956616f84356a3b8d3a8daf [file] [log] [blame]
Chris Lattnerb36cbd02005-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 Begeman72b286b2005-07-08 00:23:26 +000022#include <set>
23
Chris Lattnerb36cbd02005-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)
Chris Lattnerac2902b2005-11-21 23:06:54 +000032 : AsmPrinter(O, TM), forDarwin(false) { }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000033
34 bool doInitialization(Module &M);
Chris Lattnerb36cbd02005-07-01 22:44:09 +000035 bool doFinalization(Module &M);
36
Chris Lattnera35a8e82005-11-21 22:39:40 +000037 bool forDarwin; // FIXME: eliminate.
Chris Lattnerb36cbd02005-07-01 22:44:09 +000038
Nate Begeman72b286b2005-07-08 00:23:26 +000039 // Necessary for Darwin to print out the apprioriate types of linker stubs
40 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
41
Chris Lattnerb36cbd02005-07-01 22:44:09 +000042 inline static bool isScale(const MachineOperand &MO) {
43 return MO.isImmediate() &&
44 (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
45 MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
46 }
47
48 inline static bool isMem(const MachineInstr *MI, unsigned Op) {
49 if (MI->getOperand(Op).isFrameIndex()) return true;
Chris Lattnerb36cbd02005-07-01 22:44:09 +000050 return Op+4 <= MI->getNumOperands() &&
51 MI->getOperand(Op ).isRegister() && isScale(MI->getOperand(Op+1)) &&
Evan Chengc4ee50c2006-02-25 09:56:50 +000052 MI->getOperand(Op+2).isRegister() &&
53 (MI->getOperand(Op+3).isImmediate() ||
54 MI->getOperand(Op+3).isGlobalAddress() ||
55 MI->getOperand(Op+3).isConstantPoolIndex());
Chris Lattnerb36cbd02005-07-01 22:44:09 +000056 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000057};
58
59} // end namespace x86
60} // end namespace llvm
61
62#endif