4a88efe0d8eb13badfdab67f8babfed6f9a0670b
[kazan.git] / src / generate_spirv_parser / generate_spirv_parser.cpp
1 /*
2 * Copyright 2017 Jacob Lifshay
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 *
22 */
23 #include <iostream>
24 #include "json/json.h"
25 #include "json/parser.h"
26 #include "parser.h"
27 #include "util/optional.h"
28 #include "generate.h"
29
30 namespace vulkan_cpu
31 {
32 namespace generate_spirv_parser
33 {
34 int generate_spirv_parser_main(int argc, char **argv)
35 {
36 std::string file_name;
37 std::string output_directory;
38 if(argc >= 2)
39 file_name = argv[1];
40 if(argc >= 3)
41 output_directory = argv[2];
42 if(argc != 3 || (file_name.size() > 1 && file_name[0] == '-')
43 || (output_directory.size() > 1 && output_directory[0] == '-'))
44 {
45 std::cerr << "usage: " << argv[0] << " <input.json> <output-directory>" << std::endl;
46 return 1;
47 }
48 try
49 {
50 auto source = file_name == "-" ? json::Source::load_stdin() :
51 json::Source::load_file(std::move(file_name));
52 try
53 {
54 auto json_in = json::parse(&source);
55 auto ast = parser::parse(json_in.duplicate());
56 for(auto &generator : {
57 generate::Generators::make_spirv_header_generator(),
58 })
59 {
60 generator->run(generate::Generator::Generator_args(output_directory), ast);
61 }
62 #warning finish
63 std::cerr << "generate_spirv_parser is not finished being implemented" << std::endl;
64 return 1;
65 }
66 catch(parser::Parse_error &e)
67 {
68 std::cerr << e.what() << std::endl;
69 return 1;
70 }
71 catch(json::Parse_error &e)
72 {
73 std::cerr << e.what() << std::endl;
74 return 1;
75 }
76 }
77 catch(std::exception &e)
78 {
79 std::cerr << "error: " << e.what() << std::endl;
80 return 1;
81 }
82 return 0;
83 }
84 }
85 }
86
87 int main(int argc, char **argv)
88 {
89 return vulkan_cpu::generate_spirv_parser::generate_spirv_parser_main(argc, argv);
90 }