LCOV - code coverage report
Current view: top level - src/wasm - local-decl-encoder.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 28 28 100.0 %
Date: 2019-01-20 Functions: 6 6 100.0 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/wasm/local-decl-encoder.h"
       6             : 
       7             : #include "src/signature.h"
       8             : #include "src/wasm/leb-helper.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : namespace wasm {
      13             : 
      14           1 : void LocalDeclEncoder::Prepend(Zone* zone, const byte** start,
      15             :                                const byte** end) const {
      16           1 :   size_t size = (*end - *start);
      17           1 :   byte* buffer = reinterpret_cast<byte*>(zone->New(Size() + size));
      18           1 :   size_t pos = Emit(buffer);
      19           1 :   memcpy(buffer + pos, *start, size);
      20           1 :   pos += size;
      21           1 :   *start = buffer;
      22           1 :   *end = buffer + pos;
      23           1 : }
      24             : 
      25     1410645 : size_t LocalDeclEncoder::Emit(byte* buffer) const {
      26             :   byte* pos = buffer;
      27     2821290 :   LEBHelper::write_u32v(&pos, static_cast<uint32_t>(local_decls.size()));
      28     1468478 :   for (auto& local_decl : local_decls) {
      29       57833 :     LEBHelper::write_u32v(&pos, local_decl.first);
      30       57833 :     *pos = ValueTypes::ValueTypeCodeFor(local_decl.second);
      31       57833 :     ++pos;
      32             :   }
      33             :   DCHECK_EQ(Size(), pos - buffer);
      34     1410645 :   return static_cast<size_t>(pos - buffer);
      35             : }
      36             : 
      37      893106 : uint32_t LocalDeclEncoder::AddLocals(uint32_t count, ValueType type) {
      38             :   uint32_t result =
      39      893106 :       static_cast<uint32_t>(total + (sig ? sig->parameter_count() : 0));
      40      893106 :   total += count;
      41     1786212 :   if (local_decls.size() > 0 && local_decls.back().second == type) {
      42      835358 :     count += local_decls.back().first;
      43             :     local_decls.pop_back();
      44             :   }
      45     1786212 :   local_decls.push_back(std::pair<uint32_t, ValueType>(count, type));
      46      893106 :   return result;
      47             : }
      48             : 
      49     1438281 : size_t LocalDeclEncoder::Size() const {
      50     1438281 :   size_t size = LEBHelper::sizeof_u32v(local_decls.size());
      51     1672536 :   for (auto p : local_decls) size += 1 + LEBHelper::sizeof_u32v(p.first);
      52     1438281 :   return size;
      53             : }
      54             : 
      55             : }  // namespace wasm
      56             : }  // namespace internal
      57      183867 : }  // namespace v8

Generated by: LCOV version 1.10