LLVM API Documentation

X86AsmPrinter.h

Go to the documentation of this file.
00001 //===-- X86AsmPrinter.h - Convert X86 LLVM code to Intel assembly ---------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file the shared super class printer that converts from our internal
00011 // representation of machine-dependent LLVM code to Intel and AT&T format
00012 // assembly language.  This printer is the output mechanism used by `llc'.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef X86ASMPRINTER_H
00017 #define X86ASMPRINTER_H
00018 
00019 #include "X86.h"
00020 #include "X86TargetMachine.h"
00021 #include "llvm/CodeGen/AsmPrinter.h"
00022 #include "llvm/CodeGen/DwarfWriter.h"
00023 #include "llvm/CodeGen/MachineDebugInfo.h"
00024 #include "llvm/ADT/Statistic.h"
00025 #include <set>
00026 
00027 
00028 namespace llvm {
00029 
00030 extern Statistic<> EmittedInsts;
00031 
00032 /// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
00033 ///
00034 struct X86DwarfWriter : public DwarfWriter {
00035  // Ctor.
00036 X86DwarfWriter(std::ostream &o, AsmPrinter *ap)
00037   : DwarfWriter(o, ap)
00038     {
00039       needsSet = true;
00040       DwarfAbbrevSection = ".section __DWARFA,__debug_abbrev";
00041       DwarfInfoSection = ".section __DWARFA,__debug_info";
00042       DwarfLineSection = ".section __DWARFA,__debug_line";
00043       DwarfFrameSection = ".section __DWARFA,__debug_frame";
00044       DwarfPubNamesSection = ".section __DWARFA,__debug_pubnames";
00045       DwarfPubTypesSection = ".section __DWARFA,__debug_pubtypes";
00046       DwarfStrSection = ".section __DWARFA,__debug_str";
00047       DwarfLocSection = ".section __DWARFA,__debug_loc";
00048       DwarfARangesSection = ".section __DWARFA,__debug_aranges";
00049       DwarfRangesSection = ".section __DWARFA,__debug_ranges";
00050       DwarfMacInfoSection = ".section __DWARFA,__debug_macinfo";
00051       TextSection = ".text";
00052        DataSection = ".data";
00053     }
00054 };
00055 
00056 struct X86SharedAsmPrinter : public AsmPrinter {
00057   X86DwarfWriter DW;
00058 
00059   X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
00060     : AsmPrinter(O, TM), DW(O, this), forDarwin(false) { }
00061 
00062   bool doInitialization(Module &M);
00063   bool doFinalization(Module &M);
00064 
00065   void getAnalysisUsage(AnalysisUsage &AU) const {
00066     AU.setPreservesAll();
00067     AU.addRequired<MachineDebugInfo>();
00068     MachineFunctionPass::getAnalysisUsage(AU);
00069   }
00070 
00071   bool forDarwin;  // FIXME: eliminate.
00072 
00073   // Necessary for Darwin to print out the apprioriate types of linker stubs
00074   std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
00075 
00076   inline static bool isScale(const MachineOperand &MO) {
00077     return MO.isImmediate() &&
00078           (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||
00079           MO.getImmedValue() == 4 || MO.getImmedValue() == 8);
00080   }
00081 
00082   inline static bool isMem(const MachineInstr *MI, unsigned Op) {
00083     if (MI->getOperand(Op).isFrameIndex()) return true;
00084     return Op+4 <= MI->getNumOperands() &&
00085       MI->getOperand(Op  ).isRegister() && isScale(MI->getOperand(Op+1)) &&
00086       MI->getOperand(Op+2).isRegister() &&
00087       (MI->getOperand(Op+3).isImmediate() ||
00088        MI->getOperand(Op+3).isGlobalAddress() ||
00089        MI->getOperand(Op+3).isConstantPoolIndex());
00090   }
00091 };
00092 
00093 } // end namespace llvm
00094 
00095 #endif