Debian Codegraph @

memorytracepane.h

raw symbols SCIP
1 // File: memorytracepane.h
2 /*
3 Pep8-1 is a virtual machine for writing machine language and assembly
4 language programs.
5
6 Copyright (C) 2009 J. Stanley Warford, Pepperdine University
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef MEMORYTRACEPANE_H
23 #define MEMORYTRACEPANE_H
24
25 #include <QWidget>
26 #include <QGraphicsScene>
27 #include <QStack>
28 #include <QSet>
29 #include "memorycellgraphicsitem.h"
30 #include "enu.h"
31 #include "stackframefsm.h"
32
33 namespace Ui {
34 class MemoryTracePane;
35 }
36
37 class MemoryTracePane : public QWidget {
38 Q_OBJECT
39 Q_DISABLE_COPY(MemoryTracePane)
40 public:
41 explicit MemoryTracePane(QWidget *parent = 0);
42 virtual ~MemoryTracePane();
43
44 void setMemoryTrace();
45 // The memory trace is populated (on assembly).
46
47 void updateMemoryTrace();
48 // Post: The memory trace is updated
49
50 void cacheChanges();
51 // Post: Modfied bytes are cached for updating the sim view
52
53 void cacheStackChanges();
54 // Post: Stack changes are cached for the next time the simulation view is updated
55
56 void cacheHeapChanges();
57 // Post: Heap changes are cached for the next time the simulation view is updated
58
59 void highlightOnFocus();
60 // Post: Highlights the label based on the label window color saved in the UI file
61
62 bool hasFocus();
63 // Post: returns if the pane has focus
64
65 void setFocus();
66 // Post: the graphics item has focus
67
68 public slots:
69 void onFontChanged(QFont font);
70
71 private:
72 Ui::MemoryTracePane *ui;
73
74 QGraphicsScene *scene;
75 QStack<MemoryCellGraphicsItem *> globalVars;
76 // Stack of the global variables
77 QStack<MemoryCellGraphicsItem *> runtimeStack;
78 // Stack of the stack items
79 QStack<MemoryCellGraphicsItem *> heap;
80 // Stack of heap items
81 QStack<bool> isRuntimeStackItemAddedStack;
82 // Used to keep track if the item has been added to the scene yet for the runtime stack
83 QStack<bool> isHeapItemAddedStack;
84 // Used to keep track if the item has been added to the scene yet for the heap
85 QStringList lookAheadSymbolList;
86 // This is used to give us what we're pushing onto the stack before we get there.
87 // It must be a look-ahead list because of branching and the inability to look behind
88
89 // Stack frame
90 QMap<int, QGraphicsRectItem *> stackHeightToStackFrameMap;
91 QStack<int> numCellsInStackFrame;
92 // This is a stack of ints that each represent how many cells each stack frame encompass
93 QStack<bool> isStackFrameAddedStack;
94 // Stack used to determine if a stack frame has been added to the scene yet
95 QStack<QGraphicsRectItem *> graphicItemsInStackFrame;
96 // Stack of *items used to access the stack frames
97 QStack<bool> isHeapFrameAddedStack;
98 // Stack used to determine if a heap frame has been added to the scene yet
99 QStack<QGraphicsRectItem *> heapFrameItemStack;
100 // Stack of *items for the heap graphic frames
101
102 QPointF globalLocation;
103 // This is the location where the next global item will be added
104 QPointF stackLocation;
105 // This is the location where the next stack item will be added
106 QPointF heapLocation;
107 // This is the location where the next heap item will be added
108
109 QMap<int, MemoryCellGraphicsItem *> addressToGlobalItemMap;
110 // This map is used to identify if an address is in the globals
111 QMap<int, MemoryCellGraphicsItem *> addressToStackItemMap;
112 // This map is used to identify if an address is part of the stack
113 QMap<int, MemoryCellGraphicsItem *> addressToHeapItemMap;
114 // Used to identify if an address is part of the heap
115 QSet<int> modifiedBytes;
116 // This set is used to cache modified bytes since the last update
117 QList<int> bytesWrittenLastStep;
118 // This list is used to keep track of the bytes changed last step for highlighting purposes
119 bool delayLastStepClear;
120 // This is used to delay the clear of the bytesWrittenLastStep list for purposes of highlighting after a trap
121
122 QList<MemoryCellGraphicsItem *> newestHeapItemsList;
123 // This is used to color the most recently new'd heap items light green
124
125 StackFrameFSM stackFrameFSM;
126
127 // Called by the cacheStack/HeapChanges functions to add frames to the respective places.
128 // They're in their own functions because a fair bit happens there.
129 void addStackFrame(int numCells);
130 void addHeapFrame(int numCells);
131
132 void moveHeapUpOneCell();
133 // Moves the heap frame up n cells to accomodate for new items being added.
134
135 void popBytes(int bytesToPop);
136 // This pops bytesToPop bytes off of the runtimeStack
137
138 void mouseReleaseEvent(QMouseEvent *);
139 void mouseDoubleClickEvent(QMouseEvent *);
140
141 private slots:
142 void zoomFactorChanged(int factor);
143
144 signals:
145 void labelDoubleClicked(Enu::EPane pane);
146
147 };
148
149 #endif // MEMORYTRACEPANE_H