compile_subcommand.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "toolchain/lower/options.h"
  16. namespace Carbon {
  17. // Options for the compile subcommand.
  18. //
  19. // See the implementation of `Build` for documentation on members.
  20. struct CompileOptions {
  21. enum class Phase : int8_t {
  22. Lex,
  23. Parse,
  24. Check,
  25. Lower,
  26. Optimize,
  27. CodeGen,
  28. };
  29. friend auto operator<<(llvm::raw_ostream& out, Phase phase)
  30. -> llvm::raw_ostream&;
  31. auto Build(CommandLine::CommandBuilder& b) -> void;
  32. Lower::OptimizationLevel opt_level = Lower::OptimizationLevel::Debug;
  33. CodegenOptions codegen_options;
  34. Phase phase;
  35. Check::CheckParseTreesOptions::DumpSemIRRanges dump_sem_ir_ranges;
  36. llvm::StringRef output_filename;
  37. llvm::SmallVector<llvm::StringRef> input_filenames;
  38. llvm::SmallVector<llvm::StringRef> clang_args;
  39. bool asm_output = false;
  40. bool force_obj_output = false;
  41. bool custom_core = false;
  42. bool dump_shared_values = false;
  43. bool dump_tokens = false;
  44. bool omit_file_boundary_tokens = false;
  45. bool dump_parse_tree = false;
  46. bool dump_raw_sem_ir = false;
  47. bool dump_sem_ir = false;
  48. bool dump_cpp_ast = false;
  49. bool dump_llvm_ir = false;
  50. bool dump_asm = false;
  51. bool dump_mem_usage = false;
  52. bool dump_timings = false;
  53. bool stream_errors = false;
  54. bool preorder_parse_tree = false;
  55. bool builtin_sem_ir = false;
  56. bool prelude_import = false;
  57. bool include_debug_info = true;
  58. bool run_llvm_verifier = true;
  59. llvm::SmallVector<llvm::StringRef> exclude_dump_file_prefixes;
  60. llvm::StringRef sem_ir_crash_dump;
  61. };
  62. // Implements the compile subcommand of the driver.
  63. class CompileSubcommand : public DriverSubcommand {
  64. public:
  65. explicit CompileSubcommand();
  66. auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
  67. options_.Build(b);
  68. }
  69. auto Run(DriverEnv& driver_env) -> DriverResult override;
  70. private:
  71. // Does custom validation of the compile-subcommand options structure beyond
  72. // what the command line parsing library supports. Diagnoses and returns false
  73. // on failure.
  74. auto ValidateOptions(Diagnostics::NoLocEmitter& emitter) const -> bool;
  75. CompileOptions options_;
  76. };
  77. } // namespace Carbon
  78. #endif // CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_