LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

AsmPrinter.h

Go to the documentation of this file.
00001 //===-- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework --------*- C++ -*-===//
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 class is intended to be used as a base class for target-specific
00011 // asmwriters.  This class primarily takes care of printing global constants,
00012 // which are printed in a very similar way across all targets.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CODEGEN_ASMPRINTER_H
00017 #define LLVM_CODEGEN_ASMPRINTER_H
00018 
00019 #include "llvm/CodeGen/MachineFunctionPass.h"
00020 
00021 namespace llvm {
00022   class Constant;
00023   class Mangler;
00024 
00025   class AsmPrinter : public MachineFunctionPass {
00026   protected:
00027     /// Output stream on which we're printing assembly code.
00028     ///
00029     std::ostream &O;
00030 
00031     /// Target machine description.
00032     ///
00033     TargetMachine &TM;
00034 
00035     /// Name-mangler for global names.
00036     ///
00037     Mangler *Mang;
00038 
00039     /// Cache of mangled name for current function. This is recalculated at the
00040     /// beginning of each call to runOnMachineFunction().
00041     ///
00042     std::string CurrentFnName;
00043 
00044     //===------------------------------------------------------------------===//
00045     // Properties to be set by the derived class ctor, used to configure the
00046     // asmwriter.
00047 
00048     /// CommentString - This indicates the comment character used by the
00049     /// assembler.
00050     const char *CommentString;     // Defaults to "#"
00051 
00052     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
00053     /// onto all global symbols.  This is often used for "_" or ".".
00054     const char *GlobalPrefix;    // Defaults to ""
00055 
00056     /// ZeroDirective - this should be set to the directive used to get some
00057     /// number of zero bytes emitted to the current section.  Common cases are
00058     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
00059     /// Data*bitsDirective's will be used to emit zero bytes.
00060     const char *ZeroDirective;   // Defaults to "\t.zero\t"
00061 
00062     /// AsciiDirective - This directive allows emission of an ascii string with
00063     /// the standard C escape characters embedded into it.
00064     const char *AsciiDirective;
00065     
00066     /// DataDirectives - These directives are used to output some unit of
00067     /// integer data to the current section.  If a data directive is set to
00068     /// null, smaller data directives will be used to emit the large sizes.
00069     const char *Data8bitsDirective;   // Defaults to "\t.byte\t"
00070     const char *Data16bitsDirective;  // Defaults to "\t.short\t"
00071     const char *Data32bitsDirective;  // Defaults to "\t.long\t"
00072     const char *Data64bitsDirective;  // Defaults to "\t.quad\t"
00073 
00074     /// AlignDirective - The directive used to emit round up to an alignment
00075     /// boundary.
00076     ///
00077     const char *AlignDirective;       // Defaults to "\t.align\t"
00078 
00079     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
00080     /// emits ".align N" directives, where N is the number of bytes to align to.
00081     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
00082     /// boundary.
00083     bool AlignmentIsInBytes;          // Defaults to true
00084 
00085     AsmPrinter(std::ostream &o, TargetMachine &tm)
00086       : O(o), TM(tm),
00087         CommentString("#"),
00088         GlobalPrefix(""),
00089         ZeroDirective("\t.zero\t"),
00090         AsciiDirective("\t.ascii\t"),
00091         Data8bitsDirective("\t.byte\t"),
00092         Data16bitsDirective("\t.short\t"),
00093         Data32bitsDirective("\t.long\t"),
00094         Data64bitsDirective("\t.quad\t"),
00095         AlignDirective("\t.align\t"),
00096         AlignmentIsInBytes(true) {
00097     }
00098 
00099     /// doInitialization - Set up the AsmPrinter when we are working on a new
00100     /// module.  If your pass overrides this, it must make sure to explicitly
00101     /// call this implementation.
00102     bool doInitialization(Module &M);
00103 
00104     /// doFinalization - Shut down the asmprinter.  If you override this in your
00105     /// pass, you must make sure to call it explicitly.
00106     bool doFinalization(Module &M);
00107 
00108     /// setupMachineFunction - This should be called when a new MachineFunction
00109     /// is being processed from runOnMachineFunction.
00110     void setupMachineFunction(MachineFunction &MF);
00111 
00112     /// emitAlignment - Emit an alignment directive to the specified power of
00113     /// two boundary.  For example, if you pass in 3 here, you will get an 8
00114     /// byte alignment.
00115     void emitAlignment(unsigned NumBits) const;
00116 
00117     /// emitZeros - Emit a block of zeros.
00118     ///
00119     void emitZeros(unsigned NumZeros) const;
00120 
00121     /// emitConstantValueOnly - Print out the specified constant, without a
00122     /// storage class.  Only constants of first-class type are allowed here.
00123     void emitConstantValueOnly(const Constant *CV);
00124 
00125     /// emitGlobalConstant - Print a general LLVM constant to the .s file.
00126     ///
00127     void emitGlobalConstant(const Constant* CV);
00128   };
00129 }
00130 
00131 #endif