MCAssembler.h revision 1f2b32c5c6502c74890c188b0224e4c01ff22da4
1//===- MCAssembler.h - Object File Generation -------------------*- 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_MCASSEMBLER_H
11#define LLVM_MC_MCASSEMBLER_H
12
13#include "llvm/ADT/ilist.h"
14#include "llvm/ADT/ilist_node.h"
15#include "llvm/Support/DataTypes.h"
16
17namespace llvm {
18class raw_ostream;
19class MCAssembler;
20class MCSection;
21class MCSectionData;
22
23class MCFragment : public ilist_node<MCFragment> {
24  MCFragment(const MCFragment&);     // DO NOT IMPLEMENT
25  void operator=(const MCFragment&); // DO NOT IMPLEMENT
26
27public:
28  MCFragment(MCSectionData *SD = 0);
29};
30
31// FIXME: Should this be a separate class, or just merged into MCSection? Since
32// we anticipate the fast path being through an MCAssembler, the only reason to
33// keep it out is for API abstraction.
34class MCSectionData : public ilist_node<MCSectionData> {
35  MCSectionData(const MCSectionData&);  // DO NOT IMPLEMENT
36  void operator=(const MCSectionData&); // DO NOT IMPLEMENT
37
38public:
39  typedef iplist<MCFragment> FragmentListType;
40
41private:
42  iplist<MCFragment> Fragments;
43  const MCSection &Section;
44
45  /// Alignment - The maximum alignment seen in this section.
46  unsigned Alignment;
47
48  /// @name Assembler Backend Data
49  /// @{
50  //
51  // FIXME: This could all be kept private to the assembler implementation.
52
53  /// FileOffset - The offset of this section in the object file.
54  uint64_t FileOffset;
55
56  /// FileSize - The size of this section in the object file.
57  uint64_t FileSize;
58
59  /// @}
60
61public:
62  // Only for use as sentinel.
63  MCSectionData();
64  MCSectionData(const MCSection &Section, MCAssembler *A = 0);
65
66  const FragmentListType &getFragmentList() const { return Fragments; }
67  FragmentListType &getFragmentList() { return Fragments; }
68
69  const MCSection &getSection() const { return Section; }
70
71  unsigned getAlignment() const { return Alignment; }
72  void setAlignment(unsigned Value) { Alignment = Value; }
73
74  /// @name Assembler Backend Support
75  /// @{
76  //
77  // FIXME: This could all be kept private to the assembler implementation.
78
79  unsigned getFileSize() const { return FileSize; }
80
81  uint64_t getFileOffset() const { return FileOffset; }
82  void setFileOffset(uint64_t Value) { FileOffset = Value; }
83
84  void WriteFileData(raw_ostream &OS) const;
85
86  /// @}
87};
88
89class MCAssembler {
90public:
91  typedef iplist<MCSectionData> SectionDataListType;
92
93  typedef SectionDataListType::const_iterator const_iterator;
94  typedef SectionDataListType::iterator iterator;
95
96private:
97  MCAssembler(const MCAssembler&);    // DO NOT IMPLEMENT
98  void operator=(const MCAssembler&); // DO NOT IMPLEMENT
99
100  raw_ostream &OS;
101
102  iplist<MCSectionData> Sections;
103
104public:
105  /// Construct a new assembler instance.
106  ///
107  /// \arg OS - The stream to output to.
108  //
109  // FIXME: How are we going to parameterize this? Two obvious options are stay
110  // concrete and require clients to pass in a target like object. The other
111  // option is to make this abstract, and have targets provide concrete
112  // implementations as we do with AsmParser.
113  MCAssembler(raw_ostream &OS);
114  ~MCAssembler();
115
116  /// Finish - Do final processing and write the object to the output stream.
117  void Finish();
118
119  /// @name Section List Access
120  /// @{
121
122  const SectionDataListType &getSectionList() const { return Sections; }
123  SectionDataListType &getSectionList() { return Sections; }
124
125  iterator begin() { return Sections.begin(); }
126  const_iterator begin() const { return Sections.begin(); }
127
128  iterator end() { return Sections.end(); }
129  const_iterator end() const { return Sections.end(); }
130
131  size_t size() const { return Sections.size(); }
132
133  /// @}
134};
135
136} // end namespace llvm
137
138#endif
139