ONE - On-device Neural Engine
Loading...
Searching...
No Matches
flatc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 Google Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef FLATBUFFERS_FLATC_H_
19#define FLATBUFFERS_FLATC_H_
20
21#include <functional>
22#include <limits>
23#include <string>
24
26#include "flatbuffers/idl.h"
27#include "flatbuffers/util.h"
28
29namespace flatbuffers
30{
31
32extern void LogCompilerWarn(const std::string &warn);
33extern void LogCompilerError(const std::string &err);
34
36{
37public:
38 // Output generator for the various programming languages and formats we
39 // support.
40 struct Generator
41 {
42 typedef bool (*GenerateFn)(const flatbuffers::Parser &parser, const std::string &path,
43 const std::string &file_name);
44 typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser, const std::string &path,
45 const std::string &file_name);
46
49 const char *generator_opt_long;
50 const char *lang_name;
54 const char *generator_help;
56 };
57
58 typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn, bool show_exe_name);
59
60 typedef void (*ErrorFn)(const FlatCompiler *flatc, const std::string &err, bool usage,
61 bool show_exe_name);
62
63 // Parameters required to initialize the FlatCompiler.
65 {
66 InitParams() : generators(nullptr), num_generators(0), warn_fn(nullptr), error_fn(nullptr) {}
67
72 };
73
74 explicit FlatCompiler(const InitParams &params) : params_(params) {}
75
76 int Compile(int argc, const char **argv);
77
78 std::string GetUsageString(const char *program_name) const;
79
80private:
81 void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
82 const std::string &contents, std::vector<const char *> &include_directories) const;
83
84 void LoadBinarySchema(Parser &parser, const std::string &filename, const std::string &contents);
85
86 void Warn(const std::string &warn, bool show_exe_name = true) const;
87
88 void Error(const std::string &err, bool usage = true, bool show_exe_name = true) const;
89
90 InitParams params_;
91};
92
93} // namespace flatbuffers
94
95#endif // FLATBUFFERS_FLATC_H_
void(* ErrorFn)(const FlatCompiler *flatc, const std::string &err, bool usage, bool show_exe_name)
Definition flatc.h:60
FlatCompiler(const InitParams &params)
Definition flatc.h:74
void(* WarnFn)(const FlatCompiler *flatc, const std::string &warn, bool show_exe_name)
Definition flatc.h:58
std::string GetUsageString(const char *program_name) const
int Compile(int argc, const char **argv)
void LogCompilerError(const std::string &err)
void LogCompilerWarn(const std::string &warn)
flatbuffers::IDLOptions::Language lang
Definition flatc.h:53
bool(* GenerateFn)(const flatbuffers::Parser &parser, const std::string &path, const std::string &file_name)
Definition flatc.h:42
std::string(* MakeRuleFn)(const flatbuffers::Parser &parser, const std::string &path, const std::string &file_name)
Definition flatc.h:44