KoMo2  1.0.0
A modern ARM emulator GUI.
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
DisassemblyModel Class Reference

The declaration of the DisassemblyModel class. More...

#include <DisassemblyModel.h>

Inheritance diagram for DisassemblyModel:
Model

Public Member Functions

 DisassemblyModel (DisassemblyView *const view, KoMo2Model *const parent)
 Construct a new DisassemblyModel::DisassemblyModel object. More...
 
void refreshViews ()
 Refreshes the values in the views to display the new values fetched from Jimulator.
 
DisassemblyView *const getView ()
 Returns a pointer to the view object. More...
 
void setPCValue (const std::string val)
 Updates the value of PCValue. More...
 
virtual void changeJimulatorState (const JimulatorState newState) override
 Handles changes of Jimulator state. More...
 
virtual const bool handleKeyPress (const GdkEventKey *const e) override
 Handles any key press events. More...
 
void setEnglishMnemonic (const bool val)
 Set the value of the englishMnemonic member variable. More...
 

Private Member Functions

const std::string intToFormattedHexString (const uint32_t formatMe) const
 Converts a fixed width 32-bit integer to a hex string, padded with 0's to 8 characters, pre-fixed with "0x", and raised to all capitals. More...
 
const bool handleScroll (GdkEventScroll *const e)
 Handles the scroll events. More...
 
void incrementMemoryIndex (const uint32_t val)
 Updates the list pointers to a new value. Val is multipled by 4 - for example, if val is 1, memoryIndex is incremented by 4, as this is the gap between memory registers. More...
 
void addScrollRecognition ()
 Adds scroll recognition to the container object, which causes scroll events to be sent to the member function handleScroll.
 
const std::array< Jimulator::MemoryValues, 13 > getMemoryValues () const
 Reads memory values from Jimulator. More...
 
void onBreakpointToggle (DisassemblyRows *const row)
 Handle the toggling of a breakpoint within the DisassemblyView. More...
 
void setupButtonHandlers ()
 Adds button handlers to every breakpoint button.
 
void updateCSSFlags (const Gtk::StateFlags state, DisassemblyRows &row, const uint32_t address)
 Handles setting the CSS flags for each disassembly row, which determines which CSS class it uses and therefore how it looks. More...
 
const std::string buildDisassemblyRowAccessibilityString (DisassemblyRows &val)
 Generates the string to set for the accessibility model. More...
 
const std::string convertMnemonicToEnglish (const std::string mnemonic) const
 Converts a mnemonic into plain English. More...
 
const std::string sanitizeParamters (std::string param) const
 Sanitizes any of the paramters used with an ARM mnemonic. More...
 
const std::string toLowerCase (std::string s) const
 Converts a string to lower case. More...
 
const std::vector< std::string > parseDEFB (std::vector< std::string > v) const
 Parses the DEFB ARM mnemonic - since a single ARM command is broken into a vector by the spaces between strings, the string that the DEFB command defines will be split across several vector indexes. This function packs this string back into a single index of the vector. More...
 
const std::vector< std::string > parseSWI (std::vector< std::string > m) const
 Parses the SWI ARM mnemonic - the SWI command always takes 1 paramter, but means very different things depending on the parameter, meaning that a single entry in mnemonicsMap for the SWI command cannot work. This function packs the paramter of the SWI command in with the SWI key word for easier lookup in the map, if the first key word in the vector is SWI. More...
 
const std::pair< std::vector< std::string >, std::string > parseLabel (std::vector< std::string > m) const
 Parses labels from an ARM command. If the first index in the vector is not a recognised keyword, then it must be a label. This function defines an initial string that is only defined if the first index is a label. It then updates the vector such that upon returning, the first index is the keyword. It returns this parsed vector along with the new output text. More...
 
const std::string buildMnemonicString (std::string s, std::vector< std::string > m) const
 Builds the output mnemonics string from the vector making up the current ARM command and the value read from the map. See the comment for mnemonicMap for details on the syntax of the value read from the map. More...
 
 DisassemblyModel (const DisassemblyModel &)=delete
 
 DisassemblyModel (const DisassemblyModel &&)=delete
 
DisassemblyModeloperator= (const DisassemblyModel &)=delete
 
DisassemblyModeloperator= (const DisassemblyModel &&)=delete
 
- Private Member Functions inherited from Model
 Model (KoMo2Model *const parent)
 Constructs a new Model object - just assigns the parent variable. More...
 
KoMo2Model *const getParent () const
 Returns the parent pointer. More...
 
template<class T1 , class T2 >
void setButtonListener (Gtk::Button *const button, const T1 b, const T2 c)
 Connect any button to any member function of. More...
 
void setButtonState (Gtk::Button *const button, const bool state, Gtk::Image *const img=nullptr, const std::string newTooltip="", const std::string newLabelText="") const
 Sets the state of a button to some boolean - the assumption is that if a button is not meant to be sensitive (get_sensitive() == false) then it should also not have a tooltip or many other attributes. You can also optionally update the buttons image, tooltip text, and label text. More...
 
JimulatorState getJimulatorState () const
 Return the jimulatorState member object. More...
 

Private Attributes

DisassemblyView *const view
 The view this model represents.
 
std::string PCValue = "0x00000000"
 Stores the value currently in the program counter.
 
const Gtk::StateFlags NORMAL = Gtk::STATE_FLAG_DIR_LTR
 The CSS state flags for an un-highlighted memory row.
 
const Gtk::StateFlags PC_ADDRESS
 The CSS state flags for if the memory row is currently stored in the Program Counter. More...
 
const Gtk::StateFlags FOCUSED
 The CSS state flags for a memory row that has keyboard focus. More...
 
const Gtk::StateFlags PC_ADDRESS_FOCUSED
 The CSS state flags for e memory row that has keyboard focus and is currently stored in the Program Counter. More...
 
const std::unordered_map< std::string, std::string > mnemonicsMap
 A map pairing ARM mnemonic commands with the English translation string associated with them for the screenreader. For ARM commands that take paramters, the English equivalent string has a paramter notation that is regexed away. This notation is: ?'paramter_number'?. More...
 
bool englishMnemonic = false
 Whether or not ARM mnemonics should be read in English when being read by a screenreader, or if they should be left as ARM mnemonics.
 

Static Private Attributes

static uint32_t memoryIndex = 0
 Fixed width integer representing the memory address of the view at the top of the container.
 

Detailed Description

The declaration of the DisassemblyModel class.

Definition at line 23 of file DisassemblyModel.h.

Constructor & Destructor Documentation

DisassemblyModel::DisassemblyModel ( DisassemblyView *const  view,
KoMo2Model *const  parent 
)

Construct a new DisassemblyModel::DisassemblyModel object.

Parameters
viewA pointer to the view object, set at initialisation.
parentA pointer to the parent object, set at initialisation.

Definition at line 26 of file DisassemblyModel.cpp.

Member Function Documentation

const std::string DisassemblyModel::buildDisassemblyRowAccessibilityString ( DisassemblyRows row)
private

Generates the string to set for the accessibility model.

Parameters
rowThe row to build to accessibility string from.
Returns
const std::string The accessibility string.

Definition at line 143 of file DisassemblyModel.cpp.

const std::string DisassemblyModel::buildMnemonicString ( std::string  s,
std::vector< std::string >  m 
) const
private

Builds the output mnemonics string from the vector making up the current ARM command and the value read from the map. See the comment for mnemonicMap for details on the syntax of the value read from the map.

Parameters
sThe value read from the map.
mThe vector making up the current ARM command.
Returns
const std::string The mnemonic, translated into English.

Definition at line 283 of file DisassemblyModel.cpp.

void DisassemblyModel::changeJimulatorState ( const JimulatorState  newState)
overridevirtual

Handles changes of Jimulator state.

Parameters
newStateThe state Jimulator has changed into.

Implements Model.

Definition at line 374 of file DisassemblyModel.cpp.

const std::string DisassemblyModel::convertMnemonicToEnglish ( const std::string  mnemonic) const
private

Converts a mnemonic into plain English.

Parameters
mnemonicAn ARM instruction mnemonic.
Returns
const std::string The input parameter converted into English.

Definition at line 170 of file DisassemblyModel.cpp.

const std::array< Jimulator::MemoryValues, 13 > DisassemblyModel::getMemoryValues ( ) const
private

Reads memory values from Jimulator.

Returns
std::array<Jimulator::MemoryValues, 13> An array of the 13 memory values - their addresses, their hex columns and their disassembly/source columns.

Definition at line 474 of file DisassemblyModel.cpp.

DisassemblyView *const DisassemblyModel::getView ( )

Returns a pointer to the view object.

Returns
DisassemblyView* const The view pointer.

Definition at line 464 of file DisassemblyModel.cpp.

const bool DisassemblyModel::handleKeyPress ( const GdkEventKey *const  e)
overridevirtual

Handles any key press events.

Parameters
eThe key press event.
Returns
bool true if the key press was handled.

Implements Model.

Definition at line 381 of file DisassemblyModel.cpp.

const bool DisassemblyModel::handleScroll ( GdkEventScroll *const  e)
private

Handles the scroll events.

Parameters
eThe key press event.
Returns
bool if a key was pressed.

Definition at line 75 of file DisassemblyModel.cpp.

void DisassemblyModel::incrementMemoryIndex ( const uint32_t  val)
private

Updates the list pointers to a new value. Val is multipled by 4 - for example, if val is 1, memoryIndex is incremented by 4, as this is the gap between memory registers.

Parameters
valThe value to increment by.

Definition at line 364 of file DisassemblyModel.cpp.

const std::string DisassemblyModel::intToFormattedHexString ( const uint32_t  formatMe) const
private

Converts a fixed width 32-bit integer to a hex string, padded with 0's to 8 characters, pre-fixed with "0x", and raised to all capitals.

Parameters
formatMeThe integer to be formatted.
Returns
const std::string The formatted string.

Definition at line 102 of file DisassemblyModel.cpp.

void DisassemblyModel::onBreakpointToggle ( DisassemblyRows *const  row)
private

Handle the toggling of a breakpoint within the DisassemblyView.

Parameters
rowThe row which has had it's breakpoint toggled. Row id's are a direct index - the first row is 0, the last row is 11 - so we can combine the row ID with the memoryIndex variable to identify what address the breakpoint should be set at.

Definition at line 41 of file DisassemblyModel.cpp.

const std::vector< std::string > DisassemblyModel::parseDEFB ( std::vector< std::string >  m) const
private

Parses the DEFB ARM mnemonic - since a single ARM command is broken into a vector by the spaces between strings, the string that the DEFB command defines will be split across several vector indexes. This function packs this string back into a single index of the vector.

Parameters
mThe vector of strings making up the current ARM command.
Returns
const std::vector<std::string> The parsed vector of string making up the current ARM command.

Definition at line 209 of file DisassemblyModel.cpp.

const std::pair< std::vector< std::string >, std::string > DisassemblyModel::parseLabel ( std::vector< std::string >  m) const
private

Parses labels from an ARM command. If the first index in the vector is not a recognised keyword, then it must be a label. This function defines an initial string that is only defined if the first index is a label. It then updates the vector such that upon returning, the first index is the keyword. It returns this parsed vector along with the new output text.

Parameters
mThe vector of strings making up the current ARM command.
Returns
const std::pair<std::vector<std::string>, std::string> A pair making up the parsed vector and any output text that was derived from this function.

Definition at line 255 of file DisassemblyModel.cpp.

const std::vector< std::string > DisassemblyModel::parseSWI ( std::vector< std::string >  m) const
private

Parses the SWI ARM mnemonic - the SWI command always takes 1 paramter, but means very different things depending on the parameter, meaning that a single entry in mnemonicsMap for the SWI command cannot work. This function packs the paramter of the SWI command in with the SWI key word for easier lookup in the map, if the first key word in the vector is SWI.

Parameters
mThe vector of strings making up the current ARM command.
Returns
const std::vector<std::string> The parsed vector of strings making up the current ARM command.

Definition at line 235 of file DisassemblyModel.cpp.

const std::string DisassemblyModel::sanitizeParamters ( std::string  param) const
private

Sanitizes any of the paramters used with an ARM mnemonic.

Parameters
paramThe parameter to be sanitized.
Returns
const std::string The sanitized paramter.

Definition at line 301 of file DisassemblyModel.cpp.

void DisassemblyModel::setEnglishMnemonic ( const bool  val)

Set the value of the englishMnemonic member variable.

Parameters
valThe value to set englishMnemonic to.

Definition at line 488 of file DisassemblyModel.cpp.

void DisassemblyModel::setPCValue ( const std::string  val)

Updates the value of PCValue.

Parameters
valThe value to set PCValue to.

Definition at line 481 of file DisassemblyModel.cpp.

const std::string DisassemblyModel::toLowerCase ( std::string  s) const
private

Converts a string to lower case.

Parameters
sThe string to convert to lower case.
Returns
const std::string The lower case string.

Definition at line 316 of file DisassemblyModel.cpp.

void DisassemblyModel::updateCSSFlags ( const Gtk::StateFlags  flag,
DisassemblyRows row,
const uint32_t  address 
)
private

Handles setting the CSS flags for each disassembly row, which determines which CSS class it uses and therefore how it looks.

Parameters
flagThe current CSS state of the memory row.
rowThe current memory row.
addressThe address of the current memory row.

Definition at line 331 of file DisassemblyModel.cpp.

Member Data Documentation

const Gtk::StateFlags DisassemblyModel::FOCUSED
private
Initial value:
=
Gtk::STATE_FLAG_DIR_LTR | Gtk::STATE_FLAG_FOCUSED

The CSS state flags for a memory row that has keyboard focus.

Definition at line 67 of file DisassemblyModel.h.

const std::unordered_map<std::string, std::string> DisassemblyModel::mnemonicsMap
private

A map pairing ARM mnemonic commands with the English translation string associated with them for the screenreader. For ARM commands that take paramters, the English equivalent string has a paramter notation that is regexed away. This notation is: ?'paramter_number'?.

For example, in the command "ADD R1, R2, R3", R1 is paramter 1, R2 is paramter 2, R3 is paramter 3. So the associated English string "Add ?3? to ?2? and store in ?1?" swaps ?1? with R1, ?2? with R2, and ?3? with R3, to result in the string "Add R3 to R2 and store in R1."

Definition at line 90 of file DisassemblyModel.h.

const Gtk::StateFlags DisassemblyModel::PC_ADDRESS
private
Initial value:
=
Gtk::STATE_FLAG_DIR_LTR | Gtk::STATE_FLAG_ACTIVE

The CSS state flags for if the memory row is currently stored in the Program Counter.

Definition at line 61 of file DisassemblyModel.h.

const Gtk::StateFlags DisassemblyModel::PC_ADDRESS_FOCUSED
private
Initial value:
= Gtk::STATE_FLAG_DIR_LTR |
Gtk::STATE_FLAG_FOCUSED |
Gtk::STATE_FLAG_ACTIVE

The CSS state flags for e memory row that has keyboard focus and is currently stored in the Program Counter.

Definition at line 74 of file DisassemblyModel.h.


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