compile_subcommand.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_
  5. #define CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_
  6. #include "common/command_line.h"
  7. #include "common/error.h"
  8. #include "common/ostream.h"
  9. #include "llvm/ADT/SmallVector.h"
  10. #include "llvm/ADT/StringRef.h"
  11. #include "toolchain/check/check.h"
  12. #include "toolchain/driver/codegen_options.h"
  13. #include "toolchain/driver/driver_env.h"
  14. #include "toolchain/driver/driver_subcommand.h"
  15. namespace Carbon {
  16. // Options for the compile subcommand.
  17. //
  18. // See the implementation of `Build` for documentation on members.
  19. struct CompileOptions {
  20. enum class Phase : int8_t {
  21. Lex,
  22. Parse,
  23. Check,
  24. Lower,
  25. CodeGen,
  26. };
  27. friend auto operator<<(llvm::raw_ostream& out, Phase phase)
  28. -> llvm::raw_ostream&;
  29. auto Build(CommandLine::CommandBuilder& b) -> void;
  30. CodegenOptions codegen_options;
  31. Phase phase;
  32. Check::CheckParseTreesOptions::DumpSemIRRanges dump_sem_ir_ranges;
  33. llvm::StringRef output_filename;
  34. llvm::SmallVector<llvm::StringRef> input_filenames;
  35. llvm::SmallVector<llvm::StringRef> clang_args;
  36. bool asm_output = false;
  37. bool force_obj_output = false;
  38. bool custom_core = false;
  39. bool dump_shared_values = false;
  40. bool dump_tokens = false;
  41. bool omit_file_boundary_tokens = false;
  42. bool dump_parse_tree = false;
  43. bool dump_raw_sem_ir = false;
  44. bool dump_sem_ir = false;
  45. bool dump_llvm_ir = false;
  46. bool dump_asm = false;
  47. bool dump_mem_usage = false;
  48. bool dump_timings = false;
  49. bool stream_errors = false;
  50. bool preorder_parse_tree = false;
  51. bool builtin_sem_ir = false;
  52. bool prelude_import = false;
  53. bool include_debug_info = true;
  54. bool run_llvm_verifier = true;
  55. llvm::SmallVector<llvm::StringRef> exclude_dump_file_prefixes;
  56. };
  57. // Implements the compile subcommand of the driver.
  58. class CompileSubcommand : public DriverSubcommand {
  59. public:
  60. explicit CompileSubcommand();
  61. auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
  62. options_.Build(b);
  63. }
  64. auto Run(DriverEnv& driver_env) -> DriverResult override;
  65. private:
  66. // Does custom validation of the compile-subcommand options structure beyond
  67. // what the command line parsing library supports. Diagnoses and returns false
  68. // on failure.
  69. auto ValidateOptions(Diagnostics::NoLocEmitter& emitter) const -> bool;
  70. CompileOptions options_;
  71. };
  72. } // namespace Carbon
  73. #endif // CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_