mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
I think this will work on linux/mac, not windows obviously. But the essence is that running `bazel run -c opt //installers/local:install` will create: Symlink: /usr/bin/carbon-explorer -> /usr/lib/carbon/carbon BusyBox-style binary: /usr/lib/carbon/carbon File: /usr/lib/carbon/data/prelude.carbon And then just running `carbon-explorer foo.carbon` with no flags (in particular, not --prelude) will work. Since this removes the need for prelude_file in most cases, I'm removing the relative path logic added in #1179 -- it would otherwise conflict with what I'm doing here. I *think* overall this will result in something even simpler and more reliable for compiler explorer to use, and hopefully with enough flexibility that it's easy for us to change how it's implemented later without breaking much.
70 lines
2.3 KiB
C++
70 lines
2.3 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "executable_semantics/main.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "common/error.h"
|
|
#include "executable_semantics/common/arena.h"
|
|
#include "executable_semantics/common/nonnull.h"
|
|
#include "executable_semantics/interpreter/exec_program.h"
|
|
#include "executable_semantics/syntax/parse.h"
|
|
#include "executable_semantics/syntax/prelude.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
#include "llvm/Support/InitLLVM.h"
|
|
|
|
namespace Carbon {
|
|
|
|
namespace cl = llvm::cl;
|
|
|
|
static auto Main(llvm::StringRef default_prelude_file, int argc, char* argv[])
|
|
-> ErrorOr<Success> {
|
|
llvm::setBugReportMsg(
|
|
"Please report issues to "
|
|
"https://github.com/carbon-language/carbon-lang/issues and include the "
|
|
"crash backtrace.\n");
|
|
llvm::InitLLVM init_llvm(argc, argv);
|
|
|
|
// Printing to stderr should flush stdout. This is most noticeable when stderr
|
|
// is piped to stdout.
|
|
llvm::errs().tie(&llvm::outs());
|
|
|
|
cl::opt<bool> trace_option("trace", cl::desc("Enable tracing"));
|
|
cl::opt<std::string> input_file_name(cl::Positional, cl::desc("<input file>"),
|
|
cl::Required);
|
|
|
|
// Find the path of the executable if possible and use that as a relative root
|
|
cl::opt<std::string> prelude_file_name("prelude", cl::desc("<prelude file>"),
|
|
cl::init(default_prelude_file.str()));
|
|
cl::ParseCommandLineOptions(argc, argv);
|
|
|
|
Arena arena;
|
|
ASSIGN_OR_RETURN(AST ast, Parse(&arena, input_file_name, trace_option));
|
|
AddPrelude(prelude_file_name, &arena, &ast.declarations);
|
|
|
|
// Typecheck and run the parsed program.
|
|
ASSIGN_OR_RETURN(int unused_return_code,
|
|
ExecProgram(&arena, ast, trace_option));
|
|
(void)unused_return_code;
|
|
return Success();
|
|
}
|
|
|
|
auto ExecutableSemanticsMain(llvm::StringRef default_prelude_file, int argc,
|
|
char** argv) -> int {
|
|
if (auto result = Main(default_prelude_file, argc, argv); !result.ok()) {
|
|
llvm::errs() << result.error().message() << "\n";
|
|
return EXIT_FAILURE;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
} // namespace Carbon
|