KoMo2  1.0.0
A modern ARM emulator GUI.
DisassemblyModel.h
Go to the documentation of this file.
1 
12 #include <string>
13 #include <unordered_map>
14 #include <vector>
15 #include "TerminalModel.h"
16 
17 class DisassemblyView;
18 class DisassemblyRows;
19 
23 class DisassemblyModel : private Model {
24  public:
26  void refreshViews();
27  DisassemblyView* const getView();
28  void setPCValue(const std::string val);
29 
30  // ! Virtual overrides
31  virtual void changeJimulatorState(const JimulatorState newState) override;
32  virtual const bool handleKeyPress(const GdkEventKey* const e) override;
33  void setEnglishMnemonic(const bool val);
34 
35  private:
40 
45  static uint32_t memoryIndex;
46 
50  std::string PCValue = "0x00000000";
51 
55  const Gtk::StateFlags NORMAL = Gtk::STATE_FLAG_DIR_LTR;
56 
61  const Gtk::StateFlags PC_ADDRESS =
62  Gtk::STATE_FLAG_DIR_LTR | Gtk::STATE_FLAG_ACTIVE;
63 
67  const Gtk::StateFlags FOCUSED =
68  Gtk::STATE_FLAG_DIR_LTR | Gtk::STATE_FLAG_FOCUSED;
69 
74  const Gtk::StateFlags PC_ADDRESS_FOCUSED = Gtk::STATE_FLAG_DIR_LTR |
75  Gtk::STATE_FLAG_FOCUSED |
76  Gtk::STATE_FLAG_ACTIVE;
77 
90  const std::unordered_map<std::string, std::string> mnemonicsMap = {
91  // SWI
92  {"swi 0", "Printing character"},
93  {"swi 1", "Reading character"},
94  {"swi 2", "Halting execution"},
95  {"swi 3", "Printing string"},
96  {"swi 4", "Printing integer"},
97  // 1 paramter
98  {"defw", "defined as integer ?1?"},
99  {"defb", "Defined as string ?1?"},
100  {"beq", "Branch to label ?1? if equal"},
101  {"blt", "Branch to label ?1? if less than"},
102  {"bne", "Branch to label ?1? if not equal"},
103  {"bgt", "Branch to label ?1? if greater than"},
104  {"b", "Branch to label ?1?"},
105  // 2 paramters
106  {"mov", "Move ?2? into ?1?"},
107  {"adr", "Value at ?2? moves into ?1?"},
108  {"adrl", "Value at ?2? moves into ?1?"},
109  {"cmp", "Compare ?1? to ?2?"},
110  {"cmn", "Negatively compare ?1? to ?2?"},
111  {"str", "Store ?1? in ?2?"},
112  {"ldr", "Stores ?2? in ?1?"},
113  // 3 paramters
114  {"sub", "Subtract ?3? from ?2? and store in ?1?"},
115  {"add", "Add ?3? to ?2? and store in ?1?"},
116  {"mul", "Multiply ?3? with ?2? and store in ?1?"},
117  {"and", "bitwise and ?2? with ?3? and store in ?1?"},
118  {"orr", "bitwise or ?2? with ?3? and store in ?1?"},
119  // 4 paramters
120  {"mla", "Multiply ?2? with ?3? , add ?4? and store in ?1?"},
121  {"mls", "Multiply ?2? with ?3? , subtract ?4? and store in ?1?"}};
122 
127  bool englishMnemonic = false;
128 
129  const std::string intToFormattedHexString(const uint32_t formatMe) const;
130  const bool handleScroll(GdkEventScroll* const e);
131  void incrementMemoryIndex(const uint32_t val);
132  void addScrollRecognition();
133  const std::array<Jimulator::MemoryValues, 13> getMemoryValues() const;
134  void onBreakpointToggle(DisassemblyRows* const row);
135  void setupButtonHandlers();
136  void updateCSSFlags(const Gtk::StateFlags state,
137  DisassemblyRows& row,
138  const uint32_t address);
139  const std::string buildDisassemblyRowAccessibilityString(
140  DisassemblyRows& val);
141  const std::string convertMnemonicToEnglish(const std::string mnemonic) const;
142  const std::string sanitizeParamters(std::string param) const;
143  const std::string toLowerCase(std::string s) const;
144  const std::vector<std::string> parseDEFB(std::vector<std::string> v) const;
145  const std::vector<std::string> parseSWI(std::vector<std::string> m) const;
146  const std::pair<std::vector<std::string>, std::string> parseLabel(
147  std::vector<std::string> m) const;
148  const std::string buildMnemonicString(std::string s,
149  std::vector<std::string> m) const;
150 
151  // ! Deleted special member functions
152  // stops these functions from being misused, creates a sensible error
153  DisassemblyModel(const DisassemblyModel&) = delete;
154  DisassemblyModel(const DisassemblyModel&&) = delete;
155  DisassemblyModel& operator=(const DisassemblyModel&) = delete;
156  DisassemblyModel& operator=(const DisassemblyModel&&) = delete;
157 };
void setEnglishMnemonic(const bool val)
Set the value of the englishMnemonic member variable.
The declaration of the DisassemblyModel class.
const Gtk::StateFlags NORMAL
The CSS state flags for an un-highlighted memory row.
A single instance of this class represents a single read memory address and the associated data - thi...
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles any key press events.
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 C...
const Gtk::StateFlags FOCUSED
The CSS state flags for a memory row that has keyboard focus.
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 ...
DisassemblyModel(DisassemblyView *const view, KoMo2Model *const parent)
Construct a new DisassemblyModel::DisassemblyModel object.
KoMo2Model *const parent
All models have a parent model - KoMo2Model, the most senior model in the hierarchy, sets its parent to self.
Definition: Model.h:87
const std::string toLowerCase(std::string s) const
Converts a string to lower case.
void onBreakpointToggle(DisassemblyRows *const row)
Handle the toggling of a breakpoint within the DisassemblyView.
bool englishMnemonic
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.
const std::string intToFormattedHexString(const uint32_t formatMe) const
Converts a fixed width 32-bit integer to a hex string, padded with 0&#39;s to 8 characters, pre-fixed with "0x", and raised to all capitals.
JimulatorState
Describe the 5 states of Jimulator.
Definition: Model.h:19
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 re...
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 ...
DisassemblyView *const view
The view this model represents.
static uint32_t memoryIndex
Fixed width integer representing the memory address of the view at the top of the container...
The superclass for all other Model classes. Uses a pure virtual function, so is abastract. Keeps KoMo2Model as a friend so it alone can call setJimulatorState. This class provides basic data that are needed by all other.
Definition: Model.h:35
const Gtk::StateFlags PC_ADDRESS
The CSS state flags for if the memory row is currently stored in the Program Counter.
void refreshViews()
Refreshes the values in the views to display the new values fetched from Jimulator.
const std::string sanitizeParamters(std::string param) const
Sanitizes any of the paramters used with an ARM mnemonic.
virtual void changeJimulatorState(const JimulatorState newState) override
Handles changes of Jimulator state.
const std::string buildDisassemblyRowAccessibilityString(DisassemblyRows &val)
Generates the string to set for the accessibility model.
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...
The file containing the declaration of the class TerminalModel, which represents all of the data and ...
std::string PCValue
Stores the value currently in the program counter.
const std::string convertMnemonicToEnglish(const std::string mnemonic) const
Converts a mnemonic into plain English.
The logical model of the entire application. All other models should be member variables of this mode...
Definition: KoMo2Model.h:34
Represents the entire disassembly window in the overall KoMo2 GUI. Contains several rows of memory va...
void addScrollRecognition()
Adds scroll recognition to the container object, which causes scroll events to be sent to the member ...
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 betwe...
const std::array< Jimulator::MemoryValues, 13 > getMemoryValues() const
Reads memory values from Jimulator.
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...
void setPCValue(const std::string val)
Updates the value of PCValue.
const bool handleScroll(GdkEventScroll *const e)
Handles the scroll events.
DisassemblyView *const getView()
Returns a pointer to the view object.
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 thing...