main.cpp 1.1 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_helpers.h"
  8. #include "executable_semantics/tracing_flag.h"
  9. #include "llvm/Support/CommandLine.h"
  10. extern FILE* yyin;
  11. extern auto yyparse() -> int; // NOLINT(readability-identifier-naming)
  12. int main(int argc, char* argv[]) {
  13. // yydebug = 1;
  14. using llvm::cl::desc;
  15. using llvm::cl::opt;
  16. opt<bool> quiet_option("quiet", desc("Disable tracing"));
  17. opt<std::string> input_filename(llvm::cl::Positional, desc("<input file>"));
  18. llvm::cl::ParseCommandLineOptions(argc, argv);
  19. if (input_filename.getNumOccurrences() > 0) {
  20. Carbon::input_filename = input_filename.c_str();
  21. yyin = fopen(input_filename.c_str(), "r");
  22. if (yyin == nullptr) {
  23. std::cerr << "Error opening '" << input_filename
  24. << "': " << strerror(errno) << std::endl;
  25. return 1;
  26. }
  27. }
  28. if (quiet_option) {
  29. Carbon::tracing_output = false;
  30. }
  31. return yyparse();
  32. }