compile_subcommand.h 2.4 KB

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