1314564Sdim//===------ Core/Pass.h - Base class for linker passes ----------*- C++ -*-===//
2280461Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6280461Sdim//
7280461Sdim//===----------------------------------------------------------------------===//
8280461Sdim
9280461Sdim#ifndef LLD_CORE_PASS_H
10280461Sdim#define LLD_CORE_PASS_H
11280461Sdim
12303239Sdim#include "llvm/Support/Error.h"
13280461Sdim
14280461Sdimnamespace lld {
15314564Sdim
16292934Sdimclass SimpleFile;
17280461Sdim
18280461Sdim/// Once the core linking is done (which resolves references, coalesces atoms
19280461Sdim/// and produces a complete Atom graph), the linker runs a series of passes
20280461Sdim/// on the Atom graph. The graph is modeled as a File, which means the pass
21280461Sdim/// has access to all the atoms and to File level attributes. Each pass does
22280461Sdim/// a particular transformation to the Atom graph or to the File attributes.
23280461Sdim///
24280461Sdim/// This is the abstract base class for all passes.  A Pass does its
25280461Sdim/// actual work in it perform() method.  It can iterator over Atoms in the
26280461Sdim/// graph using the *begin()/*end() atom iterator of the File.  It can add
27280461Sdim/// new Atoms to the graph using the File's addAtom() method.
28280461Sdimclass Pass {
29280461Sdimpublic:
30314564Sdim  virtual ~Pass() = default;
31280461Sdim
32280461Sdim  /// Do the actual work of the Pass.
33303239Sdim  virtual llvm::Error perform(SimpleFile &mergedFile) = 0;
34280461Sdim
35280461Sdimprotected:
36280461Sdim  // Only subclassess can be instantiated.
37314564Sdim  Pass() = default;
38280461Sdim};
39280461Sdim
40314564Sdim} // end namespace lld
41280461Sdim
42280461Sdim#endif // LLD_CORE_PASS_H
43