diff --git a/lib/fizzy/execute.cpp b/lib/fizzy/execute.cpp index b3c97eeec..b9441f2a3 100644 --- a/lib/fizzy/execute.cpp +++ b/lib/fizzy/execute.cpp @@ -214,8 +214,8 @@ std::tuple allocate_memory(const std::vector& module_ } } -uint64_t eval_constant_expression(ConstantExpression expr, - const std::vector& imported_globals, const std::vector& globals) +Value eval_constant_expression(ConstantExpression expr, + const std::vector& imported_globals, const std::vector& globals) { if (expr.kind == ConstantExpression::Kind::Constant) return expr.value.constant; @@ -486,7 +486,7 @@ std::unique_ptr instantiate(Module module, match_imported_globals(module.imported_global_types, imported_globals); // Init globals - std::vector globals; + std::vector globals; globals.reserve(module.globalsec.size()); for (auto const& global : module.globalsec) { diff --git a/lib/fizzy/execute.hpp b/lib/fizzy/execute.hpp index 2d41e3b10..065846e53 100644 --- a/lib/fizzy/execute.hpp +++ b/lib/fizzy/execute.hpp @@ -58,7 +58,7 @@ struct ExternalMemory struct ExternalGlobal { - uint64_t* value = nullptr; + Value* value = nullptr; bool is_mutable = false; }; @@ -77,12 +77,12 @@ struct Instance // For these cases unique_ptr would either have a normal deleter or noop deleter respectively. table_ptr table = {nullptr, [](table_elements*) {}}; Limits table_limits; - std::vector globals; + std::vector globals; std::vector imported_functions; std::vector imported_globals; Instance(Module _module, bytes_ptr _memory, Limits _memory_limits, table_ptr _table, - Limits _table_limits, std::vector _globals, + Limits _table_limits, std::vector _globals, std::vector _imported_functions, std::vector _imported_globals) : module(std::move(_module)), diff --git a/lib/fizzy/parser.cpp b/lib/fizzy/parser.cpp index cd6dd1bd9..c89d5e6e5 100644 --- a/lib/fizzy/parser.cpp +++ b/lib/fizzy/parser.cpp @@ -126,6 +126,15 @@ inline parser_result parse_global_type(const uint8_t* pos, const uin return {type, pos}; } +template +inline parser_result parse_floating_point(const uint8_t* pos, const uint8_t* end) +{ + if ((pos + sizeof(T)) > end) + throw parser_error{"unexpected EOF"}; + + return {*reinterpret_cast(pos), pos + sizeof(T)}; +} + inline parser_result parse_constant_expression( ValType expected_type, const uint8_t* pos, const uint8_t* end) { @@ -174,17 +183,14 @@ inline parser_result parse_constant_expression( break; } case Instr::f32_const: - // TODO: support this once floating points are implemented result.kind = ConstantExpression::Kind::Constant; - result.value.constant = 0; - pos = skip(4, pos, end); + std::tie(result.value.constant, pos) = parse_floating_point(pos, end); constant_actual_type = ValType::f32; break; case Instr::f64_const: - // TODO: support this once floating points are implemented result.kind = ConstantExpression::Kind::Constant; result.value.constant = 0; - pos = skip(8, pos, end); + std::tie(result.value.constant, pos) = parse_floating_point(pos, end); constant_actual_type = ValType::f64; break; }