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