Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: src/vm/interpreter_mips.cc

Issue 2006403003: [mips] Initial framework support for MIPS32 (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Minor update. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/shared/bytecodes.h"
8 #include "src/shared/names.h"
9 #include "src/shared/selectors.h"
10
11 #include "src/vm/assembler.h"
12 #include "src/vm/generator.h"
13 #include "src/vm/interpreter.h"
14 #include "src/vm/intrinsics.h"
15 #include "src/vm/object.h"
16 #include "src/vm/process.h"
17 #include "src/vm/program.h"
18
19 #define __ assembler()->
20
21 namespace dartino {
22
23 class InterpreterGenerator {
24 public:
25 explicit InterpreterGenerator(Assembler* assembler)
26 : assembler_(assembler) { }
27
28 void Generate();
29
30 virtual void GeneratePrologue() = 0;
31 virtual void GenerateEpilogue() = 0;
32
33 virtual void GenerateMethodEntry() = 0;
34
35 virtual void GenerateBytecodePrologue(const char* name) = 0;
36 virtual void GenerateDebugAtBytecode() = 0;
37
38 #define V(name, branching, format, size, stack_diff, print) \
39 virtual void Do##name() = 0;
40 BYTECODES_DO(V)
41 #undef V
42
43 #define V(name) virtual void DoIntrinsic##name() = 0;
44 INTRINSICS_DO(V)
45 #undef V
46
47 protected:
48 Assembler* assembler() const { return assembler_; }
49
50 private:
51 Assembler* const assembler_;
52 };
53
54 void InterpreterGenerator::Generate() {
55 GeneratePrologue();
56 GenerateEpilogue();
57
58 GenerateMethodEntry();
59
60 GenerateDebugAtBytecode();
61
62 #define V(name, branching, format, size, stack_diff, print) \
63 GenerateBytecodePrologue("BC_" #name); \
64 Do##name();
65 BYTECODES_DO(V)
66 #undef V
67
68 #define V(name) \
69 __ AlignToPowerOfTwo(3); \
70 __ Bind("", "Intrinsic_" #name); \
71 DoIntrinsic##name();
72 INTRINSICS_DO(V)
73 #undef V
74
75 #define V(name, branching, format, size, stack_diff, print) \
76 assembler()->DefineLong("BC_" #name);
77 BYTECODES_DO(V)
78 #undef V
79
80 __ SwitchToData();
81 __ BindWithPowerOfTwoAlignment("Interpret_DispatchTable", 4);
82 #define V(name, branching, format, size, stack_diff, print) \
83 assembler()->DefineLong("BC_" #name);
84 BYTECODES_DO(V)
85 #undef V
86 }
87
88 class InterpreterGeneratorMIPS: public InterpreterGenerator {
89 public:
90 explicit InterpreterGeneratorMIPS(Assembler* assembler)
91 : InterpreterGenerator(assembler) { }
92
93 virtual void GeneratePrologue();
94 virtual void GenerateEpilogue();
95
96 virtual void GenerateMethodEntry();
97
98 virtual void GenerateBytecodePrologue(const char* name);
99 virtual void GenerateDebugAtBytecode();
100
101 virtual void DoLoadLocal0();
102 virtual void DoLoadLocal1();
103 virtual void DoLoadLocal2();
104 virtual void DoLoadLocal3();
105 virtual void DoLoadLocal4();
106 virtual void DoLoadLocal5();
107 virtual void DoLoadLocal();
108 virtual void DoLoadLocalWide();
109
110 virtual void DoLoadBoxed();
111 virtual void DoLoadStatic();
112 virtual void DoLoadStaticInit();
113 virtual void DoLoadField();
114 virtual void DoLoadFieldWide();
115
116 virtual void DoLoadConst();
117
118 virtual void DoStoreLocal();
119 virtual void DoStoreBoxed();
120 virtual void DoStoreStatic();
121 virtual void DoStoreField();
122 virtual void DoStoreFieldWide();
123
124 virtual void DoLoadLiteralNull();
125 virtual void DoLoadLiteralTrue();
126 virtual void DoLoadLiteralFalse();
127 virtual void DoLoadLiteral0();
128 virtual void DoLoadLiteral1();
129 virtual void DoLoadLiteral();
130 virtual void DoLoadLiteralWide();
131
132 virtual void DoInvokeMethodUnfold();
133 virtual void DoInvokeMethod();
134
135 virtual void DoInvokeNoSuchMethod();
136 virtual void DoInvokeTestNoSuchMethod();
137
138 virtual void DoInvokeStatic();
139 virtual void DoInvokeFactory();
140
141 virtual void DoInvokeLeafNative();
142 virtual void DoInvokeNative();
143 virtual void DoInvokeNativeYield();
144
145 virtual void DoInvokeTestUnfold();
146 virtual void DoInvokeTest();
147
148 virtual void DoInvokeSelector();
149
150 #define INVOKE_BUILTIN(kind) \
151 virtual void DoInvoke##kind##Unfold() { \
152 Invoke##kind("BC_InvokeMethodUnfold"); \
153 } \
154 virtual void DoInvoke##kind() { Invoke##kind("BC_InvokeMethod"); }
155
156 INVOKE_BUILTIN(Eq);
157 INVOKE_BUILTIN(Lt);
158 INVOKE_BUILTIN(Le);
159 INVOKE_BUILTIN(Gt);
160 INVOKE_BUILTIN(Ge);
161
162 INVOKE_BUILTIN(Add);
163 INVOKE_BUILTIN(Sub);
164 INVOKE_BUILTIN(Mod);
165 INVOKE_BUILTIN(Mul);
166 INVOKE_BUILTIN(TruncDiv);
167
168 INVOKE_BUILTIN(BitNot);
169 INVOKE_BUILTIN(BitAnd);
170 INVOKE_BUILTIN(BitOr);
171 INVOKE_BUILTIN(BitXor);
172 INVOKE_BUILTIN(BitShr);
173 INVOKE_BUILTIN(BitShl);
174
175 #undef INVOKE_BUILTIN
176
177 virtual void DoPop();
178 virtual void DoDrop();
179 virtual void DoReturn();
180 virtual void DoReturnNull();
181
182 virtual void DoBranchWide();
183 virtual void DoBranchIfTrueWide();
184 virtual void DoBranchIfFalseWide();
185
186 virtual void DoBranchBack();
187 virtual void DoBranchBackIfTrue();
188 virtual void DoBranchBackIfFalse();
189
190 virtual void DoBranchBackWide();
191 virtual void DoBranchBackIfTrueWide();
192 virtual void DoBranchBackIfFalseWide();
193
194 virtual void DoPopAndBranchWide();
195 virtual void DoPopAndBranchBackWide();
196
197 virtual void DoAllocate();
198 virtual void DoAllocateImmutable();
199 virtual void DoAllocateBoxed();
200
201 virtual void DoNegate();
202
203 virtual void DoStackOverflowCheck();
204
205 virtual void DoThrow();
206 virtual void DoThrowAfterSaveState(Label* resume);
207 virtual void DoSubroutineCall();
208 virtual void DoSubroutineReturn();
209
210 virtual void DoProcessYield();
211 virtual void DoCoroutineChange();
212
213 virtual void DoIdentical();
214 virtual void DoIdenticalNonNumeric();
215
216 virtual void DoEnterNoSuchMethod();
217 virtual void DoExitNoSuchMethod();
218
219 virtual void DoMethodEnd();
220
221 virtual void DoIntrinsicObjectEquals();
222 virtual void DoIntrinsicGetField();
223 virtual void DoIntrinsicSetField();
224 virtual void DoIntrinsicListIndexGet();
225 virtual void DoIntrinsicListIndexSet();
226 virtual void DoIntrinsicListLength();
227
228 private:
229 Label done_;
230 Label done_state_saved_;
231 Label check_stack_overflow_;
232 Label check_stack_overflow_0_;
233 Label gc_;
234 Label intrinsic_failure_;
235 Label interpreter_entry_;
236 int spill_size_;
237
238 void LoadLocal(Register reg, int index);
239 void StoreLocal(Register reg, int index);
240
241 void Push(Register reg);
242 void Pop(Register reg);
243 void Drop(int n);
244 void Drop(Register reg);
245 void DropNAndSetTop(int dropping_slots, Register reg);
246
247 void LoadFramePointer(Register reg);
248 void StoreFramePointer(Register reg);
249
250 void SaveByteCodePointer(Register scratch);
251 void RestoreByteCodePointer(Register scratch);
252
253 void PushFrameDescriptor(Register return_address, Register scratch);
254 void ReadFrameDescriptor(Register scratch);
255
256 void Return(bool is_return_null);
257
258 void Allocate(bool immutable);
259
260 // This function trashes 'scratch'.
261 void AddToRememberedSet(Register object, Register value, Register scratch);
262
263 void InvokeEq(const char* fallback);
264 void InvokeLt(const char* fallback);
265 void InvokeLe(const char* fallback);
266 void InvokeGt(const char* fallback);
267 void InvokeGe(const char* fallback);
268 void InvokeCompare(const char* fallback, Condition condition);
269
270 void InvokeAdd(const char* fallback);
271 void InvokeSub(const char* fallback);
272 void InvokeMod(const char* fallback);
273 void InvokeMul(const char* fallback);
274 void InvokeTruncDiv(const char* fallback);
275
276 void InvokeBitNot(const char* fallback);
277 void InvokeBitAnd(const char* fallback);
278 void InvokeBitOr(const char* fallback);
279 void InvokeBitXor(const char* fallback);
280 void InvokeBitShr(const char* fallback);
281 void InvokeBitShl(const char* fallback);
282
283 void InvokeMethodUnfold(bool test);
284 void InvokeMethod(bool test);
285
286 void InvokeNative(bool yield, bool safepoint);
287 void InvokeStatic();
288
289 void ConditionalStore(Register cmp, Register reg_if_eq, Register reg_if_ne,
290 const Address& address);
291
292 void CheckStackOverflow(int size);
293
294 void Dispatch(int size);
295
296 void SaveState(Label* resume);
297 void RestoreState();
298
299 static int ComputeStackPadding(int reserved, int extra) {
300 const int kAlignment = 8;
301 int rounded = (reserved + extra + kAlignment - 1) & ~(kAlignment - 1);
302 return rounded - reserved;
303 }
304 };
305
306 GENERATE(, Interpret) {
307 InterpreterGeneratorMIPS generator(assembler);
308 generator.Generate();
309 }
310
311 void InterpreterGeneratorMIPS::GeneratePrologue() {
312 }
313
314 void InterpreterGeneratorMIPS::GenerateEpilogue() {
315 // Default entrypoint.
316 __ Bind("", "InterpreterEntry");
317 __ Bind(&interpreter_entry_);
318 Dispatch(0);
319
320 /* ... */
321 }
322
323 void InterpreterGeneratorMIPS::GenerateMethodEntry() {
324 __ SwitchToText();
325 __ AlignToPowerOfTwo(3);
326 __ Bind("", "InterpreterMethodEntry");
327
328 /* ... */
329 }
330
331 void InterpreterGeneratorMIPS::GenerateBytecodePrologue(const char* name) {
332 __ SwitchToText();
333 __ AlignToPowerOfTwo(3);
334 __ nop();
335 __ nop();
336 __ nop();
337 __ nop();
338 __ nop();
339 __ Bind("Debug_", name);
340 __ la(T9, "DebugAtBytecode");
341 __ jalr(T9);
342 __ nop();
343 __ AlignToPowerOfTwo(3);
344 __ Bind("", name);
345 }
346
347 void InterpreterGeneratorMIPS::GenerateDebugAtBytecode() {
348 __ SwitchToText();
349 __ AlignToPowerOfTwo(4); // align to 8-byte storage boundary.
Søren Gjesse 2016/05/26 13:00:19 Nit: start comment with upper case letter.
petarj 2016/05/26 14:35:55 Done.
350 __ Bind("", "DebugAtBytecode");
351 }
352
353 void InterpreterGeneratorMIPS::DoLoadLocal0() {
354 }
355
356 void InterpreterGeneratorMIPS::DoLoadLocal1() {
357 }
358
359 void InterpreterGeneratorMIPS::DoLoadLocal2() {
360 }
361
362 void InterpreterGeneratorMIPS::DoLoadLocal3() {
363 }
364
365 void InterpreterGeneratorMIPS::DoLoadLocal4() {
366 }
367
368 void InterpreterGeneratorMIPS::DoLoadLocal5() {
369 }
370
371 void InterpreterGeneratorMIPS::DoLoadLocal() {
372 }
373
374 void InterpreterGeneratorMIPS::DoLoadLocalWide() {
375 }
376
377 void InterpreterGeneratorMIPS::DoLoadBoxed() {
378 }
379
380 void InterpreterGeneratorMIPS::DoLoadStatic() {
381 }
382
383 void InterpreterGeneratorMIPS::DoLoadStaticInit() {
384 }
385
386 void InterpreterGeneratorMIPS::DoLoadField() {
387 }
388
389 void InterpreterGeneratorMIPS::DoLoadFieldWide() {
390 }
391
392 void InterpreterGeneratorMIPS::DoLoadConst() {
393 }
394
395 void InterpreterGeneratorMIPS::DoStoreLocal() {
396 }
397
398 void InterpreterGeneratorMIPS::DoStoreBoxed() {
399 }
400
401 void InterpreterGeneratorMIPS::DoStoreStatic() {
402 }
403
404 void InterpreterGeneratorMIPS::DoStoreField() {
405 }
406
407 void InterpreterGeneratorMIPS::DoStoreFieldWide() {
408 }
409
410 void InterpreterGeneratorMIPS::DoLoadLiteralNull() {
411 }
412
413 void InterpreterGeneratorMIPS::DoLoadLiteralTrue() {
414 }
415
416 void InterpreterGeneratorMIPS::DoLoadLiteralFalse() {
417 }
418
419 void InterpreterGeneratorMIPS::DoLoadLiteral0() {
420 }
421
422 void InterpreterGeneratorMIPS::DoLoadLiteral1() {
423 }
424
425 void InterpreterGeneratorMIPS::DoLoadLiteral() {
426 }
427
428 void InterpreterGeneratorMIPS::DoLoadLiteralWide() {
429 }
430
431 void InterpreterGeneratorMIPS::DoInvokeMethodUnfold() {
432 }
433
434 void InterpreterGeneratorMIPS::DoInvokeMethod() {
435 }
436
437 void InterpreterGeneratorMIPS::DoInvokeNoSuchMethod() {
438 }
439
440 void InterpreterGeneratorMIPS::DoInvokeTestNoSuchMethod() {
441 }
442
443 void InterpreterGeneratorMIPS::DoInvokeTestUnfold() {
444 }
445
446 void InterpreterGeneratorMIPS::DoInvokeTest() {
447 }
448
449 void InterpreterGeneratorMIPS::DoInvokeStatic() {
450 }
451
452 void InterpreterGeneratorMIPS::DoInvokeFactory() {
453 }
454
455 void InterpreterGeneratorMIPS::DoInvokeLeafNative() {
456 }
457
458 void InterpreterGeneratorMIPS::DoInvokeNative() {
459 }
460
461 void InterpreterGeneratorMIPS::DoInvokeNativeYield() {
462 }
463
464 void InterpreterGeneratorMIPS::DoInvokeSelector() {
465 }
466
467 void InterpreterGeneratorMIPS::InvokeEq(const char* fallback) {
468 }
469
470 void InterpreterGeneratorMIPS::InvokeLt(const char* fallback) {
471 }
472
473 void InterpreterGeneratorMIPS::InvokeLe(const char* fallback) {
474 }
475
476 void InterpreterGeneratorMIPS::InvokeGt(const char* fallback) {
477 }
478
479 void InterpreterGeneratorMIPS::InvokeGe(const char* fallback) {
480 }
481
482 void InterpreterGeneratorMIPS::InvokeAdd(const char* fallback) {
483 }
484
485 void InterpreterGeneratorMIPS::InvokeSub(const char* fallback) {
486 }
487
488 void InterpreterGeneratorMIPS::InvokeMod(const char* fallback) {
489 }
490
491 void InterpreterGeneratorMIPS::InvokeMul(const char* fallback) {
492 }
493
494 void InterpreterGeneratorMIPS::InvokeTruncDiv(const char* fallback) {
495 }
496
497 void InterpreterGeneratorMIPS::InvokeBitNot(const char* fallback) {
498 }
499
500 void InterpreterGeneratorMIPS::InvokeBitAnd(const char* fallback) {
501 }
502
503 void InterpreterGeneratorMIPS::InvokeBitOr(const char* fallback) {
504 }
505
506 void InterpreterGeneratorMIPS::InvokeBitXor(const char* fallback) {
507 }
508
509 void InterpreterGeneratorMIPS::InvokeBitShr(const char* fallback) {
510 }
511
512 void InterpreterGeneratorMIPS::InvokeBitShl(const char* fallback) {
513 }
514
515 void InterpreterGeneratorMIPS::DoPop() {
516 }
517
518 void InterpreterGeneratorMIPS::DoDrop() {
519 }
520
521 void InterpreterGeneratorMIPS::DoReturn() {
522 }
523
524 void InterpreterGeneratorMIPS::DoReturnNull() {
525 }
526
527 void InterpreterGeneratorMIPS::DoBranchWide() {
528 }
529
530 void InterpreterGeneratorMIPS::DoBranchIfTrueWide() {
531 }
532
533 void InterpreterGeneratorMIPS::DoBranchIfFalseWide() {
534 }
535
536 void InterpreterGeneratorMIPS::DoBranchBack() {
537 }
538
539 void InterpreterGeneratorMIPS::DoBranchBackIfTrue() {
540 }
541
542 void InterpreterGeneratorMIPS::DoBranchBackIfFalse() {
543 }
544
545 void InterpreterGeneratorMIPS::DoBranchBackWide() {
546 }
547
548 void InterpreterGeneratorMIPS::DoBranchBackIfTrueWide() {
549 }
550
551 void InterpreterGeneratorMIPS::DoBranchBackIfFalseWide() {
552 }
553
554 void InterpreterGeneratorMIPS::DoPopAndBranchWide() {
555 }
556
557 void InterpreterGeneratorMIPS::DoPopAndBranchBackWide() {
558 }
559
560 void InterpreterGeneratorMIPS::DoAllocate() {
561 }
562
563 void InterpreterGeneratorMIPS::DoAllocateImmutable() {
564 }
565
566 void InterpreterGeneratorMIPS::DoAllocateBoxed() {
567 }
568
569 void InterpreterGeneratorMIPS::DoNegate() {
570 }
571
572 void InterpreterGeneratorMIPS::DoStackOverflowCheck() {
573 }
574
575 void InterpreterGeneratorMIPS::DoThrowAfterSaveState(Label* resume) {
576 }
577
578 void InterpreterGeneratorMIPS::DoThrow() {
579 }
580
581 void InterpreterGeneratorMIPS::DoSubroutineCall() {
582 }
583
584 void InterpreterGeneratorMIPS::DoSubroutineReturn() {
585 }
586
587 void InterpreterGeneratorMIPS::DoProcessYield() {
588 }
589
590 void InterpreterGeneratorMIPS::DoCoroutineChange() {
591 }
592
593 void InterpreterGeneratorMIPS::DoIdentical() {
594 }
595
596 void InterpreterGeneratorMIPS::DoIdenticalNonNumeric() {
597 }
598
599 void InterpreterGeneratorMIPS::DoEnterNoSuchMethod() {
600 }
601
602 void InterpreterGeneratorMIPS::DoExitNoSuchMethod() {
603 }
604
605 void InterpreterGeneratorMIPS::DoMethodEnd() {
606 }
607
608 void InterpreterGeneratorMIPS::DoIntrinsicObjectEquals() {
609 }
610
611 void InterpreterGeneratorMIPS::DoIntrinsicGetField() {
612 }
613
614 void InterpreterGeneratorMIPS::DoIntrinsicSetField() {
615 }
616
617 void InterpreterGeneratorMIPS::DoIntrinsicListIndexGet() {
618 }
619
620 void InterpreterGeneratorMIPS::DoIntrinsicListIndexSet() {
621 }
622
623 void InterpreterGeneratorMIPS::DoIntrinsicListLength() {
624 }
625
626 void InterpreterGeneratorMIPS::Push(Register reg) {
627 }
628
629 void InterpreterGeneratorMIPS::Return(bool is_return_null) {
630 }
631
632 void InterpreterGeneratorMIPS::LoadLocal(Register reg, int index) {
633 }
634
635 void InterpreterGeneratorMIPS::StoreLocal(Register reg, int index) {
636 }
637
638 void InterpreterGeneratorMIPS::Drop(int n) {
639 }
640
641 void InterpreterGeneratorMIPS::Drop(Register reg) {
642 }
643
644 void InterpreterGeneratorMIPS::DropNAndSetTop(int dropping_slots,
645 Register reg) {
646 }
647
648 void InterpreterGeneratorMIPS::LoadFramePointer(Register reg) {
649 }
650
651 void InterpreterGeneratorMIPS::StoreFramePointer(Register reg) {
652 }
653
654 void InterpreterGeneratorMIPS::SaveByteCodePointer(Register scratch) {
655 }
656
657 void InterpreterGeneratorMIPS::RestoreByteCodePointer(Register scratch) {
658 }
659
660 void InterpreterGeneratorMIPS::PushFrameDescriptor(Register return_address,
661 Register scratch) {
662 }
663
664 void InterpreterGeneratorMIPS::ReadFrameDescriptor(Register scratch) {
665 }
666
667 void InterpreterGeneratorMIPS::InvokeMethodUnfold(bool test) {
668 }
669
670 void InterpreterGeneratorMIPS::InvokeMethod(bool test) {
671 }
672
673 void InterpreterGeneratorMIPS::InvokeNative(bool yield, bool safepoint) {
674 }
675
676 void InterpreterGeneratorMIPS::InvokeStatic() {
677 }
678
679 void InterpreterGeneratorMIPS::Allocate(bool immutable) {
680 }
681
682 void InterpreterGeneratorMIPS::AddToRememberedSet(Register object,
683 Register value,
684 Register scratch) {
685 }
686
687 void InterpreterGeneratorMIPS::InvokeCompare(const char* fallback,
688 Condition cond) {
689 }
690
691 void InterpreterGeneratorMIPS::ConditionalStore(Register cmp,
692 Register reg_if_eq,
693 Register reg_if_ne,
694 const Address& address) {
695 }
696
697 void InterpreterGeneratorMIPS::CheckStackOverflow(int size) {
698 }
699
700 void InterpreterGeneratorMIPS::Dispatch(int size) {
701 }
702
703 void InterpreterGeneratorMIPS::SaveState(Label* resume) {
704 }
705
706 void InterpreterGeneratorMIPS::RestoreState() {
707 }
708 } // namespace dartino
709 #endif // defined DARTINO_TARGET_MIPS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698