compile_subcommand.h 2.3 KB

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