ConfigManager.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===- ConfigManager.h ----------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_TOOLS_LLVM_OBJCOPY_CONFIGMANAGER_H
  9. #define LLVM_TOOLS_LLVM_OBJCOPY_CONFIGMANAGER_H
  10. #include "COFF/COFFConfig.h"
  11. #include "CommonConfig.h"
  12. #include "ELF/ELFConfig.h"
  13. #include "MachO/MachOConfig.h"
  14. #include "MultiFormatConfig.h"
  15. #include "wasm/WasmConfig.h"
  16. #include "llvm/Support/Allocator.h"
  17. #include <vector>
  18. namespace llvm {
  19. namespace objcopy {
  20. // ConfigManager keeps all configurations and prepare
  21. // format-specific options.
  22. struct ConfigManager : public MultiFormatConfig {
  23. virtual ~ConfigManager() {}
  24. const CommonConfig &getCommonConfig() const override { return Common; }
  25. Expected<const ELFConfig &> getELFConfig() const override;
  26. Expected<const COFFConfig &> getCOFFConfig() const override;
  27. Expected<const MachOConfig &> getMachOConfig() const override;
  28. Expected<const WasmConfig &> getWasmConfig() const override;
  29. // All configs.
  30. CommonConfig Common;
  31. ELFConfig ELF;
  32. COFFConfig COFF;
  33. MachOConfig MachO;
  34. WasmConfig Wasm;
  35. };
  36. // Configuration for the overall invocation of this tool. When invoked as
  37. // objcopy, will always contain exactly one CopyConfig. When invoked as strip,
  38. // will contain one or more CopyConfigs.
  39. struct DriverConfig {
  40. SmallVector<ConfigManager, 1> CopyConfigs;
  41. BumpPtrAllocator Alloc;
  42. };
  43. // ParseObjcopyOptions returns the config and sets the input arguments. If a
  44. // help flag is set then ParseObjcopyOptions will print the help messege and
  45. // exit. ErrorCallback is used to handle recoverable errors. An Error returned
  46. // by the callback aborts the parsing and is then returned by this function.
  47. Expected<DriverConfig>
  48. parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
  49. llvm::function_ref<Error(Error)> ErrorCallback);
  50. // ParseInstallNameToolOptions returns the config and sets the input arguments.
  51. // If a help flag is set then ParseInstallNameToolOptions will print the help
  52. // messege and exit.
  53. Expected<DriverConfig>
  54. parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr);
  55. // ParseBitcodeStripOptions returns the config and sets the input arguments.
  56. // If a help flag is set then ParseBitcodeStripOptions will print the help
  57. // messege and exit.
  58. Expected<DriverConfig> parseBitcodeStripOptions(ArrayRef<const char *> ArgsArr);
  59. // ParseStripOptions returns the config and sets the input arguments. If a
  60. // help flag is set then ParseStripOptions will print the help messege and
  61. // exit. ErrorCallback is used to handle recoverable errors. An Error returned
  62. // by the callback aborts the parsing and is then returned by this function.
  63. Expected<DriverConfig>
  64. parseStripOptions(ArrayRef<const char *> ArgsArr,
  65. llvm::function_ref<Error(Error)> ErrorCallback);
  66. } // namespace objcopy
  67. } // namespace llvm
  68. #endif // LLVM_TOOLS_LLVM_OBJCOPY_CONFIGMANAGER_H