blob: 8f32f20b7fe53f582174508bed69bbaee0e36f02 [file] [log] [blame]
Than McIntoshc84d4022018-06-20 08:50:57 -04001//===-- Action.cpp --------------------------------------------------------===//
Than McIntosha71e06e2018-04-23 18:22:53 -04002//
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// Gollvm driver helper class Action methods.
10//
11//===----------------------------------------------------------------------===//
12
13#include "Action.h"
14#include "Artifact.h"
15
16#include "llvm/Support/raw_ostream.h"
17
Than McIntoshcdcf1322020-09-15 15:02:51 -040018#include <sstream>
19
Than McIntosha71e06e2018-04-23 18:22:53 -040020namespace gollvm {
21namespace driver {
22
23const char *Action::getName() const
24{
25 switch (type_) {
Than McIntoshfac70312018-05-09 09:46:46 -040026 case A_ReadStdin: return "readstdin";
27 case A_InputFile: return "inputfile";
Than McIntoshcdcf1322020-09-15 15:02:51 -040028 case A_CompileAndAssemble: return "compile+assemble";
Than McIntosha71e06e2018-04-23 18:22:53 -040029 case A_Compile: return "compile";
30 case A_Assemble: return "assemble";
31 case A_Link: return "link";
32 default:
33 assert(false);
34 return "<unknown action type>";
35 }
36 return nullptr;
37}
38
39const char *Action::resultFileSuffix() const
40{
41 switch (type_) {
Than McIntoshfac70312018-05-09 09:46:46 -040042 case A_ReadStdin: {
43 const ReadStdinAction *rsia = this->castToReadStdinAction();
44 return rsia->suffix();
45 }
46 case A_InputFile: return "i";
Than McIntosha71e06e2018-04-23 18:22:53 -040047 case A_Compile: return "s";
eric fang748fb5e2020-11-12 11:52:01 +080048 case A_Assemble:
49 case A_CompileAndAssemble: return "o";
Than McIntosha71e06e2018-04-23 18:22:53 -040050 case A_Link: return "e";
51 default:
52 assert(false);
53 return "x";
54 }
55 return nullptr;
56}
57
Than McIntoshcdcf1322020-09-15 15:02:51 -040058std::string Action::toString()
Than McIntosha71e06e2018-04-23 18:22:53 -040059{
Than McIntoshcdcf1322020-09-15 15:02:51 -040060 std::stringstream s;
61 s << "Action " << getName() << std::endl << " inputs:\n";
Than McIntosha71e06e2018-04-23 18:22:53 -040062 for (auto inp : inputs()) {
Than McIntoshcdcf1322020-09-15 15:02:51 -040063 s << " " << inp->getName() << " ";
Than McIntosha71e06e2018-04-23 18:22:53 -040064 InputAction *ia = inp->castToInputAction();
65 if (ia)
Than McIntoshcdcf1322020-09-15 15:02:51 -040066 s << ia->input()->toString();
67 s << "\n";
Than McIntosha71e06e2018-04-23 18:22:53 -040068 }
Than McIntoshcdcf1322020-09-15 15:02:51 -040069 return s.str();
70}
71
72void Action::dump()
73{
74 llvm::errs() << toString();
Than McIntosha71e06e2018-04-23 18:22:53 -040075}
76
77} // end namespace driver
78} // end namespace gollvm