From fb4a6b397665df011348ade24a8e38d2219f095a Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Fri, 21 Aug 2009 09:11:24 +0000 Subject: llvm-mc: Start MCAssembler and MCMachOStreamer. - Together these form the (Mach-O) back end of the assembler. - MCAssembler is the actual assembler backend, which is designed to have a reasonable API. This will eventually grow to support multiple object file implementations, but for now its Mach-O/i386 only. - MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API, e.g. converting the various directives into fragments, managing state like the current section, and so on. - llvm-mc will use the new backend via '-filetype=obj', which may eventually be, but is not yet, since I hear that people like assemblers which actually assemble. - The only thing that works at the moment is changing sections. For the time being I have a Python Mach-O dumping tool in test/scripts so this stuff can be easily tested, eventually I expect to replace this with a real LLVM tool. - More doxyments to come. I assume that since this stuff doesn't touch any of the things which are part of 2.6 that it is ok to put this in not so long before the freeze, but if someone objects let me know, I can pull it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79612 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCAssembler.h | 137 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 include/llvm/MC/MCAssembler.h (limited to 'include') diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h new file mode 100644 index 0000000000..a714e4503d --- /dev/null +++ b/include/llvm/MC/MCAssembler.h @@ -0,0 +1,137 @@ +//===- MCAssembler.h - Object File Generation -------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_MC_MCASSEMBLER_H +#define LLVM_MC_MCASSEMBLER_H + +#include "llvm/ADT/ilist.h" +#include "llvm/ADT/ilist_node.h" + +namespace llvm { +class raw_ostream; +class MCAssembler; +class MCSection; +class MCSectionData; + +class MCFragment : public ilist_node { + MCFragment(const MCFragment&); // DO NOT IMPLEMENT + void operator=(const MCFragment&); // DO NOT IMPLEMENT + +public: + MCFragment(MCSectionData *SD = 0); +}; + +// FIXME: Should this be a separate class, or just merged into MCSection? Since +// we anticipate the fast path being through an MCAssembler, the only reason to +// keep it out is for API abstraction. +class MCSectionData : public ilist_node { + MCSectionData(const MCSectionData&); // DO NOT IMPLEMENT + void operator=(const MCSectionData&); // DO NOT IMPLEMENT + +public: + typedef iplist FragmentListType; + +private: + iplist Fragments; + const MCSection &Section; + + /// Alignment - The maximum alignment seen in this section. + unsigned Alignment; + + /// @name Assembler Backend Data + /// @{ + // + // FIXME: This could all be kept private to the assembler implementation. + + /// FileOffset - The offset of this section in the object file. + uint64_t FileOffset; + + /// FileSize - The size of this section in the object file. + uint64_t FileSize; + + /// @} + +public: + // Only for use as sentinel. + MCSectionData(); + MCSectionData(const MCSection &Section, MCAssembler *A = 0); + + const FragmentListType &getFragmentList() const { return Fragments; } + FragmentListType &getFragmentList() { return Fragments; } + + const MCSection &getSection() const { return Section; } + + unsigned getAlignment() const { return Alignment; } + void setAlignment(unsigned Value) { Alignment = Value; } + + /// @name Assembler Backend Support + /// @{ + // + // FIXME: This could all be kept private to the assembler implementation. + + unsigned getFileSize() const { return FileSize; } + + uint64_t getFileOffset() const { return FileOffset; } + void setFileOffset(uint64_t Value) { FileOffset = Value; } + + void WriteFileData(raw_ostream &OS) const; + + /// @} +}; + +class MCAssembler { +public: + typedef iplist SectionDataListType; + + typedef SectionDataListType::const_iterator const_iterator; + typedef SectionDataListType::iterator iterator; + +private: + MCAssembler(const MCAssembler&); // DO NOT IMPLEMENT + void operator=(const MCAssembler&); // DO NOT IMPLEMENT + + raw_ostream &OS; + + iplist Sections; + +public: + /// Construct a new assembler instance. + /// + /// \arg OS - The stream to output to. + // + // FIXME: How are we going to parameterize this? Two obvious options are stay + // concrete and require clients to pass in a target like object. The other + // option is to make this abstract, and have targets provide concrete + // implementations as we do with AsmParser. + MCAssembler(raw_ostream &OS); + ~MCAssembler(); + + /// Finish - Do final processing and write the object to the output stream. + void Finish(); + + /// @name Section List Access + /// @{ + + const SectionDataListType &getSectionList() const { return Sections; } + SectionDataListType &getSectionList() { return Sections; } + + iterator begin() { return Sections.begin(); } + const_iterator begin() const { return Sections.begin(); } + + iterator end() { return Sections.end(); } + const_iterator end() const { return Sections.end(); } + + size_t size() const { return Sections.size(); } + + /// @} +}; + +} // end namespace llvm + +#endif -- cgit v1.2.3