compile_subcommand.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. static const CommandLine::CommandInfo Info;
  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 dump_shared_values = false;
  36. bool dump_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 include_diagnostic_kind = false;
  44. bool stream_errors = false;
  45. bool preorder_parse_tree = false;
  46. bool builtin_sem_ir = false;
  47. bool prelude_import = false;
  48. bool include_debug_info = true;
  49. llvm::StringRef exclude_dump_file_prefix;
  50. };
  51. // Implements the compile subcommand of the driver.
  52. class CompileSubcommand : public DriverSubcommand {
  53. public:
  54. auto BuildOptions(CommandLine::CommandBuilder& b) { options_.Build(b); }
  55. auto Run(DriverEnv& driver_env) -> DriverResult override;
  56. private:
  57. // Does custom validation of the compile-subcommand options structure beyond
  58. // what the command line parsing library supports.
  59. auto ValidateOptions(DriverEnv& driver_env) const -> bool;
  60. CompileOptions options_;
  61. };
  62. } // namespace Carbon
  63. #endif // CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_