1 //===-- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_ASMPRINTER_H
17 #define LLVM_CODEGEN_ASMPRINTER_H
19 #include "llvm/CodeGen/MachineFunctionPass.h"
25 class AsmPrinter : public MachineFunctionPass {
27 /// Output stream on which we're printing assembly code.
31 /// Target machine description.
35 /// Name-mangler for global names.
39 /// Cache of mangled name for current function. This is recalculated at the
40 /// beginning of each call to runOnMachineFunction().
42 std::string CurrentFnName;
44 //===------------------------------------------------------------------===//
45 // Properties to be set by the derived class ctor, used to configure the
48 /// CommentString - This indicates the comment character used by the
50 const char *CommentString; // Defaults to "#"
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 ""
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"
62 /// AsciiDirective - This directive allows emission of an ascii string with
63 /// the standard C escape characters embedded into it.
64 const char *AsciiDirective;
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"
74 /// AlignDirective - The directive used to emit round up to an alignment
77 const char *AlignDirective; // Defaults to "\t.align\t"
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
83 bool AlignmentIsInBytes; // Defaults to true
85 AsmPrinter(std::ostream &o, TargetMachine &tm)
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) {
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);
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);
108 /// setupMachineFunction - This should be called when a new MachineFunction
109 /// is being processed from runOnMachineFunction.
110 void setupMachineFunction(MachineFunction &MF);
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
115 void emitAlignment(unsigned NumBits) const;
117 /// emitZeros - Emit a block of zeros.
119 void emitZeros(unsigned NumZeros) const;
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);
125 /// emitGlobalConstant - Print a general LLVM constant to the .s file.
127 void emitGlobalConstant(const Constant* CV);