User Guide
main_c.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <CLI/CLI.hpp>
9 
10 #include "config/config.h"
11 #include "utils/logger.hpp"
12 
13 #include "parser/c11_driver.hpp"
14 
15 /**
16  * \file
17  * Standalone parser program for C. This demonstrate basic
18  * usage of parser and driver class.
19  */
20 
21 using namespace nmodl;
22 
23 int main(int argc, const char* argv[]) {
24  CLI::App app{fmt::format("C-Parser : Standalone Parser for C Code({})", Version::to_string())};
25 
26  std::vector<std::string> files;
27  app.add_option("file", files, "One or more C files to process")
28  ->required()
29  ->check(CLI::ExistingFile);
30 
31  CLI11_PARSE(app, argc, argv);
32 
33  for (const auto& f: files) {
34  logger->info("Processing {}", f);
35  std::ifstream file(f);
36 
37  /// driver object creates lexer and parser
39  driver.set_verbose(true);
40 
41  /// just call parser method
42  driver.parse_stream(file);
43  }
44  return 0;
45 }
main
int main(int argc, const char *argv[])
Definition: main_c.cpp:46
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::logger
logger_type logger
Definition: logger.cpp:34
nmodl::parser::CDriver
Class that binds all pieces together for parsing C verbatim blocks.
Definition: c11_driver.hpp:37
nmodl::parser::UnitDriver::set_verbose
void set_verbose(bool b)
Definition: unit_driver.hpp:69
driver
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28
c11_driver.hpp
nmodl::Version::to_string
static std::string to_string()
return version string (version + git id) as a string
Definition: config.h:39
logger.hpp
Implement logger based on spdlog library.
config.h
Version information and units file path.
nmodl::parser::UnitDriver::parse_stream
bool parse_stream(std::istream &in)
parse Units file provided as istream
Definition: unit_driver.cpp:18