carbon.cpp 992 B

123456789101112131415161718192021222324252627
  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. #include "explorer/main.h"
  5. #include "llvm/ADT/SmallString.h"
  6. #include "llvm/Support/FileSystem.h"
  7. #include "llvm/Support/Path.h"
  8. namespace fs = llvm::sys::fs;
  9. namespace path = llvm::sys::path;
  10. auto main(int argc, char** argv) -> int {
  11. llvm::StringRef bin = path::filename(argv[0]);
  12. if (bin == "carbon-explorer") {
  13. static int static_for_main_addr;
  14. std::string exe = fs::getMainExecutable(
  15. argv[0], static_cast<void*>(&static_for_main_addr));
  16. llvm::StringRef install_path = path::parent_path(exe);
  17. llvm::SmallString<256> prelude_file(install_path);
  18. path::append(prelude_file, "data", "prelude.carbon");
  19. return Carbon::ExplorerMain(prelude_file, argc, argv);
  20. } else {
  21. fprintf(stderr, "Unrecognized Carbon binary requested: %s", argv[0]);
  22. return 1;
  23. }
  24. }