Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- lld/Core/Writer.h - Abstract File Format Interface -----------------===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 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 LLD_CORE_WRITER_H |
| 11 | #define LLD_CORE_WRITER_H |
| 12 | |
| 13 | #include "lld/Common/LLVM.h" |
| 14 | #include "llvm/Support/Error.h" |
| 15 | #include <memory> |
| 16 | #include <vector> |
| 17 | |
| 18 | namespace lld { |
| 19 | class File; |
| 20 | class LinkingContext; |
| 21 | class MachOLinkingContext; |
| 22 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 23 | /// The Writer is an abstract class for writing object files, shared |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 24 | /// library files, and executable files. Each file format (e.g. mach-o, etc) |
| 25 | /// has a concrete subclass of Writer. |
| 26 | class Writer { |
| 27 | public: |
| 28 | virtual ~Writer(); |
| 29 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 30 | /// Write a file from the supplied File object |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 31 | virtual llvm::Error writeFile(const File &linkedFile, StringRef path) = 0; |
| 32 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 33 | /// This method is called by Core Linking to give the Writer a chance |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 34 | /// to add file format specific "files" to set of files to be linked. This is |
| 35 | /// how file format specific atoms can be added to the link. |
| 36 | virtual void createImplicitFiles(std::vector<std::unique_ptr<File>> &) {} |
| 37 | |
| 38 | protected: |
| 39 | // only concrete subclasses can be instantiated |
| 40 | Writer(); |
| 41 | }; |
| 42 | |
| 43 | std::unique_ptr<Writer> createWriterMachO(const MachOLinkingContext &); |
| 44 | std::unique_ptr<Writer> createWriterYAML(const LinkingContext &); |
| 45 | } // end namespace lld |
| 46 | |
| 47 | #endif |