LCOV - code coverage report
Current view: top level - test/unittests/compiler - opcodes-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 30 30 100.0 %
Date: 2019-04-17 Functions: 14 20 70.0 %

          Line data    Source code
       1             : // Copyright 2015 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/compiler/opcodes.h"
       6             : #include "testing/gtest-support.h"
       7             : 
       8             : namespace v8 {
       9             : namespace internal {
      10             : namespace compiler {
      11             : 
      12             : namespace {
      13             : 
      14             : bool IsCommonOpcode(IrOpcode::Value opcode) {
      15         737 :   switch (opcode) {
      16             : #define OPCODE(Opcode)      \
      17             :   case IrOpcode::k##Opcode: \
      18             :     return true;
      19             :     COMMON_OP_LIST(OPCODE)
      20             :     CONTROL_OP_LIST(OPCODE)
      21             : #undef OPCODE
      22             :     default:
      23             :       return false;
      24             :   }
      25             : }
      26             : 
      27             : 
      28             : bool IsControlOpcode(IrOpcode::Value opcode) {
      29         737 :   switch (opcode) {
      30             : #define OPCODE(Opcode)      \
      31             :   case IrOpcode::k##Opcode: \
      32             :     return true;
      33             :     CONTROL_OP_LIST(OPCODE)
      34             : #undef OPCODE
      35             :     default:
      36             :       return false;
      37             :   }
      38             : }
      39             : 
      40             : 
      41             : bool IsJsOpcode(IrOpcode::Value opcode) {
      42         737 :   switch (opcode) {
      43             : #define OPCODE(Opcode)      \
      44             :   case IrOpcode::k##Opcode: \
      45             :     return true;
      46             :     JS_OP_LIST(OPCODE)
      47             : #undef OPCODE
      48             :     default:
      49             :       return false;
      50             :   }
      51             : }
      52             : 
      53             : 
      54             : bool IsConstantOpcode(IrOpcode::Value opcode) {
      55         737 :   switch (opcode) {
      56             : #define OPCODE(Opcode)      \
      57             :   case IrOpcode::k##Opcode: \
      58             :     return true;
      59             :     CONSTANT_OP_LIST(OPCODE)
      60             : #undef OPCODE
      61             :     default:
      62             :       return false;
      63             :   }
      64             : }
      65             : 
      66             : 
      67             : bool IsComparisonOpcode(IrOpcode::Value opcode) {
      68         737 :   switch (opcode) {
      69             : #define OPCODE(Opcode)      \
      70             :   case IrOpcode::k##Opcode: \
      71             :     return true;
      72             :     JS_COMPARE_BINOP_LIST(OPCODE)
      73             :     SIMPLIFIED_COMPARE_BINOP_LIST(OPCODE)
      74             :     MACHINE_COMPARE_BINOP_LIST(OPCODE)
      75             : #undef OPCODE
      76             :     default:
      77             :       return false;
      78             :   }
      79             : }
      80             : 
      81             : char const* const kMnemonics[] = {
      82             : #define OPCODE(Opcode) #Opcode,
      83             :     ALL_OP_LIST(OPCODE)
      84             : #undef OPCODE
      85             : };
      86             : 
      87             : const IrOpcode::Value kOpcodes[] = {
      88             : #define OPCODE(Opcode) IrOpcode::k##Opcode,
      89             :     ALL_OP_LIST(OPCODE)
      90             : #undef OPCODE
      91             : };
      92             : 
      93             : }  // namespace
      94             : 
      95       15443 : TEST(IrOpcodeTest, IsCommonOpcode) {
      96        2949 :   TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
      97        2211 :     EXPECT_EQ(IsCommonOpcode(opcode), IrOpcode::IsCommonOpcode(opcode));
      98             :   }
      99           1 : }
     100             : 
     101       15443 : TEST(IrOpcodeTest, IsControlOpcode) {
     102        2949 :   TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
     103        2211 :     EXPECT_EQ(IsControlOpcode(opcode), IrOpcode::IsControlOpcode(opcode));
     104             :   }
     105           1 : }
     106             : 
     107       15443 : TEST(IrOpcodeTest, IsJsOpcode) {
     108        2949 :   TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
     109        2211 :     EXPECT_EQ(IsJsOpcode(opcode), IrOpcode::IsJsOpcode(opcode));
     110             :   }
     111           1 : }
     112             : 
     113       15443 : TEST(IrOpcodeTest, IsConstantOpcode) {
     114        2949 :   TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
     115        2211 :     EXPECT_EQ(IsConstantOpcode(opcode), IrOpcode::IsConstantOpcode(opcode));
     116             :   }
     117           1 : }
     118             : 
     119       15443 : TEST(IrOpcodeTest, IsComparisonOpcode) {
     120        2949 :   TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
     121        2211 :     EXPECT_EQ(IsComparisonOpcode(opcode), IrOpcode::IsComparisonOpcode(opcode));
     122             :   }
     123           1 : }
     124             : 
     125       15443 : TEST(IrOpcodeTest, Mnemonic) {
     126        2949 :   TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
     127         737 :     EXPECT_STREQ(kMnemonics[opcode], IrOpcode::Mnemonic(opcode));
     128             :   }
     129           1 : }
     130             : 
     131             : }  // namespace compiler
     132             : }  // namespace internal
     133        9264 : }  // namespace v8

Generated by: LCOV version 1.10