compile_subcommand.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 dump_shared_values = false;
  36. bool dump_tokens = false;
  37. bool omit_file_boundary_tokens = false;
  38. bool dump_parse_tree = false;
  39. bool dump_raw_sem_ir = false;
  40. bool dump_sem_ir = false;
  41. bool dump_llvm_ir = false;
  42. bool dump_asm = false;
  43. bool dump_mem_usage = false;
  44. bool dump_timings = 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. Diagnoses and returns false
  63. // on failure.
  64. auto ValidateOptions(NoLocDiagnosticEmitter& emitter) const -> bool;
  65. CompileOptions options_;
  66. };
  67. } // namespace Carbon
  68. #endif // CARBON_TOOLCHAIN_DRIVER_COMPILE_SUBCOMMAND_H_