blob: 21fde97f6305ed1b4f06faecfefaebdfb0bccf3d [file] [log] [blame]
Than McIntosha71e06e2018-04-23 18:22:53 -04001//===-- Artifact.h --------------------------------------------------------===//
2//
Than McIntoshc84d4022018-06-20 08:50:57 -04003// Copyright 2018 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
Than McIntosha71e06e2018-04-23 18:22:53 -04006//
7//===----------------------------------------------------------------------===//
8//
9// Defines the Artifact class (helper for driver functionality).
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef GOLLVM_DRIVER_ARTIFACT_H
14#define GOLLVM_DRIVER_ARTIFACT_H
15
16#include "llvm/ADT/SmallVector.h"
17
18namespace llvm {
19namespace opt {
20class Arg;
21}
22}
23
24namespace gollvm {
25namespace driver {
26
27// An artifact is a file produced or consumed by some compilation step.
28// Artifacts may correspond to user-specified files (command line arg
29// for example) or temporary files created by some intermediate phase
30// in the compilation.
31
32class Artifact {
33 public:
34 enum Type {
35 A_Argument,
36 A_TempFile,
37 A_Empty
38 };
39
40 // Empty artifact (unusable as is)
41 Artifact() : type_(A_Empty) { u.arg = nullptr; }
42
43 // Construct an artifact from a command line arg.
44 explicit Artifact(llvm::opt::Arg *arg)
45 : type_(A_Argument) { u.arg = arg; }
46
47 // Construct an artifact given a temp file path.
48 explicit Artifact(const char *tempfilepath)
49 : type_(A_TempFile) { u.file = tempfilepath; }
50
51 // Type of input
52 Type type() const { return type_; }
53
54 // File for input
55 const char *file() const;
56
Than McIntosh93bb72f2018-04-24 15:36:24 -040057 // Return input argument if type is A_Argument, null otherwise.
58 llvm::opt::Arg *arg();
59
Than McIntosha71e06e2018-04-23 18:22:53 -040060 // Debugging
61 std::string toString();
62 void dump();
63
64 private:
65 Type type_;
66 union {
67 llvm::opt::Arg *arg;
68 const char *file;
69 } u;
70};
71
72// A list of artifacts.
73typedef llvm::SmallVector<Artifact *, 3> ArtifactList;
74
75} // end namespace driver
76} // end namespace gollvm
77
78#endif // GOLLVM_DRIVER_ARTIFACT_H