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