compile_subcommand.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_cpp_ast = false;
  46. bool dump_llvm_ir = false;
  47. bool dump_asm = false;
  48. bool dump_mem_usage = false;
  49. bool dump_timings = false;
  50. bool stream_errors = false;
  51. bool preorder_parse_tree = false;
  52. bool builtin_sem_ir = false;
  53. bool prelude_import = false;
  54. bool gen_implicit_type_impls = false;
  55. bool include_debug_info = true;
  56. bool run_llvm_verifier = true;
  57. llvm::SmallVector<llvm::StringRef> exclude_dump_file_prefixes;
  58. };
  59. // Implements the compile subcommand of the driver.
  60. class CompileSubcommand : public DriverSubcommand {
  61. public:
  62. explicit CompileSubcommand();
  63. auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
  64. options_.Build(b);
  65. }
  66. auto Run(DriverEnv& driver_env) -> DriverResult override;
  67. private:
  68. // Does custom validation of the compile-subcommand options structure beyond
  69. // what the command line parsing library supports. Diagnoses and returns false
  70. // on failure.
  71. auto ValidateOptions(Diagnostics::NoLocEmitter& emitter) const -> bool;
  72. CompileOptions options_;
  73. };
  74. } // namespace Carbon
  75. #endif // CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_