main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 <cstdio>
  5. #include <cstring>
  6. #include <iostream>
  7. #include "executable_semantics/syntax/parse.h"
  8. #include "executable_semantics/syntax/syntax_helpers.h"
  9. #include "executable_semantics/tracing_flag.h"
  10. #include "llvm/Support/CommandLine.h"
  11. int main(int argc, char* argv[]) {
  12. // yydebug = 1;
  13. using llvm::cl::desc;
  14. using llvm::cl::opt;
  15. opt<bool> trace_option("trace", desc("Enable tracing"));
  16. opt<std::string> inputFileName(llvm::cl::Positional, desc("<input file>"),
  17. llvm::cl::Required);
  18. llvm::cl::ParseCommandLineOptions(argc, argv);
  19. if (trace_option) {
  20. Carbon::tracing_output = true;
  21. }
  22. std::variant<Carbon::AST, Carbon::SyntaxErrorCode> astOrError =
  23. Carbon::parse(inputFileName);
  24. if (auto* error = std::get_if<Carbon::SyntaxErrorCode>(&astOrError)) {
  25. // Diagnostic already reported to std::cerr; this is just a return code.
  26. return *error;
  27. }
  28. // Typecheck and run the parsed program.
  29. Carbon::ExecProgram(std::get<Carbon::AST>(astOrError));
  30. }