Add comments for the MCStreamer interface.
[oota-llvm.git] / include / llvm / MC / MCStreamer.h
1 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_MCSTREAMER_H
11 #define LLVM_MC_MCSTREAMER_H
12
13 namespace llvm {
14   class MCAtom;
15   class MCContext;
16   class MCImm;
17   class MCInst;
18   class MCSection;
19   class MCSymbol;
20   class raw_ostream;
21
22   /// MCStreamer - Streaming machine code generation interface.
23   class MCStreamer {
24   public:
25     enum SymbolAttr {
26       Global,
27       Weak,
28       PrivateExtern
29     };
30
31   private:
32     MCContext &Context;
33
34     MCStreamer(const MCStreamer&); // DO NOT IMPLEMENT
35     MCStreamer &operator=(const MCStreamer&); // DO NOT IMPLEMENT
36
37   protected:
38     MCStreamer(MCContext &Ctx);
39
40   public:
41     virtual ~MCStreamer();
42
43     MCContext &getContext() const { return Context; }
44
45     /// SwitchSection - Set the current section where code is being emitted to
46     /// @param Section.
47     ///
48     /// This corresponds to assembler directives like .section, .text, etc.
49     virtual void SwitchSection(MCSection *Section) = 0;
50
51     /// EmitLabel - Emit a label for @param Symbol into the current section.
52     ///
53     /// This corresponds to an assembler statement such as:
54     ///   foo:
55     ///
56     /// @param Symbol - The symbol to emit. A given symbol should only be
57     /// emitted as a label once, and symbols emitted as a label should never be
58     /// used in an assignment.
59     //
60     // FIXME: What to do about the current section? Should we get rid of the
61     // symbol section in the constructor and initialize it here?
62     virtual void EmitLabel(MCSymbol *Symbol);
63
64     /// EmitAssignment - Emit an assignment of @param Value to @param Symbol.
65     ///
66     /// This corresponds to an assembler statement such as:
67     ///  symbol = value
68     ///
69     /// The assignment generates no code, but has the side effect of binding the
70     /// value in the current context. For the assembly streamer, this prints the
71     /// binding into the .s file.
72     ///
73     /// @param Symbol - The symbol being assigned to.
74     /// @param Value - The value for the symbol.
75     /// @param MakeAbsolute - If true, then the symbol should be given the
76     /// absolute value of @param Value, even if @param Value would be
77     /// relocatable expression. This corresponds to the ".set" directive.
78     virtual void EmitAssignment(MCSymbol *Symbol, const MCImm &Value,
79                                 bool MakeAbsolute = false) = 0;
80
81     /// EmitSymbolAttribute - Add the given @param Attribute to @param Symbol.
82     //
83     // FIXME: This doesn't make much sense, could we just have attributes be on
84     // the symbol and make the printer smart enough to add the right symbols?
85     // This should work as long as the order of attributes in the file doesn't
86     // matter.
87     virtual void EmitSymbolAttribute(MCSymbol *Symbol, 
88                                      SymbolAttr Attribute) = 0;
89
90     /// EmitBytes - Emit @param Length bytes starting at @param Data into the
91     /// output.
92     ///
93     /// This is used to implement assembler directives such as .byte, .ascii,
94     /// etc.
95     virtual void EmitBytes(const char *Data, unsigned Length) = 0;
96
97     /// EmitValue - Emit the expression @param Value into the output as a native
98     /// integer of the given @param Size bytes.
99     ///
100     /// This is used to implement assembler directives such as .word, .quad,
101     /// etc.
102     ///
103     /// @param Value - The value to emit.
104     /// @param Size - The size of the integer (in bytes) to emit. This must
105     /// match a native machine width.
106     virtual void EmitValue(const MCImm &Value, unsigned Size) = 0;
107
108     /// EmitInstruction - Emit the given @param Instruction into the current
109     /// section.
110     virtual void EmitInstruction(const MCInst &Inst) = 0;
111   };
112
113   /// createAsmStreamer - Create a machine code streamer which will print out
114   /// assembly for the native target, suitable for compiling with a native
115   /// assembler.
116   MCStreamer *createAsmStreamer(MCContext &Ctx, raw_ostream &OS);
117
118   // FIXME: These two may end up getting rolled into a single
119   // createObjectStreamer interface, which implements the assembler backend, and
120   // is parameterized on an output object file writer.
121
122   /// createMachOStream - Create a machine code streamer which will generative
123   /// Mach-O format object files.
124   MCStreamer *createMachOStreamer(MCContext &Ctx, raw_ostream &OS);
125
126   /// createELFStreamer - Create a machine code streamer which will generative
127   /// ELF format object files.
128   MCStreamer *createELFStreamer(MCContext &Ctx, raw_ostream &OS);
129
130 } // end namespace llvm
131
132 #endif