OpenASIP  2.0
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.

82  {
83  ID_SOURCEFILE_CHOICE = 19000,
85  };

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 }

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 }

◆ 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 }

◆ 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 }

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

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 }

◆ 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 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 }

◆ 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 }

◆ 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 }

◆ 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 }

◆ 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 }

◆ 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) {
143  showLine(currentLineNums_.back());
144  }
145 }

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

Here is the call graph for this function:

Member Data Documentation

◆ currentFile_

wxString ProximDebuggerWindow::currentFile_
private

Definition at line 73 of file ProximDebuggerWindow.hh.

◆ currentLineNums_

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

Definition at line 75 of file ProximDebuggerWindow.hh.

◆ sourceCodeText_

wxTextCtrl* ProximDebuggerWindow::sourceCodeText_
private

Definition at line 79 of file ProximDebuggerWindow.hh.

◆ sourceFileList_

wxChoice* ProximDebuggerWindow::sourceFileList_
private

Definition at line 77 of file ProximDebuggerWindow.hh.


The documentation for this class was generated from the following files:
TTAProgram::Move::sourceFileName
std::string sourceFileName() const
Definition: Move.cc:488
WxConversion::toWxString
static wxString toWxString(const std::string &source)
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
ProximDebuggerWindow::sourceCodeText_
wxTextCtrl * sourceCodeText_
Definition: ProximDebuggerWindow.hh:79
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::Move::sourceLineNumber
int sourceLineNumber() const
Definition: Move.cc:459
ProximToolbox::program
static const TTAProgram::Program & program()
Definition: ProximToolbox.cc:88
ProximDebuggerWindow::updateAnnotations
void updateAnnotations()
Definition: ProximDebuggerWindow.cc:123
ProximDebuggerWindow::ID_SOURCECODE
@ ID_SOURCECODE
Definition: ProximDebuggerWindow.hh:84
ProximDebuggerWindow::showLine
void showLine(int lineNum)
Definition: ProximDebuggerWindow.cc:202
ProximDebuggerWindow::highlightLine
void highlightLine(int lineNum)
Definition: ProximDebuggerWindow.cc:185
TTAProgram::Program::instructionAt
Instruction & instructionAt(InstructionAddress address) const
Definition: Program.cc:374
ErrorDialog
Definition: ErrorDialog.hh:42
ProximDebuggerWindow::ID_SOURCEFILE_CHOICE
@ ID_SOURCEFILE_CHOICE
Definition: ProximDebuggerWindow.hh:83
ProximDebuggerWindow::setLineAttributes
void setLineAttributes(int lineNum, wxTextAttr style)
Definition: ProximDebuggerWindow.cc:170
TTAProgram::Move
Definition: Move.hh:55
ProximDebuggerWindow::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: ProximDebuggerWindow.cc:250
ProximDebuggerWindow::currentLineNums_
std::vector< int > currentLineNums_
Definition: ProximDebuggerWindow.hh:75
ProximDebuggerWindow::sourceFileList_
wxChoice * sourceFileList_
Definition: ProximDebuggerWindow.hh:77
ProximDebuggerWindow::loadProgram
void loadProgram(const TTAProgram::Program &program)
Definition: ProximDebuggerWindow.cc:91
TTAProgram::Move::hasSourceLineNumber
bool hasSourceLineNumber() const
Definition: Move.cc:445
ProximDebuggerWindow::currentFile_
wxString currentFile_
Definition: ProximDebuggerWindow.hh:73
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
ProximDebuggerWindow::loadSourceCode
void loadSourceCode(wxString sourceFile)
Definition: ProximDebuggerWindow.cc:155
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
ProximSimulatorWindow::ProximSimulatorWindow
ProximSimulatorWindow(ProximMainFrame *mainFrame, wxWindowID id=-1, wxPoint pos=wxDefaultPosition, wxSize size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
Definition: ProximSimulatorWindow.cc:49
TTAProgram::Move::hasSourceFileName
bool hasSourceFileName() const
Definition: Move.cc:478