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