2 * Copyright 2017 Jacob Lifshay
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:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
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
27 namespace generate_spirv_parser
33 std::string
to_hex_string(std::uint32_t v
)
35 return json::ast::Number_value::append_unsigned_integer_to_string(v
, "0x", 0x10, 8);
38 constexpr json::Location
make_empty_location() noexcept
40 // use function to make empty location so it will be easy to find all occurrences if location
41 // info is added to ast
46 json::ast::Value
Copyright::to_json() const
48 json::ast::Array retval
;
49 retval
.values
.reserve(lines
.size());
50 for(auto &line
: lines
)
51 retval
.values
.push_back(json::ast::Value(make_empty_location(), line
));
52 return json::ast::Value(make_empty_location(), std::move(retval
));
55 json::ast::Value
Instructions::to_json() const
57 json::ast::Array retval
;
59 return json::ast::Value(make_empty_location(), std::move(retval
));
62 json::ast::Value
Operand_kinds::Operand_kind::Enumerants::Enumerant::to_json() const
64 json::ast::Object retval
;
66 return json::ast::Value(make_empty_location(), std::move(retval
));
69 json::ast::Value
Operand_kinds::Operand_kind::Enumerants::to_json() const
71 json::ast::Array retval
;
72 retval
.values
.reserve(enumerants
.size());
73 for(auto &enumerant
: enumerants
)
74 retval
.values
.push_back(enumerant
.to_json());
75 return json::ast::Value(make_empty_location(), std::move(retval
));
78 json::ast::Value
Operand_kinds::Operand_kind::Doc::to_json() const
80 return json::ast::Value(make_empty_location(), value
);
83 json::ast::Value
Operand_kinds::Operand_kind::Bases::to_json() const
85 json::ast::Array retval
;
86 retval
.values
.reserve(values
.size());
87 for(auto &value
: values
)
88 retval
.values
.push_back(json::ast::Value(make_empty_location(), value
));
89 return json::ast::Value(make_empty_location(), std::move(retval
));
92 json::ast::Value
Operand_kinds::Operand_kind::to_json() const
94 json::ast::Object retval
;
95 retval
.values
["category"] =
96 json::ast::Value(make_empty_location(), get_json_name_from_category(category
));
97 retval
.values
["kind"] = json::ast::Value(make_empty_location(), kind
);
98 retval
.values
[get_value_json_key_name_from_category(category
)] = util::visit(
99 [&](auto &v
) -> json::ast::Value
104 return json::ast::Value(make_empty_location(), std::move(retval
));
107 json::ast::Value
Operand_kinds::to_json() const
109 json::ast::Array retval
;
110 retval
.values
.reserve(operand_kinds
.size());
111 for(auto &operand_kind
: operand_kinds
)
112 retval
.values
.push_back(operand_kind
.to_json());
113 return json::ast::Value(make_empty_location(), std::move(retval
));
116 json::ast::Value
Top_level::to_json() const
118 json::ast::Object retval
;
119 retval
.values
["copyright"] = copyright
.to_json();
120 retval
.values
["magic_number"] =
121 json::ast::Value(make_empty_location(), to_hex_string(magic_number
));
122 retval
.values
["major_version"] = json::ast::Value(
123 make_empty_location(), json::ast::Number_value::unsigned_integer_to_string(major_version
));
124 retval
.values
["minor_version"] = json::ast::Value(
125 make_empty_location(), json::ast::Number_value::unsigned_integer_to_string(minor_version
));
126 retval
.values
["revision"] = json::ast::Value(
127 make_empty_location(), json::ast::Number_value::unsigned_integer_to_string(revision
));
128 retval
.values
["instructions"] = instructions
.to_json();
129 retval
.values
["operand_kinds"] = operand_kinds
.to_json();
130 return json::ast::Value(make_empty_location(), std::move(retval
));