This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterpreterThread_ControlFlowInstructions.cpp
126 lines (102 loc) · 3.43 KB
/
InterpreterThread_ControlFlowInstructions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Interpreter_ControlFlowInstructions.cpp
* mindstormssimulation
*
* Created by Torsten Kammer on 26.04.10
* Copyright 2010 RWTH Aachen University All rights reserved.
*
*/
#include "InterpreterThread.h"
#include "Interpreter.h"
#include <iostream>
#include "../Execution/RXEFile.h"
#include "../System/VMMemory.h"
void InterpreterThread::op_jmp(unsigned flags, const uint16_t *params)
{
// Parameters:
// 0: offset (immediate, signed): Alter PC by this much.
int16_t offset = int16_t(params[0]);
instruction += (offset - 2);
// Account for size of jmp instruction, as otherwise we will go right past it.
}
void InterpreterThread::op_brcmp(unsigned flags, const uint16_t *params)
{
// Parameters:
// 0: offset (immediate, signed): Alter PC by this much if comparison is true
// 1: Source1, memory location
// 2: Source2, memory location
if (aggregatedComparisonBetweenMemoryLocation(flags, params[1], params[2]))
{
int16_t offset = int16_t(params[0]);
instruction += (offset - 4);
// Account for size of instruction, as otherwise we will go right past it.
}
}
void InterpreterThread::op_brtst(unsigned flags, const uint16_t *params)
{
// Parameters:
// 0: offset (immediate, signed): Alter PC by this much if comparison is true
// 1: Source, memory location
bool jump;
if(memory->getFile()->isAggregatedType(params[1]))
jump = aggregatedComparisonBetweenScalarValueAndAggregated(flags, 0, params[1], false);
else
jump = aggregatedComparisonBetweenScalarValues(flags, memory->getScalarValue(params[1]), 0);
if (jump)
{
int16_t offset = int16_t(params[0]);
instruction += (offset - 3);
// Account for size of instruction, as otherwise we will go right past it.
}
}
void InterpreterThread::op_stop(unsigned flags, const uint16_t *params)
{
throw std::runtime_error("op_stop");
}
void InterpreterThread::op_finclump(unsigned flags, const uint16_t *params)
{
// parameters:
// 0: start, immediate. First clump to schedule
// 1: end, immediate. Last clump to schedule
isTerminated = true;
if(params[0] != 0xffff /* it would be -1 if this was a signed number */) {
interpreter->scheduleDependantClumps(currentClump, params[0], params[1]);
}
}
void InterpreterThread::op_finclumpimmed(unsigned flags, const uint16_t *params)
{
// parameters:
// 0: clumpId, immediate. Clump to schedule
isTerminated = true;
interpreter->scheduleClump(params[0]);
}
void InterpreterThread::op_acquire(unsigned flags, const uint16_t *params)
{
std::cout << "ignored acquire" << std::endl;
}
void InterpreterThread::op_release(unsigned flags, const uint16_t *params)
{
std::cout << "ignored release" << std::endl;
}
void InterpreterThread::op_subcall(unsigned flags, const uint16_t *params)
{
// Parameters:
// 0: Subroutine, immediate. Clump to branch to.
// 1: CallerID, memory. Store ID of this clump there.
// Store clump to jump back to.
memory->setScalarValue(params[1], currentClump);
// Store instruction to jump back to
stack.push_back(instruction);
// Branch into new clump
currentClump = params[0];
instruction = memory->getFile()->getCodeStartForClump(currentClump);
}
void InterpreterThread::op_subret(unsigned flags, const uint16_t *params)
{
// Parameters:
// 0: CallerID, memory. Jump back to clump with this ID.
// Find old clump and restore operation there.
currentClump = memory->getScalarValue(params[0]);
instruction = stack.back();
stack.pop_back();
}