| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #if defined(FLETCH_TARGET_ARM) | 5 #if defined(DARTINO_TARGET_ARM) |
| 6 | 6 |
| 7 #include "src/shared/bytecodes.h" | 7 #include "src/shared/bytecodes.h" |
| 8 #include "src/shared/names.h" | 8 #include "src/shared/names.h" |
| 9 #include "src/shared/selectors.h" | 9 #include "src/shared/selectors.h" |
| 10 | 10 |
| 11 #include "src/vm/assembler.h" | 11 #include "src/vm/assembler.h" |
| 12 #include "src/vm/generator.h" | 12 #include "src/vm/generator.h" |
| 13 #include "src/vm/interpreter.h" | 13 #include "src/vm/interpreter.h" |
| 14 #include "src/vm/intrinsics.h" | 14 #include "src/vm/intrinsics.h" |
| 15 #include "src/vm/object.h" | 15 #include "src/vm/object.h" |
| 16 #include "src/vm/process.h" | 16 #include "src/vm/process.h" |
| 17 #include "src/vm/program.h" | 17 #include "src/vm/program.h" |
| 18 | 18 |
| 19 #define __ assembler()-> | 19 #define __ assembler()-> |
| 20 | 20 |
| 21 namespace fletch { | 21 namespace dartino { |
| 22 | 22 |
| 23 class InterpreterGenerator { | 23 class InterpreterGenerator { |
| 24 public: | 24 public: |
| 25 explicit InterpreterGenerator(Assembler* assembler) : assembler_(assembler) {} | 25 explicit InterpreterGenerator(Assembler* assembler) : assembler_(assembler) {} |
| 26 | 26 |
| 27 void Generate(); | 27 void Generate(); |
| 28 | 28 |
| 29 virtual void GeneratePrologue() = 0; | 29 virtual void GeneratePrologue() = 0; |
| 30 virtual void GenerateEpilogue() = 0; | 30 virtual void GenerateEpilogue() = 0; |
| 31 | 31 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 Push(R2); | 423 Push(R2); |
| 424 __ add(R5, R0, Immediate(Function::kSize - HeapObject::kTag)); | 424 __ add(R5, R0, Immediate(Function::kSize - HeapObject::kTag)); |
| 425 CheckStackOverflow(0); | 425 CheckStackOverflow(0); |
| 426 Dispatch(0); | 426 Dispatch(0); |
| 427 } | 427 } |
| 428 | 428 |
| 429 void InterpreterGeneratorARM::GenerateBytecodePrologue(const char* name) { | 429 void InterpreterGeneratorARM::GenerateBytecodePrologue(const char* name) { |
| 430 __ SwitchToText(); | 430 __ SwitchToText(); |
| 431 __ AlignToPowerOfTwo(3); | 431 __ AlignToPowerOfTwo(3); |
| 432 __ nop(); | 432 __ nop(); |
| 433 #ifdef FLETCH_THUMB_ONLY | 433 #ifdef DARTINO_THUMB_ONLY |
| 434 // Thumb is has 16-bit nop's, not 32-bit. | 434 // Thumb is has 16-bit nop's, not 32-bit. |
| 435 __ nop(); | 435 __ nop(); |
| 436 #endif | 436 #endif |
| 437 __ Bind("Debug_", name); | 437 __ Bind("Debug_", name); |
| 438 __ bl("DebugAtBytecode"); | 438 __ bl("DebugAtBytecode"); |
| 439 __ AlignToPowerOfTwo(3); | 439 __ AlignToPowerOfTwo(3); |
| 440 __ Bind("", name); | 440 __ Bind("", name); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void InterpreterGeneratorARM::GenerateDebugAtBytecode() { | 443 void InterpreterGeneratorARM::GenerateDebugAtBytecode() { |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 void InterpreterGeneratorARM::DoIntrinsicListLength() { | 1394 void InterpreterGeneratorARM::DoIntrinsicListLength() { |
| 1395 // Load the backing store (array) from the first instance field of the list. | 1395 // Load the backing store (array) from the first instance field of the list. |
| 1396 LoadLocal(R2, 0); // List. | 1396 LoadLocal(R2, 0); // List. |
| 1397 __ ldr(R2, Address(R2, Instance::kSize - HeapObject::kTag)); | 1397 __ ldr(R2, Address(R2, Instance::kSize - HeapObject::kTag)); |
| 1398 __ ldr(R0, Address(R2, Array::kLengthOffset - HeapObject::kTag)); | 1398 __ ldr(R0, Address(R2, Array::kLengthOffset - HeapObject::kTag)); |
| 1399 | 1399 |
| 1400 __ mov(PC, LR); | 1400 __ mov(PC, LR); |
| 1401 } | 1401 } |
| 1402 | 1402 |
| 1403 void InterpreterGeneratorARM::Push(Register reg) { | 1403 void InterpreterGeneratorARM::Push(Register reg) { |
| 1404 #ifdef FLETCH_THUMB_ONLY | 1404 #ifdef DARTINO_THUMB_ONLY |
| 1405 StoreLocal(reg, -1); | 1405 StoreLocal(reg, -1); |
| 1406 __ sub(R6, R6, Immediate(1 * kWordSize)); | 1406 __ sub(R6, R6, Immediate(1 * kWordSize)); |
| 1407 #else | 1407 #else |
| 1408 __ str(reg, Address(R6, -1 * kWordSize), WRITE_BACK); | 1408 __ str(reg, Address(R6, -1 * kWordSize), WRITE_BACK); |
| 1409 #endif | 1409 #endif |
| 1410 } | 1410 } |
| 1411 | 1411 |
| 1412 void InterpreterGeneratorARM::Pop(Register reg) { | 1412 void InterpreterGeneratorARM::Pop(Register reg) { |
| 1413 #ifdef FLETCH_THUMB_ONLY | 1413 #ifdef DARTINO_THUMB_ONLY |
| 1414 LoadLocal(reg, 0); | 1414 LoadLocal(reg, 0); |
| 1415 Drop(1); | 1415 Drop(1); |
| 1416 #else | 1416 #else |
| 1417 __ ldr(reg, R6, Immediate(kWordSize)); | 1417 __ ldr(reg, R6, Immediate(kWordSize)); |
| 1418 #endif | 1418 #endif |
| 1419 } | 1419 } |
| 1420 | 1420 |
| 1421 void InterpreterGeneratorARM::Return(bool is_return_null) { | 1421 void InterpreterGeneratorARM::Return(bool is_return_null) { |
| 1422 // Materialize the result in register R0. | 1422 // Materialize the result in register R0. |
| 1423 if (is_return_null) { | 1423 if (is_return_null) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1445 | 1445 |
| 1446 void InterpreterGeneratorARM::Drop(int n) { | 1446 void InterpreterGeneratorARM::Drop(int n) { |
| 1447 __ add(R6, R6, Immediate(n * kWordSize)); | 1447 __ add(R6, R6, Immediate(n * kWordSize)); |
| 1448 } | 1448 } |
| 1449 | 1449 |
| 1450 void InterpreterGeneratorARM::Drop(Register reg) { | 1450 void InterpreterGeneratorARM::Drop(Register reg) { |
| 1451 __ add(R6, R6, Operand(reg, TIMES_WORD_SIZE)); | 1451 __ add(R6, R6, Operand(reg, TIMES_WORD_SIZE)); |
| 1452 } | 1452 } |
| 1453 | 1453 |
| 1454 void InterpreterGeneratorARM::DropNAndSetTop(int dropping_slots, Register reg) { | 1454 void InterpreterGeneratorARM::DropNAndSetTop(int dropping_slots, Register reg) { |
| 1455 #ifdef FLETCH_THUMB_ONLY | 1455 #ifdef DARTINO_THUMB_ONLY |
| 1456 Drop(dropping_slots); | 1456 Drop(dropping_slots); |
| 1457 StoreLocal(reg, 0); | 1457 StoreLocal(reg, 0); |
| 1458 #else | 1458 #else |
| 1459 __ str(reg, Address(R6, dropping_slots * kWordSize), WRITE_BACK); | 1459 __ str(reg, Address(R6, dropping_slots * kWordSize), WRITE_BACK); |
| 1460 #endif | 1460 #endif |
| 1461 } | 1461 } |
| 1462 | 1462 |
| 1463 void InterpreterGeneratorARM::LoadFramePointer(Register reg) { | 1463 void InterpreterGeneratorARM::LoadFramePointer(Register reg) { |
| 1464 __ ldr(reg, Address(SP, spill_size_)); | 1464 __ ldr(reg, Address(SP, spill_size_)); |
| 1465 } | 1465 } |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1915 // Compute the address of the first and last instance field. | 1915 // Compute the address of the first and last instance field. |
| 1916 __ sub(R7, R0, Immediate(kWordSize + HeapObject::kTag)); | 1916 __ sub(R7, R0, Immediate(kWordSize + HeapObject::kTag)); |
| 1917 __ add(R7, R7, R2); | 1917 __ add(R7, R7, R2); |
| 1918 __ add(R9, R0, Immediate(Instance::kSize - HeapObject::kTag)); | 1918 __ add(R9, R0, Immediate(Instance::kSize - HeapObject::kTag)); |
| 1919 | 1919 |
| 1920 Label loop, done; | 1920 Label loop, done; |
| 1921 __ Bind(&loop); | 1921 __ Bind(&loop); |
| 1922 __ cmp(R9, R7); | 1922 __ cmp(R9, R7); |
| 1923 __ b(HI, &done); | 1923 __ b(HI, &done); |
| 1924 Pop(R1); | 1924 Pop(R1); |
| 1925 #ifdef FLETCH_THUMB_ONLY | 1925 #ifdef DARTINO_THUMB_ONLY |
| 1926 __ str(R1, Address(R7, 0)); | 1926 __ str(R1, Address(R7, 0)); |
| 1927 __ sub(R7, R7, Immediate(1 * kWordSize)); | 1927 __ sub(R7, R7, Immediate(1 * kWordSize)); |
| 1928 #else | 1928 #else |
| 1929 __ str(R1, R7, Immediate(-1 * kWordSize)); | 1929 __ str(R1, R7, Immediate(-1 * kWordSize)); |
| 1930 #endif | 1930 #endif |
| 1931 __ b(&loop); | 1931 __ b(&loop); |
| 1932 | 1932 |
| 1933 __ Bind(&done); | 1933 __ Bind(&done); |
| 1934 Push(R0); | 1934 Push(R0); |
| 1935 Dispatch(kAllocateLength); | 1935 Dispatch(kAllocateLength); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 Label done; | 1982 Label done; |
| 1983 __ b(HI, &done); | 1983 __ b(HI, &done); |
| 1984 __ mov(R0, Immediate(size)); | 1984 __ mov(R0, Immediate(size)); |
| 1985 __ b(&check_stack_overflow_); | 1985 __ b(&check_stack_overflow_); |
| 1986 __ Bind(&done); | 1986 __ Bind(&done); |
| 1987 } | 1987 } |
| 1988 } | 1988 } |
| 1989 | 1989 |
| 1990 void InterpreterGeneratorARM::Dispatch(int size) { | 1990 void InterpreterGeneratorARM::Dispatch(int size) { |
| 1991 // Load the next bytecode through R5 and dispatch to it. | 1991 // Load the next bytecode through R5 and dispatch to it. |
| 1992 #ifdef FLETCH_THUMB_ONLY | 1992 #ifdef DARTINO_THUMB_ONLY |
| 1993 __ ldrb(R7, Address(R5, size)); | 1993 __ ldrb(R7, Address(R5, size)); |
| 1994 if (size > 0) { | 1994 if (size > 0) { |
| 1995 __ add(R5, R5, Immediate(size)); | 1995 __ add(R5, R5, Immediate(size)); |
| 1996 } | 1996 } |
| 1997 #else | 1997 #else |
| 1998 __ ldrb(R7, Address(R5, size), WRITE_BACK); | 1998 __ ldrb(R7, Address(R5, size), WRITE_BACK); |
| 1999 #endif | 1999 #endif |
| 2000 __ ldr(R9, "Interpret_DispatchTable"); | 2000 __ ldr(R9, "Interpret_DispatchTable"); |
| 2001 __ ldr(PC, Address(R9, Operand(R7, TIMES_WORD_SIZE))); | 2001 __ ldr(PC, Address(R9, Operand(R7, TIMES_WORD_SIZE))); |
| 2002 __ GenerateConstantPool(); | 2002 __ GenerateConstantPool(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 StoreFramePointer(R5); | 2042 StoreFramePointer(R5); |
| 2043 | 2043 |
| 2044 // Set the bytecode pointer from the stack. | 2044 // Set the bytecode pointer from the stack. |
| 2045 __ ldr(R5, Address(R5, -kWordSize)); | 2045 __ ldr(R5, Address(R5, -kWordSize)); |
| 2046 | 2046 |
| 2047 // Pop and branch to resume address. | 2047 // Pop and branch to resume address. |
| 2048 Pop(LR); | 2048 Pop(LR); |
| 2049 __ mov(PC, LR); | 2049 __ mov(PC, LR); |
| 2050 } | 2050 } |
| 2051 | 2051 |
| 2052 } // namespace fletch | 2052 } // namespace dartino |
| 2053 | 2053 |
| 2054 #endif // defined(FLETCH_TARGET_ARM) | 2054 #endif // defined(DARTINO_TARGET_ARM) |
| OLD | NEW |