Than McIntosh | c84d402 | 2018-06-20 08:50:57 -0400 | [diff] [blame] | 1 | //===-- Action.cpp --------------------------------------------------------===// |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 2 | // |
Than McIntosh | c84d402 | 2018-06-20 08:50:57 -0400 | [diff] [blame] | 3 | // 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 McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 6 | // |
| 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 McIntosh | cdcf132 | 2020-09-15 15:02:51 -0400 | [diff] [blame] | 18 | #include <sstream> |
| 19 | |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 20 | namespace gollvm { |
| 21 | namespace driver { |
| 22 | |
| 23 | const char *Action::getName() const |
| 24 | { |
| 25 | switch (type_) { |
Than McIntosh | fac7031 | 2018-05-09 09:46:46 -0400 | [diff] [blame] | 26 | case A_ReadStdin: return "readstdin"; |
| 27 | case A_InputFile: return "inputfile"; |
Than McIntosh | cdcf132 | 2020-09-15 15:02:51 -0400 | [diff] [blame] | 28 | case A_CompileAndAssemble: return "compile+assemble"; |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 29 | 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 | |
| 39 | const char *Action::resultFileSuffix() const |
| 40 | { |
| 41 | switch (type_) { |
Than McIntosh | fac7031 | 2018-05-09 09:46:46 -0400 | [diff] [blame] | 42 | case A_ReadStdin: { |
| 43 | const ReadStdinAction *rsia = this->castToReadStdinAction(); |
| 44 | return rsia->suffix(); |
| 45 | } |
| 46 | case A_InputFile: return "i"; |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 47 | case A_Compile: return "s"; |
eric fang | 748fb5e | 2020-11-12 11:52:01 +0800 | [diff] [blame] | 48 | case A_Assemble: |
| 49 | case A_CompileAndAssemble: return "o"; |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 50 | case A_Link: return "e"; |
| 51 | default: |
| 52 | assert(false); |
| 53 | return "x"; |
| 54 | } |
| 55 | return nullptr; |
| 56 | } |
| 57 | |
Than McIntosh | cdcf132 | 2020-09-15 15:02:51 -0400 | [diff] [blame] | 58 | std::string Action::toString() |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 59 | { |
Than McIntosh | cdcf132 | 2020-09-15 15:02:51 -0400 | [diff] [blame] | 60 | std::stringstream s; |
| 61 | s << "Action " << getName() << std::endl << " inputs:\n"; |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 62 | for (auto inp : inputs()) { |
Than McIntosh | cdcf132 | 2020-09-15 15:02:51 -0400 | [diff] [blame] | 63 | s << " " << inp->getName() << " "; |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 64 | InputAction *ia = inp->castToInputAction(); |
| 65 | if (ia) |
Than McIntosh | cdcf132 | 2020-09-15 15:02:51 -0400 | [diff] [blame] | 66 | s << ia->input()->toString(); |
| 67 | s << "\n"; |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 68 | } |
Than McIntosh | cdcf132 | 2020-09-15 15:02:51 -0400 | [diff] [blame] | 69 | return s.str(); |
| 70 | } |
| 71 | |
| 72 | void Action::dump() |
| 73 | { |
| 74 | llvm::errs() << toString(); |
Than McIntosh | a71e06e | 2018-04-23 18:22:53 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | } // end namespace driver |
| 78 | } // end namespace gollvm |