OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dartino project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 |
| 5 #if defined(DARTINO_TARGET_MIPS) |
| 6 |
| 7 #include "src/vm/assembler.h" // NOLINT we don't include assembler_mips.h. |
| 8 |
| 9 #include <stdio.h> |
| 10 #include <stdarg.h> |
| 11 |
| 12 namespace dartino { |
| 13 |
| 14 int Label::position_counter_ = 0; |
| 15 |
| 16 static const char* ConditionToString(Condition cond) { |
| 17 static const char* kConditionNames[] = { "f", "t", "un", "or", "eq", |
| 18 "ne", "ueq", "olg", "olt", "uge", |
| 19 "ult", "oge", "ole", "ugt", "ule", |
| 20 "ogt", "sf", "st", "ngle", "gle", |
| 21 "seq", "sne", "ngl", "gl", "lt", |
| 22 "nlt", "nge", "ge", "le", "nle", |
| 23 "ngt", "gt"}; |
| 24 return kConditionNames[cond]; |
| 25 } |
| 26 |
| 27 void Assembler::BindWithPowerOfTwoAlignment(const char* name, int power) { |
| 28 AlignToPowerOfTwo(power); |
| 29 printf("\t.globl %s%s\n%s%s:\n", LabelPrefix(), name, LabelPrefix(), name); |
| 30 } |
| 31 |
| 32 void Assembler::AlignToPowerOfTwo(int power) { |
| 33 printf("\t.align %d\n", power); |
| 34 } |
| 35 |
| 36 void Assembler::Bind(Label* label) { |
| 37 printf(".L%d:\n", label->position()); |
| 38 } |
| 39 |
| 40 void Assembler::SwitchToText() { |
| 41 puts("\n\t.text"); |
| 42 } |
| 43 |
| 44 void Assembler::SwitchToData() { |
| 45 puts("\n\t.data"); |
| 46 } |
| 47 |
| 48 static const char* ToString(Register reg) { |
| 49 static const char* kRegisterNames[] = {"zero", "at", "v0", "v1", "a0", "a1", |
| 50 "a2", "a3", "t0", "t1", "t2", "t3", |
| 51 "t4", "t5", "t6", "t7", "s0", "s1", |
| 52 "s2", "s3", "s4", "s5", "s6", "s7", |
| 53 "t8", "t9", "k0", "k1", "gp", "sp", |
| 54 "fp", "ra"}; |
| 55 ASSERT(reg >= ZR && reg <= RA); |
| 56 return kRegisterNames[reg]; |
| 57 } |
| 58 |
| 59 void Assembler::Print(const char* format, ...) { |
| 60 printf("\t"); |
| 61 va_list arguments; |
| 62 va_start(arguments, format); |
| 63 while (*format != '\0') { |
| 64 if (*format == '%') { |
| 65 format++; |
| 66 switch (*format) { |
| 67 case '%': { |
| 68 putchar('%'); |
| 69 break; |
| 70 } |
| 71 |
| 72 case 'a': { |
| 73 const Address* address = va_arg(arguments, const Address*); |
| 74 PrintAddress(address); |
| 75 break; |
| 76 } |
| 77 |
| 78 case 'c': { |
| 79 Condition condition = static_cast<Condition>(va_arg(arguments, int)); |
| 80 printf("%s", ConditionToString(condition)); |
| 81 break; |
| 82 } |
| 83 |
| 84 case 'l': { |
| 85 Label* label = va_arg(arguments, Label*); |
| 86 printf(".L%d", label->position()); |
| 87 break; |
| 88 } |
| 89 |
| 90 case 'r': { |
| 91 Register reg = static_cast<Register>(va_arg(arguments, int)); |
| 92 printf("$%s", ToString(reg)); |
| 93 break; |
| 94 } |
| 95 |
| 96 case 'i': { |
| 97 const Immediate* immediate = va_arg(arguments, const Immediate*); |
| 98 printf("%d", immediate->value()); |
| 99 break; |
| 100 } |
| 101 |
| 102 case 's': { |
| 103 const char* label = va_arg(arguments, const char*); |
| 104 printf("%s%s", LabelPrefix(), label); |
| 105 break; |
| 106 } |
| 107 |
| 108 default: { |
| 109 UNREACHABLE(); |
| 110 break; |
| 111 } |
| 112 } |
| 113 } else { |
| 114 putchar(*format); |
| 115 } |
| 116 format++; |
| 117 } |
| 118 va_end(arguments); |
| 119 putchar('\n'); |
| 120 } |
| 121 |
| 122 void Assembler::PrintAddress(const Address* address) { |
| 123 printf("%d($%s)", address->offset(), ToString(address->base())); |
| 124 } |
| 125 |
| 126 } // namespace dartino |
| 127 |
| 128 #endif // defined(DARTINO_TARGET_MIPS) |
OLD | NEW |