Debian Codegraph @

assembler.h

raw symbols SCIP
1 /****************************************************************************
2 ** SASM - simple IDE for assembler development
3 ** Copyright (C) 2013 Dmitriy Manushin
4 ** Contact: site: http://dman95.github.io/SASM/
5 ** e-mail: [email protected]
6 **
7 ** This file is part of SASM.
8 **
9 ** SASM is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation, either version 3 of the License, or
12 ** (at your option) any later version.
13 **
14 ** SASM is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with SASM. If not, see <http://www.gnu.org/licenses/>.
21 **
22 ** Этот файл — часть SASM.
23 **
24 ** SASM - свободная программа: вы можете перераспространять ее и/или
25 ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде,
26 ** в каком она была опубликована Фондом свободного программного обеспечения;
27 ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней
28 ** версии.
29 **
30 ** SASM распространяется в надежде, что она будет полезной,
31 ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
32 ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
33 ** общественной лицензии GNU.
34 **
35 ** Вы должны были получить копию Стандартной общественной лицензии GNU
36 ** вместе с этой программой. Если это не так, см.
37 ** <http://www.gnu.org/licenses/>.)
38 **
39 ****************************************************************************/
40
41 #ifndef ASSEMBLER_H
42 #define ASSEMBLER_H
43
44 #include <QObject>
45 #include <QMap>
46 #include <QList>
47 #include <QRegExp>
48 #include <QFile>
49 #include <QTextStream>
50 #include <QVector>
51 #include <QTextCharFormat>
52 #include <QSettings>
53 #include "common.h"
54 #include "codeeditor.h"
55
56 /**
57 * @file assembler.h
58 * Base class for creating assembler instances
59 */
60
61 /*! \brief This is the base class that all assemblers inherit
62 *
63 * The Assembler class contains functions which can be used to retrieve assember specific
64 * parameters such as the linker & assembler location, the default program text, and
65 * user specified options.
66 *
67 */
68
69 class Assembler : public QObject
70 {
71 Q_OBJECT
72 public:
73 /*!
74 * \brief Struct for setting correspondence between
75 * program text line numbers and addresses in memory
76 */
77 struct LineNum {
78 //! Program text line number
79 quint64 numInCode;
80 //! Address of instruction on this line in memory
81 quint64 numInMem;
82 bool operator ==(const LineNum& ln)
83 {
84 return ln.numInCode == numInCode;
85 }
86 };
87 /*!
88 * \brief Struct for setting pattern's highlighting rules
89 */
90 struct HighlightingRule
91 {
92 HighlightingRule() : isComment(false) {
93 }
94 //! Pattern to highlight
95 QRegExp pattern;
96 //! Highlighting format - foreground color, background color, bold style and etc.
97 QTextCharFormat format;
98 bool isComment;
99 };
100 bool x86;
101
102 //! Assembler constructor. Note that this is the stage where x86 is determined.
103 explicit Assembler(bool x86, QObject *parent = 0);
104
105 //! Return the default path to the assembler.
106 virtual QString getAssemblerPath() = 0;
107
108 //! Returns the default path to the linker.
109 virtual QString getLinkerPath() = 0;
110
111 /*!
112 * \brief Get entry point offset in object file.
113 * \param lst listing file
114 * \param entryLabel entry point label name - main or start
115 * \return entry point address in object file
116 */
117 virtual quint64 getMainOffset(QFile &lst, QString entryLabel) = 0;
118
119 /*!
120 * \brief Parses the listing file \a lst and fills vector \a lines with results of parsing
121 * \param lst listing file
122 * \param lines vector with info to fill
123 * \param offset difference between address of instruction in object file
124 * and address of instruction in memory
125 */
126 virtual void parseLstFile(QFile &lst,
127 QVector<Assembler::LineNum> &lines,
128 quint64 offset) = 0;
129
130 /*!
131 * \brief Sets highlighting for assembly listing
132 * \param highlightingRules highlighting rules to fill
133 * \param formats formats for different types of highlighted expressions
134 * (see NASM, MASM, FASM, GAS as examples)
135 * \param multiLineComments is needed to support multiline comments
136 * \param commentStartExpression multiline comment start ("/" + "*" in C for example)
137 * \param commentEndExpression multiline comment end ("*" + "/" in C for example)
138 */
139 virtual void fillHighligherRules(QVector<Assembler::HighlightingRule> &highlightingRules,
140 QList<QTextCharFormat *> &formats,
141 bool &multiLineComments,
142 QRegExp &commentStartExpression,
143 QRegExp &commentEndExpression) = 0;
144
145 //! Returns the default start text (default project code)
146 virtual QString getStartText() = 0;
147
148 //! Puts the debug string that makes frame (mov ebp, esp)
149 virtual void putDebugString(CodeEditor *code) = 0;
150
151 //! Returns the default assembler options
152 virtual QString getAssemblerOptions() = 0;
153
154 //! Returns the default linker options
155 virtual QString getLinkerOptions() = 0;
156
157 //! Determines if the system is x86
158 bool isx86();
159
160 signals:
161
162 public slots:
163
164 };
165
166 #endif // ASSEMBLER_H
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 /*! \mainpage SASM Dev Guide
182 *
183 * \section intro_sec Introduction
184 *
185 * Below you will find what and where to modify appropriate header and source files when you want to add a feature.
186 *
187 * \section section1 Commenting
188 *
189 * When commenting use doxygen's syntax. Place the comment above the intended line. After adding the feature, run
190 * doxygen.exe configfile to update the documentation. Be sure to double check the documentation to ensure the
191 * added comments were parsed correctly.
192 *
193 * \section section2 Adding Assembler Support
194 *
195 * Adding support is a relatively straight forward process. Each supported assembler is a derived Assembler and
196 * has its own header and cpp file.
197 *
198 * \subsection step1 Step 1: Creating the header and cpp
199 *
200 * The first step is to create the new header and cpp file for the assembler. These should be named all lowercase without gaps
201 *
202 * \subsection step2 Step 2: Creating the assembler class
203 *
204 * The decleration of the class may best be discussed in light of already supported assemblers. Take for example, NASM. The NASM
205 * class is defined as:
206 * class NASM : public Assembler
207 *
208 * The generic definition is
209 * class YOURASSEMBLER : public Assembler
210 *
211 * The variables and methods of YOURASSEMBLER should be the virtual methods of Assembler. If you are unsure what to add, refer to
212 * the already supported assemler classes. You may copy and paste them.
213 *
214 * \subsection step3 Step 3: Adding it to the Build Options
215 *
216 * You should hopefully know enough QT to be able to add form controls. The code for modifying the build menu can be found in
217 * mainwindow.cpp. Refer to its documentation for more reference on where to add/modify code.
218 *
219 * \section section3 Adding Language Support
220 *
221 *
222 * \subsection help Help File
223 *
224 * The help file, helpENG.html, needs to be translated and saved into a new help<NEW LANGUAGE>.html file.
225 * The
226 * void MainWindow::openHelp()
227 * must be modified to support the added language. This is done by adding another if statement.
228 *
229 * \subsection interface Interface language
230 *
231 * New language_<new language>.ts file needs to be created and filled with translations using Qt Linguist.
232 * Compiled language_<new language>.qm and qt_<new_language>.qm files need to be added in SASM folder.
233 * Support of new language needs to be added in settings (mainwindow.cpp) and in loading code (main.cpp).
234 */
235
236
237
238
239
240
241