Initial implementation of the nodes in a SelectionDAG.
[oota-llvm.git] / include / llvm / CodeGen / AsmPrinter.h
1 //===-- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework --------*- C++ -*-===//
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 class is intended to be used as a base class for target-specific
11 // asmwriters.  This class primarily takes care of printing global constants,
12 // which are printed in a very similar way across all targets.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_ASMPRINTER_H
17 #define LLVM_CODEGEN_ASMPRINTER_H
18
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20
21 namespace llvm {
22   class Constant;
23   class Mangler;
24
25   class AsmPrinter : public MachineFunctionPass {
26   protected:
27     /// Output stream on which we're printing assembly code.
28     ///
29     std::ostream &O;
30
31     /// Target machine description.
32     ///
33     TargetMachine &TM;
34
35     /// Name-mangler for global names.
36     ///
37     Mangler *Mang;
38
39     /// Cache of mangled name for current function. This is recalculated at the
40     /// beginning of each call to runOnMachineFunction().
41     ///
42     std::string CurrentFnName;
43
44     //===------------------------------------------------------------------===//
45     // Properties to be set by the derived class ctor, used to configure the
46     // asmwriter.
47
48     /// CommentString - This indicates the comment character used by the
49     /// assembler.
50     const char *CommentString;     // Defaults to "#"
51
52     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
53     /// onto all global symbols.  This is often used for "_" or ".".
54     const char *GlobalPrefix;    // Defaults to ""
55
56     /// ZeroDirective - this should be set to the directive used to get some
57     /// number of zero bytes emitted to the current section.  Common cases are
58     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
59     /// Data*bitsDirective's will be used to emit zero bytes.
60     const char *ZeroDirective;   // Defaults to "\t.zero\t"
61
62     /// AsciiDirective - This directive allows emission of an ascii string with
63     /// the standard C escape characters embedded into it.
64     const char *AsciiDirective;
65     
66     /// DataDirectives - These directives are used to output some unit of
67     /// integer data to the current section.  If a data directive is set to
68     /// null, smaller data directives will be used to emit the large sizes.
69     const char *Data8bitsDirective;   // Defaults to "\t.byte\t"
70     const char *Data16bitsDirective;  // Defaults to "\t.short\t"
71     const char *Data32bitsDirective;  // Defaults to "\t.long\t"
72     const char *Data64bitsDirective;  // Defaults to "\t.quad\t"
73
74     /// AlignDirective - The directive used to emit round up to an alignment
75     /// boundary.
76     ///
77     const char *AlignDirective;       // Defaults to "\t.align\t"
78
79     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
80     /// emits ".align N" directives, where N is the number of bytes to align to.
81     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
82     /// boundary.
83     bool AlignmentIsInBytes;          // Defaults to true
84
85     AsmPrinter(std::ostream &o, TargetMachine &tm)
86       : O(o), TM(tm),
87         CommentString("#"),
88         GlobalPrefix(""),
89         ZeroDirective("\t.zero\t"),
90         AsciiDirective("\t.ascii\t"),
91         Data8bitsDirective("\t.byte\t"),
92         Data16bitsDirective("\t.short\t"),
93         Data32bitsDirective("\t.long\t"),
94         Data64bitsDirective("\t.quad\t"),
95         AlignDirective("\t.align\t"),
96         AlignmentIsInBytes(true) {
97     }
98
99     /// doInitialization - Set up the AsmPrinter when we are working on a new
100     /// module.  If your pass overrides this, it must make sure to explicitly
101     /// call this implementation.
102     bool doInitialization(Module &M);
103
104     /// doFinalization - Shut down the asmprinter.  If you override this in your
105     /// pass, you must make sure to call it explicitly.
106     bool doFinalization(Module &M);
107
108     /// setupMachineFunction - This should be called when a new MachineFunction
109     /// is being processed from runOnMachineFunction.
110     void setupMachineFunction(MachineFunction &MF);
111
112     /// emitAlignment - Emit an alignment directive to the specified power of
113     /// two boundary.  For example, if you pass in 3 here, you will get an 8
114     /// byte alignment.
115     void emitAlignment(unsigned NumBits) const;
116
117     /// emitZeros - Emit a block of zeros.
118     ///
119     void emitZeros(unsigned NumZeros) const;
120
121     /// emitConstantValueOnly - Print out the specified constant, without a
122     /// storage class.  Only constants of first-class type are allowed here.
123     void emitConstantValueOnly(const Constant *CV);
124
125     /// emitGlobalConstant - Print a general LLVM constant to the .s file.
126     ///
127     void emitGlobalConstant(const Constant* CV);
128   };
129 }
130
131 #endif