Use llvm's CommandLine for parsing (#332)

This commit is contained in:
Jon Meow
2021-03-02 15:16:17 -08:00
committed by GitHub
parent d48b17adc7
commit 30648724c9
4 changed files with 19 additions and 8 deletions
+13 -5
View File
@@ -7,6 +7,7 @@
#include <iostream>
#include "executable_semantics/syntax_helpers.h"
#include "llvm/Support/CommandLine.h"
extern FILE* yyin;
extern auto yyparse() -> int; // NOLINT(readability-identifier-naming)
@@ -14,12 +15,19 @@ extern auto yyparse() -> int; // NOLINT(readability-identifier-naming)
int main(int argc, char* argv[]) {
// yydebug = 1;
if (argc > 1) {
Carbon::input_filename = argv[1];
yyin = fopen(argv[1], "r");
using llvm::cl::desc;
using llvm::cl::opt;
// TODO: Add with related support.
// opt<bool> quiet_option("quiet", desc("Disable tracing"));
opt<std::string> input_filename(llvm::cl::Positional, desc("<input file>"));
llvm::cl::ParseCommandLineOptions(argc, argv);
if (input_filename.getNumOccurrences() > 0) {
Carbon::input_filename = input_filename.c_str();
yyin = fopen(input_filename.c_str(), "r");
if (yyin == nullptr) {
std::cerr << "Error opening '" << argv[1] << "': " << strerror(errno)
<< std::endl;
std::cerr << "Error opening '" << input_filename
<< "': " << strerror(errno) << std::endl;
return 1;
}
}