ONE - On-device Neural Engine
Loading...
Searching...
No Matches
flatc.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef FLATBUFFERS_FLATC_H_
18#define FLATBUFFERS_FLATC_H_
19
20#include <functional>
21#include <limits>
22#include <list>
23#include <memory>
24#include <string>
25
28#include "flatbuffers/idl.h"
29#include "flatbuffers/util.h"
30
31namespace flatbuffers {
32
33extern void LogCompilerWarn(const std::string &warn);
34extern void LogCompilerError(const std::string &err);
35
38
39 std::string program_name;
40
41 std::string output_path;
42
43 std::vector<std::string> filenames;
44
45 std::list<std::string> include_directories_storage;
46 std::vector<const char *> include_directories;
47 std::vector<const char *> conform_include_directories;
48 std::vector<bool> generator_enabled;
49 size_t binary_files_from = std::numeric_limits<size_t>::max();
50 std::string conform_to_schema;
51 std::string annotate_schema;
53 bool any_generator = false;
54 bool print_make_rules = false;
55 bool raw_binary = false;
56 bool schema_binary = false;
57 bool grpc_enabled = false;
58 bool requires_bfbs = false;
59 bool file_names_only = false;
60
61 std::vector<std::shared_ptr<CodeGenerator>> generators;
62};
63
65 std::string short_opt;
66 std::string long_opt;
67 std::string parameter;
68 std::string description;
69};
70
72 public:
73 typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn,
74 bool show_exe_name);
75
76 typedef void (*ErrorFn)(const FlatCompiler *flatc, const std::string &err,
77 bool usage, bool show_exe_name);
78
79 // Parameters required to initialize the FlatCompiler.
80 struct InitParams {
81 InitParams() : warn_fn(nullptr), error_fn(nullptr) {}
82
85 };
86
87 explicit FlatCompiler(const InitParams &params) : params_(params) {}
88
90 std::shared_ptr<CodeGenerator> code_generator);
91
92 int Compile(const FlatCOptions &options);
93
94 std::string GetShortUsageString(const std::string &program_name) const;
95 std::string GetUsageString(const std::string &program_name) const;
96
97 // Parse the FlatC options from command line arguments.
98 FlatCOptions ParseFromCommandLineArguments(int argc, const char **argv);
99
100 private:
101 void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
102 const std::string &contents,
103 const std::vector<const char *> &include_directories) const;
104
105 void LoadBinarySchema(Parser &parser, const std::string &filename,
106 const std::string &contents);
107
108 void Warn(const std::string &warn, bool show_exe_name = true) const;
109
110 void Error(const std::string &err, bool usage = true,
111 bool show_exe_name = true) const;
112
113 void AnnotateBinaries(const uint8_t *binary_schema,
114 uint64_t binary_schema_size,
115 const FlatCOptions &options);
116
117 void ValidateOptions(const FlatCOptions &options);
118
119 Parser GetConformParser(const FlatCOptions &options);
120
121 std::unique_ptr<Parser> GenerateCode(const FlatCOptions &options,
122 Parser &conform_parser);
123
124 std::map<std::string, std::shared_ptr<CodeGenerator>> code_generators_;
125
126 InitParams params_;
127};
128
129} // namespace flatbuffers
130
131#endif // FLATBUFFERS_FLATC_H_
void(* ErrorFn)(const FlatCompiler *flatc, const std::string &err, bool usage, bool show_exe_name)
Definition flatc.h:76
bool RegisterCodeGenerator(const FlatCOption &option, std::shared_ptr< CodeGenerator > code_generator)
int Compile(const FlatCOptions &options)
FlatCompiler(const InitParams &params)
Definition flatc.h:87
void(* WarnFn)(const FlatCompiler *flatc, const std::string &warn, bool show_exe_name)
Definition flatc.h:73
FlatCOptions ParseFromCommandLineArguments(int argc, const char **argv)
std::string GetShortUsageString(const std::string &program_name) const
std::string GetUsageString(const std::string &program_name) const
void LogCompilerError(const std::string &err)
void LogCompilerWarn(const std::string &warn)
std::string description
Definition flatc.h:68
std::string short_opt
Definition flatc.h:65
std::string long_opt
Definition flatc.h:66
std::string parameter
Definition flatc.h:67
std::string conform_to_schema
Definition flatc.h:50
bool annotate_include_vector_contents
Definition flatc.h:52
std::vector< bool > generator_enabled
Definition flatc.h:48
std::string output_path
Definition flatc.h:41
std::string annotate_schema
Definition flatc.h:51
std::vector< const char * > include_directories
Definition flatc.h:46
std::vector< std::shared_ptr< CodeGenerator > > generators
Definition flatc.h:61
std::string program_name
Definition flatc.h:39
std::vector< const char * > conform_include_directories
Definition flatc.h:47
std::vector< std::string > filenames
Definition flatc.h:43
std::list< std::string > include_directories_storage
Definition flatc.h:45