OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ProximDebuggerWindow Class Reference

#include <ProximDebuggerWindow.hh>

Inheritance diagram for ProximDebuggerWindow:
Inheritance graph
Collaboration diagram for ProximDebuggerWindow:
Collaboration graph

Public Member Functions

 ProximDebuggerWindow (ProximMainFrame *parent, int id)
 
virtual ~ProximDebuggerWindow ()
 
virtual void reset ()
 
void loadProgram (const TTAProgram::Program &program)
 
void updateAnnotations ()
 
void loadSourceCode (wxString sourceFile)
 
void setLineAttributes (int lineNum, wxTextAttr style)
 
void highlightLine (int lineNum)
 
void showLine (int lineNum)
 

Private Types

enum  { ID_SOURCEFILE_CHOICE = 19000 , ID_SOURCECODE }
 

Private Member Functions

void onProgramLoaded (const SimulatorEvent &event)
 
void onSimulationStop (const SimulatorEvent &event)
 
void onSourceFileChoice (wxCommandEvent &event)
 
wxSizer * createContents (wxWindow *parent, bool call_fit, bool set_sizer)
 

Private Attributes

wxString currentFile_
 
std::vector< int > currentLineNums_
 
wxChoice * sourceFileList_
 
wxTextCtrl * sourceCodeText_
 

Additional Inherited Members

- Protected Member Functions inherited from ProximSimulatorWindow
 ProximSimulatorWindow (ProximMainFrame *mainFrame, wxWindowID id=-1, wxPoint pos=wxDefaultPosition, wxSize size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
 
virtual ~ProximSimulatorWindow ()
 

Detailed Description

Proxim subwindow which displays program source code annotations.

This window listens to SimulatorEvents and updates the window contents automatically.

Definition at line 54 of file ProximDebuggerWindow.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
ID_SOURCEFILE_CHOICE 
ID_SOURCECODE 

Definition at line 82 of file ProximDebuggerWindow.hh.

Constructor & Destructor Documentation

◆ ProximDebuggerWindow()

ProximDebuggerWindow::ProximDebuggerWindow ( ProximMainFrame parent,
int  id 
)

Definition at line 58 of file ProximDebuggerWindow.cc.

59 :
60 ProximSimulatorWindow(parent, id, wxDefaultPosition, wxSize(800,600)),
61 currentFile_() {
62
63 createContents(this, true, true);
65}
void loadProgram(const TTAProgram::Program &program)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
static const TTAProgram::Program & program()

References ProximToolbox::program().

Here is the call graph for this function:

◆ ~ProximDebuggerWindow()

ProximDebuggerWindow::~ProximDebuggerWindow ( )
virtual

Definition at line 68 of file ProximDebuggerWindow.cc.

68 {
69}

Member Function Documentation

◆ createContents()

wxSizer * ProximDebuggerWindow::createContents ( wxWindow *  parent,
bool  call_fit,
bool  set_sizer 
)
private

Creates the window contents.

Code generated by wxDesigner.

Definition at line 250 of file ProximDebuggerWindow.cc.

251 {
252
253 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
254
255 wxBoxSizer *upperSizer = new wxBoxSizer(wxHORIZONTAL);
256 sourceFileList_ = new wxChoice(
257 parent, ID_SOURCEFILE_CHOICE, wxDefaultPosition, wxDefaultSize);
258
259 upperSizer->Add(sourceFileList_, 1, wxGROW|wxALL, 5);
260 mainSizer->Add(upperSizer, 0, wxGROW|wxALL, 5);
261
262 sourceCodeText_ = new wxTextCtrl(
263 parent, ID_SOURCECODE, wxEmptyString, wxDefaultPosition,
264 wxSize(640, 600), wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
265
266 mainSizer->Add(sourceCodeText_, 1, wxGROW|wxALL, 5);
267
268 if (set_sizer)
269 {
270 parent->SetSizer( mainSizer );
271 if (call_fit)
272 mainSizer->SetSizeHints( parent );
273 }
274
275 return mainSizer;
276}

References ID_SOURCECODE, ID_SOURCEFILE_CHOICE, sourceCodeText_, and sourceFileList_.

◆ highlightLine()

void ProximDebuggerWindow::highlightLine ( int  lineNum)

Highlights line of code in the sourceCodeText_ widget

Parameters
lineNumSource code line number.

Definition at line 185 of file ProximDebuggerWindow.cc.

185 {
186
187 if (std::find(currentLineNums_.begin(), currentLineNums_.end(), lineNum) ==
188 currentLineNums_.end()) {
189
190 currentLineNums_.push_back(lineNum);
191 setLineAttributes(lineNum, wxTextAttr(*wxWHITE, *wxBLUE));
192 }
193}
void setLineAttributes(int lineNum, wxTextAttr style)
std::vector< int > currentLineNums_

References currentLineNums_, and setLineAttributes().

Referenced by updateAnnotations().

Here is the call graph for this function:

◆ loadProgram()

void ProximDebuggerWindow::loadProgram ( const TTAProgram::Program program)

Loads a program model to the window.

Parameters
programProgram to load.

Definition at line 91 of file ProximDebuggerWindow.cc.

91 {
92 // get list of used source code files for drop-down list
93 for (int i = 0; i < program.moveCount(); i++) {
94
95 const TTAProgram::Move& m = program.moveAt(i);
96
97 if (m.hasSourceFileName()) {
98 wxString sourceFile = WxConversion::toWxString(m.sourceFileName());
99
100 if (sourceFileList_->FindString(sourceFile) == -1) {
101 sourceFileList_->Append(sourceFile);
102 }
103 }
104 }
105
106 // load first file from drop-down list and set hilights
107 if (sourceFileList_->GetCount() > 0) {
108 loadSourceCode(sourceFileList_->GetString(0));
110 } else {
111 ErrorDialog dialog(
112 this, _T("No debugging information available."));
113 dialog.ShowModal();
114 }
115}
find Finds info of the inner loops in the program
void loadSourceCode(wxString sourceFile)
bool hasSourceFileName() const
Definition Move.cc:478
std::string sourceFileName() const
Definition Move.cc:488
static wxString toWxString(const std::string &source)

References TTAProgram::Move::hasSourceFileName(), loadSourceCode(), program, sourceFileList_, TTAProgram::Move::sourceFileName(), WxConversion::toWxString(), and updateAnnotations().

Referenced by onProgramLoaded().

Here is the call graph for this function:

◆ loadSourceCode()

void ProximDebuggerWindow::loadSourceCode ( wxString  sourceFile)

Loads source code into the sourceCodeText_ widget

Parameters
sourceFileAbsolute file location as wxString.

Definition at line 155 of file ProximDebuggerWindow.cc.

155 {
156
157 sourceCodeText_->LoadFile(sourceFile);
158 currentFile_ = sourceFile;
159 sourceFileList_->SetSelection(sourceFileList_->FindString(sourceFile));
160}

References currentFile_, sourceCodeText_, and sourceFileList_.

Referenced by loadProgram(), and onSourceFileChoice().

◆ onProgramLoaded()

void ProximDebuggerWindow::onProgramLoaded ( const SimulatorEvent event)
private

Event handler which is called when a new program is loaded in the simulator.

Definition at line 211 of file ProximDebuggerWindow.cc.

211 {
213}

References loadProgram(), and ProximToolbox::program().

Here is the call graph for this function:

◆ onSimulationStop()

void ProximDebuggerWindow::onSimulationStop ( const SimulatorEvent event)
private

Event handler which is called when simulation step ends.

Definition at line 220 of file ProximDebuggerWindow.cc.

220 {
221 // unhilight old lines
222 for (int lineNum : currentLineNums_) {
223 setLineAttributes(lineNum, wxTextAttr(*wxBLACK, *wxWHITE));
224 }
225 currentLineNums_.clear();
226
228}

References currentLineNums_, setLineAttributes(), and updateAnnotations().

Here is the call graph for this function:

◆ onSourceFileChoice()

void ProximDebuggerWindow::onSourceFileChoice ( wxCommandEvent &  event)
private

Event handler for drop-down list selection.

Loads selected source code from the drop-down list.

Definition at line 237 of file ProximDebuggerWindow.cc.

237 {
238 loadSourceCode(sourceFileList_->GetString(sourceFileList_->GetSelection()));
239 currentLineNums_.clear();
241}

References currentLineNums_, loadSourceCode(), sourceFileList_, and updateAnnotations().

Here is the call graph for this function:

◆ reset()

void ProximDebuggerWindow::reset ( )
virtual

Resets the window when a new program or machine is being loaded in the simulator.

Reimplemented from ProximSimulatorWindow.

Definition at line 77 of file ProximDebuggerWindow.cc.

77 {
78 sourceFileList_->Clear();
79 sourceCodeText_->Clear();
80 currentFile_.clear();
81 currentLineNums_.clear();
82}

References currentFile_, currentLineNums_, sourceCodeText_, and sourceFileList_.

◆ setLineAttributes()

void ProximDebuggerWindow::setLineAttributes ( int  lineNum,
wxTextAttr  style 
)

Sets certain style attributes to the line in sourceCodeText_ widget

Parameters
lineNumLine number
styleStyle attributes (text color, background color, font, alignment)

Definition at line 170 of file ProximDebuggerWindow.cc.

170 {
171
172 long lineStart = sourceCodeText_->XYToPosition(0, lineNum - 1);
173 long lineEnd = lineStart + sourceCodeText_->GetLineLength(lineNum - 1);
174
175 sourceCodeText_->SetStyle(lineStart, lineEnd, style);
176}

References sourceCodeText_.

Referenced by highlightLine(), and onSimulationStop().

◆ showLine()

void ProximDebuggerWindow::showLine ( int  lineNum)

Makes line visible in the sourceCodeText_ widget

Parameters
lineNumSource code line number.

Definition at line 202 of file ProximDebuggerWindow.cc.

202 {
203 sourceCodeText_->ShowPosition(sourceCodeText_->XYToPosition(0,lineNum - 1));
204}

References sourceCodeText_.

Referenced by updateAnnotations().

◆ updateAnnotations()

void ProximDebuggerWindow::updateAnnotations ( )

Parses possible annotations in the current instruction and hilights source code lines.

Definition at line 123 of file ProximDebuggerWindow.cc.

123 {
124
125 Word pc = wxGetApp().simulation()->frontend()->programCounter();
126
127 const TTAProgram::Instruction& instruction =
129
130 // check annotations and hilight possible lines
131 for (int i = 0; i < instruction.moveCount(); i++) {
132 const TTAProgram::Move& m = instruction.move(i);
133
134 if (m.hasSourceLineNumber()) {
135 wxString sourceFile = WxConversion::toWxString(m.sourceFileName());
136 if (sourceFile == currentFile_) {
138 }
139 }
140 }
141 // make last higlighted line visible
142 if (currentLineNums_.size() > 0) {
144 }
145}
void highlightLine(int lineNum)
Move & move(int i) const
bool hasSourceLineNumber() const
Definition Move.cc:445
int sourceLineNumber() const
Definition Move.cc:459
Instruction & instructionAt(InstructionAddress address) const
Definition Program.cc:374

References currentFile_, currentLineNums_, TTAProgram::Move::hasSourceLineNumber(), highlightLine(), TTAProgram::Program::instructionAt(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), ProximToolbox::program(), showLine(), TTAProgram::Move::sourceFileName(), TTAProgram::Move::sourceLineNumber(), and WxConversion::toWxString().

Referenced by loadProgram(), onSimulationStop(), and onSourceFileChoice().

Here is the call graph for this function:

Member Data Documentation

◆ currentFile_

wxString ProximDebuggerWindow::currentFile_
private

Definition at line 73 of file ProximDebuggerWindow.hh.

Referenced by loadSourceCode(), reset(), and updateAnnotations().

◆ currentLineNums_

std::vector<int> ProximDebuggerWindow::currentLineNums_
private

◆ sourceCodeText_

wxTextCtrl* ProximDebuggerWindow::sourceCodeText_
private

◆ sourceFileList_

wxChoice* ProximDebuggerWindow::sourceFileList_
private

The documentation for this class was generated from the following files: