blob: 1cdfabefebd7ed2553aef86b61d2b7fd9e587733 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- 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
18namespace lld {
19class File;
20class LinkingContext;
21class MachOLinkingContext;
22
Andrew Scullcdfcccc2018-10-05 20:58:37 +010023/// The Writer is an abstract class for writing object files, shared
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010024/// library files, and executable files. Each file format (e.g. mach-o, etc)
25/// has a concrete subclass of Writer.
26class Writer {
27public:
28 virtual ~Writer();
29
Andrew Scullcdfcccc2018-10-05 20:58:37 +010030 /// Write a file from the supplied File object
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010031 virtual llvm::Error writeFile(const File &linkedFile, StringRef path) = 0;
32
Andrew Scullcdfcccc2018-10-05 20:58:37 +010033 /// This method is called by Core Linking to give the Writer a chance
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010034 /// 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
38protected:
39 // only concrete subclasses can be instantiated
40 Writer();
41};
42
43std::unique_ptr<Writer> createWriterMachO(const MachOLinkingContext &);
44std::unique_ptr<Writer> createWriterYAML(const LinkingContext &);
45} // end namespace lld
46
47#endif