LCOV - code coverage report
Current view: top level - src/wasm - local-decl-encoder.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 26 26 100.0 %
Date: 2017-04-26 Functions: 4 4 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/wasm/leb-helper.h"
       8             : 
       9             : using namespace v8::internal;
      10             : using namespace v8::internal::wasm;
      11             : 
      12           1 : void LocalDeclEncoder::Prepend(Zone* zone, const byte** start,
      13             :                                const byte** end) const {
      14           1 :   size_t size = (*end - *start);
      15           1 :   byte* buffer = reinterpret_cast<byte*>(zone->New(Size() + size));
      16           1 :   size_t pos = Emit(buffer);
      17           1 :   memcpy(buffer + pos, *start, size);
      18           1 :   pos += size;
      19           1 :   *start = buffer;
      20           1 :   *end = buffer + pos;
      21           1 : }
      22             : 
      23       76951 : size_t LocalDeclEncoder::Emit(byte* buffer) const {
      24             :   byte* pos = buffer;
      25      153902 :   LEBHelper::write_u32v(&pos, static_cast<uint32_t>(local_decls.size()));
      26      164911 :   for (auto& local_decl : local_decls) {
      27       11009 :     LEBHelper::write_u32v(&pos, local_decl.first);
      28             :     *pos = WasmOpcodes::ValueTypeCodeFor(local_decl.second);
      29       11009 :     ++pos;
      30             :   }
      31             :   DCHECK_EQ(Size(), pos - buffer);
      32       76951 :   return static_cast<size_t>(pos - buffer);
      33             : }
      34             : 
      35       39873 : uint32_t LocalDeclEncoder::AddLocals(uint32_t count, ValueType type) {
      36             :   uint32_t result =
      37       39873 :       static_cast<uint32_t>(total + (sig ? sig->parameter_count() : 0));
      38       39873 :   total += count;
      39       79746 :   if (local_decls.size() > 0 && local_decls.back().second == type) {
      40       28950 :     count += local_decls.back().first;
      41             :     local_decls.pop_back();
      42             :   }
      43       79746 :   local_decls.push_back(std::pair<uint32_t, ValueType>(count, type));
      44       39873 :   return result;
      45             : }
      46             : 
      47      108785 : size_t LocalDeclEncoder::Size() const {
      48      108785 :   size_t size = LEBHelper::sizeof_u32v(local_decls.size());
      49      196748 :   for (auto p : local_decls) size += 1 + LEBHelper::sizeof_u32v(p.first);
      50      108785 :   return size;
      51             : }

Generated by: LCOV version 1.10