compile_subcommand.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. };
  61. // Implements the compile subcommand of the driver.
  62. class CompileSubcommand : public DriverSubcommand {
  63. public:
  64. explicit CompileSubcommand();
  65. auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
  66. options_.Build(b);
  67. }
  68. auto Run(DriverEnv& driver_env) -> DriverResult override;
  69. private:
  70. // Does custom validation of the compile-subcommand options structure beyond
  71. // what the command line parsing library supports. Diagnoses and returns false
  72. // on failure.
  73. auto ValidateOptions(Diagnostics::NoLocEmitter& emitter) const -> bool;
  74. CompileOptions options_;
  75. };
  76. } // namespace Carbon
  77. #endif // CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_