From: Jacob Lifshay Date: Mon, 5 Jun 2017 01:20:24 +0000 (-0700) Subject: implement all top-level json members X-Git-Tag: gsoc-2017~110 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=75f4c0b425183a5f7fcba6a3fe9a1fefc8e788e2;p=kazan.git implement all top-level json members --- diff --git a/src/generate_spirv_parser/ast.h b/src/generate_spirv_parser/ast.h index eedb5c7..1779c8a 100644 --- a/src/generate_spirv_parser/ast.h +++ b/src/generate_spirv_parser/ast.h @@ -44,21 +44,39 @@ struct copyright } }; +struct instructions +{ +#warning finish +}; + +struct operand_kinds +{ +#warning finish +}; + struct top_level { copyright copyright; std::uint32_t magic_number; std::size_t major_version; std::size_t minor_version; -#warning finish adding members + std::size_t revision; + instructions instructions; + operand_kinds operand_kinds; top_level(ast::copyright copyright, std::uint32_t magic_number, std::size_t major_version, - std::size_t minor_version) + std::size_t minor_version, + std::size_t revision, + ast::instructions instructions, + ast::operand_kinds operand_kinds) : copyright(std::move(copyright)), magic_number(magic_number), major_version(major_version), - minor_version(minor_version) + minor_version(minor_version), + revision(revision), + instructions(std::move(instructions)), + operand_kinds(std::move(operand_kinds)) { } }; diff --git a/src/generate_spirv_parser/parser.cpp b/src/generate_spirv_parser/parser.cpp index ee7595f..7596b92 100644 --- a/src/generate_spirv_parser/parser.cpp +++ b/src/generate_spirv_parser/parser.cpp @@ -80,6 +80,30 @@ ast::copyright parse_copyright(json::ast::value value, const path_builder_base * return ast::copyright(std::move(copyright_array)); } +ast::operand_kinds parse_operand_kinds(json::ast::value value, + const path_builder_base *parent_path_builder) +{ + if(json::ast::get_value_kind(value) != json::ast::value_kind::array) + throw parse_error(parent_path_builder->path(), "operand_kinds is not an array"); + auto &operand_kinds_array = + static_cast(*util::get(value)); + static_cast(operand_kinds_array); +#warning finish + return ast::operand_kinds(); +} + +ast::instructions parse_instructions(json::ast::value value, + const path_builder_base *parent_path_builder) +{ + if(json::ast::get_value_kind(value) != json::ast::value_kind::array) + throw parse_error(parent_path_builder->path(), "instructions is not an array"); + auto &instructions_array = + static_cast(*util::get(value)); + static_cast(instructions_array); +#warning finish + return ast::instructions(); +} + template T parse_integer(const json::ast::value &value, const path_builder_base *parent_path_builder, @@ -163,7 +187,9 @@ ast::top_level parse(json::ast::value &&top_level_value) util::optional magic_number; util::optional major_version; util::optional minor_version; -#warning finish adding ast::top_level members + util::optional revision; + util::optional instructions; + util::optional operand_kinds; for(auto &entry : top_level_object.values) { const auto &key = std::get<0>(entry); @@ -186,16 +212,32 @@ ast::top_level parse(json::ast::value &&top_level_value) { minor_version = parse_integer(entry_value, &path_builder, "minor_version"); } + else if(key == "revision") + { + revision = parse_integer(entry_value, &path_builder, "revision"); + } + else if(key == "instructions") + { + instructions = parse_instructions(std::move(entry_value), &path_builder); + } + else if(key == "operand_kinds") + { + operand_kinds = parse_operand_kinds(std::move(entry_value), &path_builder); + } else { throw parse_error(path_builder.path(), "unknown key"); } } - return ast::top_level( + auto retval = ast::top_level( get_value_or_throw_parse_error(std::move(copyright), nullptr, "missing copyright"), get_value_or_throw_parse_error(magic_number, nullptr, "missing magic_number"), get_value_or_throw_parse_error(major_version, nullptr, "missing major_version"), - get_value_or_throw_parse_error(minor_version, nullptr, "missing minor_version")); + get_value_or_throw_parse_error(minor_version, nullptr, "missing minor_version"), + get_value_or_throw_parse_error(revision, nullptr, "missing revision"), + get_value_or_throw_parse_error(instructions, nullptr, "missing instructions"), + get_value_or_throw_parse_error(operand_kinds, nullptr, "missing operand_kinds")); + throw parse_error({}, "not finished implementing"); } } }