-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.h
78 lines (63 loc) · 1.24 KB
/
memory.h
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
#pragma once
#include "globals.h"
// this should really be a union but then I can't really debug it effectively
// so it will be a struct for the time being.
struct datum
{
int integer;
double fpoint;
void* loc;
// for debugging
string type;
datum() {
}
datum(int i) {
integer = i;
type = "int";
}
datum(double d) {
fpoint = d;
type = "Float";
}
datum(void* op) {
loc = op;
type = "address";
}
string toString();
};
class memory
{
private:
datum *registers;
bool* gets;
bool* sets;
datum *heap;
int heappointer;
datum *stack;
public:
memory()
: registers(new datum[NUMREGISTERS])
, gets(new bool[NUMREGISTERS])
, sets(new bool[NUMREGISTERS])
, heap(new datum[HEAPSIZE])
, heappointer(0)
, stack(new datum[STACKSIZE])
{
registerset(SPREGID, datum(0));
registerset(FPREGID, datum(0));
}
/*
datum stackpop();
void stackpush(datum n);
*/
datum stackget(int address);
void stackset(int address, datum value);
datum registerget(registerid id);
void registerset(registerid id, datum value);
void debugMemory();
void resetregdebug();
int allocate(int n);
datum heapget(int address);
void heapset(int address, datum value);
string debugRegName(registerid r);
};