Home | History | Annotate | Download | only in wasm
      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/memory-tracing.h"
      6 
      7 #include "src/utils.h"
      8 #include "src/v8memory.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 namespace wasm {
     13 
     14 void TraceMemoryOperation(ExecutionTier tier, const MemoryTracingInfo* info,
     15                           int func_index, int position, uint8_t* mem_start) {
     16   EmbeddedVector<char, 64> value;
     17   auto mem_rep = static_cast<MachineRepresentation>(info->mem_rep);
     18   switch (mem_rep) {
     19 #define TRACE_TYPE(rep, str, format, ctype1, ctype2)                     \
     20   case MachineRepresentation::rep:                                       \
     21     SNPrintF(value, str ":" format,                                      \
     22              ReadLittleEndianValue<ctype1>(                              \
     23                  reinterpret_cast<Address>(mem_start) + info->address),  \
     24              ReadLittleEndianValue<ctype2>(                              \
     25                  reinterpret_cast<Address>(mem_start) + info->address)); \
     26     break;
     27     TRACE_TYPE(kWord8, " i8", "%d / %02x", uint8_t, uint8_t)
     28     TRACE_TYPE(kWord16, "i16", "%d / %04x", uint16_t, uint16_t)
     29     TRACE_TYPE(kWord32, "i32", "%d / %08x", uint32_t, uint32_t)
     30     TRACE_TYPE(kWord64, "i64", "%" PRId64 " / %016" PRIx64, uint64_t, uint64_t)
     31     TRACE_TYPE(kFloat32, "f32", "%f / %08x", float, uint32_t)
     32     TRACE_TYPE(kFloat64, "f64", "%f / %016" PRIx64, double, uint64_t)
     33 #undef TRACE_TYPE
     34     default:
     35       SNPrintF(value, "???");
     36   }
     37   const char* eng = "?";
     38   switch (tier) {
     39     case ExecutionTier::kOptimized:
     40       eng = "turbofan";
     41       break;
     42     case ExecutionTier::kBaseline:
     43       eng = "liftoff";
     44       break;
     45     case ExecutionTier::kInterpreter:
     46       eng = "interpreter";
     47       break;
     48   }
     49   printf("%-11s func:%6d+0x%-6x%s %08x val: %s\n", eng, func_index, position,
     50          info->is_store ? " store to" : "load from", info->address,
     51          value.start());
     52 }
     53 
     54 }  // namespace wasm
     55 }  // namespace internal
     56 }  // namespace v8
     57