constants-mips.cc 3.91 KB
Newer Older
1
// Copyright 2011 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5
#if V8_TARGET_ARCH_MIPS
6

7
#include "src/codegen/mips/constants-mips.h"
8

9 10
namespace v8 {
namespace internal {
11 12

// -----------------------------------------------------------------------------
13
// Registers.
14 15 16 17

// These register names are defined in a way to match the native disassembler
// formatting. See for example the command "objdump -d <binary file>".
const char* Registers::names_[kNumSimuRegisters] = {
18 19 20 21
    "zero_reg", "at", "v0", "v1", "a0", "a1", "a2", "a3", "t0",
    "t1",       "t2", "t3", "t4", "t5", "t6", "t7", "s0", "s1",
    "s2",       "s3", "s4", "s5", "s6", "s7", "t8", "t9", "k0",
    "k1",       "gp", "sp", "fp", "ra", "LO", "HI", "pc"};
22

23 24
// List of alias names which can be used when referring to MIPS registers.
const Registers::RegisterAlias Registers::aliases_[] = {
25 26 27 28 29
    {0, "zero"},
    {23, "cp"},
    {30, "s8"},
    {30, "s8_fp"},
    {kInvalidRegister, nullptr}};
30

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
const char* Registers::Name(int reg) {
  const char* result;
  if ((0 <= reg) && (reg < kNumSimuRegisters)) {
    result = names_[reg];
  } else {
    result = "noreg";
  }
  return result;
}

int Registers::Number(const char* name) {
  // Look through the canonical names.
  for (int i = 0; i < kNumSimuRegisters; i++) {
    if (strcmp(names_[i], name) == 0) {
      return i;
    }
  }

  // Look through the alias names.
  int i = 0;
  while (aliases_[i].reg != kInvalidRegister) {
    if (strcmp(aliases_[i].name, name) == 0) {
      return aliases_[i].reg;
    }
    i++;
  }

  // No register with the reguested name found.
  return kInvalidRegister;
}

62
const char* FPURegisters::names_[kNumFPURegisters] = {
63 64 65
    "f0",  "f1",  "f2",  "f3",  "f4",  "f5",  "f6",  "f7",  "f8",  "f9",  "f10",
    "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", "f20", "f21",
    "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"};
66

67
// List of alias names which can be used when referring to MIPS registers.
68
const FPURegisters::RegisterAlias FPURegisters::aliases_[] = {
69
    {kInvalidRegister, nullptr}};
70

71
const char* FPURegisters::Name(int creg) {
72
  const char* result;
73
  if ((0 <= creg) && (creg < kNumFPURegisters)) {
74 75 76 77 78 79 80
    result = names_[creg];
  } else {
    result = "nocreg";
  }
  return result;
}

81
int FPURegisters::Number(const char* name) {
82
  // Look through the canonical names.
83
  for (int i = 0; i < kNumFPURegisters; i++) {
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    if (strcmp(names_[i], name) == 0) {
      return i;
    }
  }

  // Look through the alias names.
  int i = 0;
  while (aliases_[i].creg != kInvalidRegister) {
    if (strcmp(aliases_[i].name, name) == 0) {
      return aliases_[i].creg;
    }
    i++;
  }

  // No Cregister with the reguested name found.
  return kInvalidFPURegister;
}

102 103 104 105 106 107
const char* MSARegisters::names_[kNumMSARegisters] = {
    "w0",  "w1",  "w2",  "w3",  "w4",  "w5",  "w6",  "w7",  "w8",  "w9",  "w10",
    "w11", "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21",
    "w22", "w23", "w24", "w25", "w26", "w27", "w28", "w29", "w30", "w31"};

const MSARegisters::RegisterAlias MSARegisters::aliases_[] = {
108
    {kInvalidRegister, nullptr}};
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

const char* MSARegisters::Name(int creg) {
  const char* result;
  if ((0 <= creg) && (creg < kNumMSARegisters)) {
    result = names_[creg];
  } else {
    result = "nocreg";
  }
  return result;
}

int MSARegisters::Number(const char* name) {
  // Look through the canonical names.
  for (int i = 0; i < kNumMSARegisters; i++) {
    if (strcmp(names_[i], name) == 0) {
      return i;
    }
  }

  // Look through the alias names.
  int i = 0;
  while (aliases_[i].creg != kInvalidRegister) {
    if (strcmp(aliases_[i].name, name) == 0) {
      return aliases_[i].creg;
    }
    i++;
  }

  // No Cregister with the reguested name found.
  return kInvalidMSARegister;
}
140

141 142
}  // namespace internal
}  // namespace v8
143 144

#endif  // V8_TARGET_ARCH_MIPS