Debian Codegraph @

masm.cpp

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 #include "masm.h"
42
43 /**
44 * @file masm.cpp
45 * Implements the MASM Assembler
46 */
47
48
49 //! Windows only!
50
51 MASM::MASM(bool x86, QObject *parent) :
52 Assembler(x86, parent)
53 {
54 #ifndef Q_OS_WIN32
55 QMessageBox::critical(0, tr("Error!"), tr("MASM is available on Windows only."));
56 #else
57 if (!x86) {
58 QMessageBox::critical(0, tr("Error!"), tr("Only 32-bit version of MASM is available."));
59 }
60 #endif
61 }
62
63 QString MASM::getAssemblerPath()
64 {
65 return "C:/masm32/bin/ml.exe";
66 }
67
68 QString MASM::getLinkerPath()
69 {
70 return "C:/masm32/bin/link.exe";
71 }
72
73 quint64 MASM::getMainOffset(QFile &lst, QString entryLabel)
74 {
75 QTextStream lstStream(&lst);
76 QRegExp mainLabel(" [0-9a-fA-F]{8,16}.*" + entryLabel + ":.*");
77 QRegExp empty1("\t\t\t C.*");
78 QRegExp empty2(" *;.*");
79 while (!lstStream.atEnd()) {
80 QString line = lstStream.readLine();
81 if (empty1.exactMatch(line))
82 continue;
83 if (empty2.exactMatch(line))
84 continue;
85 if (!mainLabel.exactMatch(line))
86 continue;
87 QByteArray lineArr = line.toLocal8Bit();
88 const char *s = lineArr.constData();
89 quint64 a;
90 if (sscanf(s, "%llx", &a) == 1) {
91 return a;
92 }
93 }
94 return -1;
95 }
96
97 void MASM::parseLstFile(QFile &lst, QVector<Assembler::LineNum> &lines, quint64 offset)
98 {
99 QTextStream lstStream(&lst);
100 QList<QPair<quint64, QString> > instrList;
101 bool inTextSection = false;
102 QRegExp sectionTextRegExp("\\.code");
103 sectionTextRegExp.setCaseSensitivity(Qt::CaseInsensitive);
104 QRegExp sectionDataRegExp("\\.(data|fardata|const)");
105 sectionDataRegExp.setCaseSensitivity(Qt::CaseInsensitive);
106 QRegExp empty1("\t\t\t C.*");
107 QRegExp empty2(" *;.*");
108 QRegExp stringWithCode(" [0-9a-fA-F]{8,16} +[0-9a-fA-F]{1,16}.*");
109 QRegExp stringWithAddress(" [0-9a-fA-F]{8,16}.*");
110 QRegExp macroBegin("[\t0-9a-fA-FRE ]+1\t.*");
111 QRegExp macro("[\t0-9a-fA-FRE ]+ +[1-9]\t.*");
112 QString mayBeMacro, line, macroInstruction;
113 bool inMacro = false;
114 while (!lstStream.atEnd()) {
115 line = lstStream.readLine();
116 if (empty1.exactMatch(line))
117 continue;
118 if (empty2.exactMatch(line))
119 continue;
120 if (line.indexOf(sectionTextRegExp) != -1) {
121 inTextSection = true;
122 } else if (line.indexOf(sectionDataRegExp) != -1) {
123 inTextSection = false;
124 }
125 if (inTextSection) {
126 QByteArray lineArr = line.toLocal8Bit();
127 const char *s = lineArr.constData();
128 quint64 a;
129
130 //! Check if invoke
131 if (line.contains("invoke", Qt::CaseInsensitive)) {
132 macroInstruction = line;
133 if (macro.exactMatch(macroInstruction))
134 continue;
135 int k = 0;
136 while (k < macroInstruction.length() && macroInstruction[k].isSpace())
137 k++;
138 macroInstruction.remove(0, k);
139 if (macroInstruction[0] == '=')
140 continue;
141 macroInstruction.remove(QRegExp("^[0-9a-fA-F]{8,16}[ \t]+")); //if label
142 while (!stringWithAddress.exactMatch(line) && !lstStream.atEnd())
143 line = lstStream.readLine();
144 lineArr = line.toLocal8Bit();
145 s = lineArr.constData();
146 if (sscanf(s, "%llx", &a) == 1) {
147 instrList.append(QPair<quint64, QString>(a + offset, macroInstruction));
148 macroInstruction.clear();
149 }
150 continue;
151 }
152
153 //! Check if return
154 if (line.contains("return", Qt::CaseInsensitive)) {
155 macroInstruction = line;
156 if (macro.exactMatch(macroInstruction))
157 continue;
158 int k = 0;
159 while (k < macroInstruction.length() && macroInstruction[k].isSpace())
160 k++;
161 macroInstruction.remove(0, k);
162 macroInstruction.remove(QRegExp("^[0-9a-fA-F]{8,16}[ \t]+")); //if label
163 while (!stringWithAddress.exactMatch(line) && !lstStream.atEnd())
164 line = lstStream.readLine();
165 lineArr = line.toLocal8Bit();
166 s = lineArr.constData();
167 if (sscanf(s, "%llx", &a) == 1) {
168 instrList.append(QPair<quint64, QString>(a + offset, macroInstruction));
169 macroInstruction.clear();
170 }
171 continue;
172 }
173
174 //! Check if macro
175 if (line.startsWith("\t\t\t\t")) {
176 mayBeMacro = line;
177 int k = 0;
178 while (k < mayBeMacro.length() && mayBeMacro[k].isSpace())
179 k++;
180 mayBeMacro.remove(0, k);
181 continue;
182 }
183 //! If previous may be macro - switch to finding macro start address mode
184 if (!mayBeMacro.isEmpty() && !inMacro) {
185 if (macroBegin.exactMatch(line)) {
186 inMacro = true;
187 } else {
188 mayBeMacro.clear();
189 }
190 }
191 //! If in macro, find its start address
192 if (inMacro && stringWithCode.exactMatch(line) && sscanf(s, "%llx", &a) == 1) {
193
194 instrList.append(QPair<quint64, QString>(a + offset, mayBeMacro));
195 mayBeMacro.clear();
196 inMacro = false;
197 }
198
199 //! Check if instruction
200 if (!stringWithCode.exactMatch(line) || macro.exactMatch(line) || sscanf(s, "%llx", &a) != 1)
201 continue;
202 int index = line.indexOf(QRegExp("[RE\t]\t"));
203 if (index == -1)
204 continue;
205 line = line.mid(index + 2);
206 int k = 0;
207 while (k < line.length() && line[k].isSpace())
208 k++;
209 line.remove(0, k);
210 if (line[0] == '*')
211 continue;
212 instrList.append(QPair<quint64, QString>(a + offset, line));
213 }
214 }
215 lst.close();
216
217 QFile programFile(Common::pathInTemp("program.asm"));
218 programFile.open(QFile::ReadOnly);
219 QTextStream programStream(&programFile);
220 QList<QPair<quint64, QString> > programList;
221 int numInCode = 0;
222 while (!programStream.atEnd()) {
223 QString line = programStream.readLine();
224 numInCode++;
225 int k = 0;
226 while (k < line.length() && line[k].isSpace())
227 k++;
228 line.remove(0, k);
229 programList.append(QPair<quint64, QString>(numInCode, line));
230 }
231 //! Offset in instrList
232 int i = 0;
233 //! Offset in programList
234 int j = 0;
235 int lastSeenInProgramList = 0;
236 while (i < instrList.size()) {
237 if (programList[j].second == instrList[i].second) {
238 LineNum l;
239 l.numInCode = programList[j].first;
240 l.numInMem = instrList[i].first;
241 lines.append(l);
242 i++;
243 lastSeenInProgramList = j;
244 }
245 j++;
246 //! If true, skip line in instrList and back to first unwatched line in programList
247 if (j >= programList.size()) {
248 i++;
249 j = lastSeenInProgramList + 1;
250 }
251 }
252 programFile.close();
253 }
254
255 QString MASM::getStartText()
256 {
257 return QString(".386\n.model flat, stdcall\noption casemap : none\n.code\nstart:\n") +
258 QString(" ;write your code here\n xor eax, eax\n ret\n end start\n");
259 }
260
261 void MASM::putDebugString(CodeEditor *)
262 {
263 }
264
265 QString MASM::getAssemblerOptions()
266 {
267 return "/nologo /Sn /Sa /c /coff /Fo$PROGRAM.OBJ$ /Fl$LSTOUTPUT$ $SOURCE$";
268 }
269
270 QString MASM::getLinkerOptions()
271 {
272 return "/SUBSYSTEM:CONSOLE /OPT:NOREF /NOLOGO /OUT:$PROGRAM$ $PROGRAM.OBJ$";
273 }
274
275 void MASM::fillHighligherRules(QVector<Assembler::HighlightingRule> &highlightingRules,
276 QList<QTextCharFormat *> &formats,
277 bool &multiLineComments,
278 QRegExp &commentStartExpression,
279 QRegExp &commentEndExpression)
280 {
281 typedef Assembler::HighlightingRule HighlightingRule;
282 QTextCharFormat &keywordFormat = *formats[0];
283 QTextCharFormat &registerFormat = *formats[1];
284 QTextCharFormat &numberFormat = *formats[2];
285 QTextCharFormat &memoryFormat = *formats[3];
286 QTextCharFormat &labelFormat = *formats[4];
287 QTextCharFormat &commentFormat = *formats[5];
288 QTextCharFormat &systemFormat = *formats[6];
289 //QTextCharFormat &iomacrosFormat = *formats[7];
290 QTextCharFormat &quotationFormat = *formats[8];
291 QTextCharFormat &labelWithDotFormat = *formats[9];
292
293 //! Setting up regular expressions
294 HighlightingRule rule;
295
296 //! Keywords
297 QStringList keywordPatterns;
298 keywordPatterns << "\\bAAA\\b" << "\\bAAD\\b" << "\\bAAM\\b" << "\\bAAS\\b" <<
299 "\\bADC\\b" << "\\bADD\\b" << "\\bAND\\b" << "\\bCALL\\b" <<
300 "\\bCBW\\b" << "\\bCLC\\b" << "\\bCLD\\b" << "\\bCLI\\b" <<
301 "\\bCMC\\b" << "\\bCMP\\b" << "\\bCMPSB\\b" << "\\bCMPSW\\b" <<
302 "\\bCWD\\b" << "\\bDAA\\b" << "\\bDAS\\b" << "\\bDEC\\b" <<
303 "\\bDIV\\b" << "\\bESC\\b" << "\\bHLT\\b" << "\\bIDIV\\b" <<
304 "\\bIMUL\\b" << "\\bIN\\b" << "\\bINC\\b" << "\\bINT\\b" <<
305 "\\bINTO\\b" << "\\bIRET\\b" << "\\bJA\\b" << "\\bJAE\\b" <<
306 "\\bJB\\b" << "\\bJBE\\b" << "\\bJC\\b" << "\\bJCXZ\\b" <<
307 "\\bJE\\b" << "\\bJG\\b" << "\\bJGE\\b" << "\\bJL\\b" <<
308 "\\bJLE\\b" << "\\bJNA\\b" << "\\bJNAE\\b" << "\\bJNB\\b" <<
309 "\\bJNBE\\b" << "\\bJNC\\b" << "\\bJNE\\b" << "\\bJNG\\b" <<
310 "\\bJNGE\\b" << "\\bJNL\\b" << "\\bJNLE\\b" << "\\bJNO\\b" <<
311 "\\bJNP\\b" << "\\bJNS\\b" << "\\bJNZ\\b" << "\\bJO\\b" <<
312 "\\bJP\\b" << "\\bJPE\\b" << "\\bJPO\\b" << "\\bJS\\b" <<
313 "\\bJZ\\b" << "\\bJMP\\b" << "\\bLAHF\\b" << "\\bLDS\\b" <<
314 "\\bLEA\\b" << "\\bLES\\b" << "\\bLOCK\\b" << "\\bLODSB\\b" <<
315 "\\bLODSW\\b" << "\\bLOOP\\b" << "\\bLOOPE\\b" << "\\bLOOPNE\\b" <<
316 "\\bLOOPNZ\\b" << "\\bLOOPZ\\b" << "\\bMOV\\b" << "\\bMOVSB\\b" <<
317 "\\bMOVSW\\b" << "\\bMUL\\b" << "\\bNEG\\b" << "\\bNOP\\b" <<
318 "\\bNOT\\b" << "\\bOR\\b" << "\\bOUT\\b" << "\\bPOP\\b" <<
319 "\\bPOPF\\b" << "\\bPUSH\\b" << "\\bPUSHF\\b" << "\\bRCL\\b" <<
320 "\\bRCR\\b" << "\\bREP\\b" << "\\bREPE\\b" << "\\bREPNE\\b" <<
321 "\\bREPNZ\\b" << "\\bREPZ\\b" << "\\bRET\\b" << "\\bRETN\\b" <<
322 "\\bRETF\\b" << "\\bROL\\b" << "\\bROR\\b" << "\\bSAHF\\b" <<
323 "\\bSAL\\b" << "\\bSAR\\b" << "\\bSBB\\b" << "\\bSCASB\\b" <<
324 "\\bSCASW\\b" << "\\bSHL\\b" << "\\bSHR\\b" << "\\bSTC\\b" <<
325 "\\bSTD\\b" << "\\bSTI\\b" << "\\bSTOSB\\b" << "\\bSTOSW\\b" <<
326 "\\bSUB\\b" << "\\bTEST\\b" << "\\bWAIT\\b" << "\\bXCHG\\b" <<
327 "\\bXLAT\\b" << "\\bXOR\\b" << "\\bBOUND\\b" << "\\bENTER\\b" <<
328 "\\bINS\\b" << "\\bLEAVE\\b" << "\\bOUTS\\b" << "\\bPOPA\\b" <<
329 "\\bPUSHA\\b" << "\\bARPL\\b" << "\\bCLTS\\b" << "\\bLAR\\b" <<
330 "\\bLGDT\\b" << "\\bLIDT\\b" << "\\bLLDT\\b" << "\\bLMSW\\b" <<
331 "\\bLOADALL\\b" << "\\bLSL\\b" << "\\bLTR\\b" << "\\bSGDT\\b" <<
332 "\\bSIDT\\b" << "\\bSLDT\\b" << "\\bSMSW\\b" << "\\bSTR\\b" <<
333 "\\bVERR\\b" << "\\bVERW\\b" << "\\bBSF\\b" << "\\bBSR\\b" <<
334 "\\bBT\\b" << "\\bBTC\\b" << "\\bBTR\\b" << "\\bBTS\\b" <<
335 "\\bCDQ\\b" << "\\bCMPSD\\b" << "\\bCWDE\\b" << "\\bINSD\\b" <<
336 "\\bIRET\\b" << "\\bIRETW\\b" << "\\bIRETD\\b" << "\\bJCXZ\\b" <<
337 "\\bJECXZ\\b" << "\\bLFS\\b" << "\\bLGS\\b" << "\\bLSS\\b" <<
338 "\\bLODSD\\b" << "\\bMOVSD\\b" << "\\bMOVSX\\b" << "\\bMOVZX\\b" <<
339 "\\bOUTSD\\b" << "\\bPOPAD\\b" << "\\bPOPFD\\b" << "\\bPUSHAD\\b" <<
340 "\\bPUSHFD\\b" << "\\bSCASD\\b" << "\\bSETA\\b" << "\\bSETAE\\b" <<
341 "\\bSETB\\b" << "\\bSETBE\\b" << "\\bSETC\\b" << "\\bSETE\\b" <<
342 "\\bSETG\\b" << "\\bSETGE\\b" << "\\bSETL\\b" << "\\bSETLE\\b" <<
343 "\\bSETNA\\b" << "\\bSETNAE\\b" << "\\bSETNB\\b" << "\\bSETNBE\\b" <<
344 "\\bSETNC\\b" << "\\bSETNE\\b" << "\\bSETNG\\b" << "\\bSETNGE\\b" <<
345 "\\bSETNL\\b" << "\\bSETNLE\\b" << "\\bSETNO\\b" << "\\bSETNP\\b" <<
346 "\\bSETNS\\b" << "\\bSETNZ\\b" << "\\bSETO\\b" << "\\bSETP\\b" <<
347 "\\bSETPE\\b" << "\\bSETPO\\b" << "\\bSETS\\b" << "\\bSETZ\\b" <<
348 "\\bSHLD\\b" << "\\bSHRD\\b" << "\\bSTOSD\\b" <<
349 "\\bPOPAD\\b" << "\\bPOPFD\\b" << "\\bPUSHAD\\b" << "\\bPUSHFD\\b" <<
350 "\\bSCASD\\b" << "\\bBSWAP\\b" << "\\bCMPXCHG\\b" << "\\bINVD\\b" <<
351 "\\bINVLPG\\b" << "\\bWBINVD\\b" << "\\bXADD\\b" << "\\bCPUID\\b" <<
352 "\\bCMPXCHG8B\\b" << "\\bRDMSR\\b" << "\\bRDTSC\\b" << "\\bWRMSR\\b" <<
353 "\\bRSM\\b" << "\\bRDPMC\\b" << "\\bCMOVA\\b" << "\\bCMOVAE\\b" <<
354 "\\bCMOVB\\b" << "\\bCMOVBE\\b" << "\\bCMOVC\\b" << "\\bCMOVE\\b" <<
355 "\\bCMOVG\\b" << "\\bCMOVGE\\b" << "\\bCMOVL\\b" << "\\bCMOVLE\\b" <<
356 "\\bCMOVNA\\b" << "\\bCMOVNAE\\b" << "\\bCMOVNB\\b" << "\\bCMOVNBE\\b" <<
357 "\\bCMOVNC\\b" << "\\bCMOVNE\\b" << "\\bCMOVNG\\b" << "\\bCMOVNGE\\b" <<
358 "\\bCMOVNL\\b" << "\\bCMOVNLE\\b" << "\\bCMOVNO\\b" << "\\bCMOVNP\\b" <<
359 "\\bCMOVNS\\b" << "\\bCMOVNZ\\b" << "\\bCMOVO\\b" << "\\bCMOVP\\b" <<
360 "\\bCMOVPE\\b" << "\\bCMOVPO\\b" << "\\bCMOVS\\b" << "\\bCMOVZ\\b" <<
361 "\\bF2XM1\\b" << "\\bFABS\\b" << "\\bFADD\\b" << "\\bFADDP\\b" <<
362 "\\bFBLD\\b" << "\\bFBSTP\\b" << "\\bFCHS\\b" << "\\bFCLEX\\b" <<
363 "\\bFCOM\\b" << "\\bFCOMP\\b" << "\\bFCOMPP\\b" << "\\bFDECSTP\\b" <<
364 "\\bFDISI\\b" << "\\bFDIV\\b" << "\\bFDIVP\\b" << "\\bFDIVR\\b" <<
365 "\\bFDIVRP\\b" << "\\bFENI\\b" << "\\bFFREE\\b" << "\\bFIADD\\b" <<
366 "\\bFICOM\\b" << "\\bFICOMP\\b" << "\\bFIDIV\\b" << "\\bFIDIVR\\b" <<
367 "\\bFILD\\b" << "\\bFIMUL\\b" << "\\bFINCSTP\\b" << "\\bFINIT\\b" <<
368 "\\bFIST\\b" << "\\bFISTP\\b" << "\\bFISUB\\b" << "\\bFISUBR\\b" <<
369 "\\bFLD\\b" << "\\bFLD1\\b" << "\\bFLDCW\\b" << "\\bFLDENV\\b" <<
370 "\\bFLDENVW\\b" << "\\bFLDL2E\\b" << "\\bFLDL2T\\b" << "\\bFLDLG2\\b" <<
371 "\\bFLDLN2\\b" << "\\bFLDPI\\b" << "\\bFLDZ\\b" << "\\bFMUL\\b" <<
372 "\\bFMULP\\b" << "\\bFNCLEX\\b" << "\\bFNDISI\\b" << "\\bFNENI\\b" <<
373 "\\bFNINIT\\b" << "\\bFNOP\\b" << "\\bFNSAVE\\b" << "\\bFNSAVEW\\b" <<
374 "\\bFNSTCW\\b" << "\\bFNSTENV\\b" << "\\bFNSTENVW\\b" << "\\bFNSTSW\\b" <<
375 "\\bFPATAN\\b" << "\\bFPREM\\b" << "\\bFPTAN\\b" << "\\bFRNDINT\\b" <<
376 "\\bFRSTOR\\b" << "\\bFRSTORW\\b" << "\\bFSAVE\\b" << "\\bFSAVEW\\b" <<
377 "\\bFSCALE\\b" << "\\bFSQRT\\b" << "\\bFST\\b" << "\\bFSTCW\\b" <<
378 "\\bFSTENV\\b" << "\\bFSTENVW\\b" << "\\bFSTP\\b" << "\\bFSTSW\\b" <<
379 "\\bFSUB\\b" << "\\bFSUBP\\b" << "\\bFSUBR\\b" << "\\bFSUBRP\\b" <<
380 "\\bFTST\\b" << "\\bFWAIT\\b" << "\\bFXAM\\b" << "\\bFXCH\\b" <<
381 "\\bFXTRACT\\b" << "\\bFYL2X\\b" << "\\bFYL2XP1\\b" << "\\bFSETPM\\b" <<
382 "\\bFCOS\\b" << "\\bFLDENVD\\b" << "\\bFSAVED\\b" << "\\bFSTENVD\\b" <<
383 "\\bFPREM1\\b" << "\\bFRSTORD\\b" << "\\bFSIN\\b" << "\\bFSINCOS\\b" <<
384 "\\bFSTENVD\\b" << "\\bFUCOM\\b" << "\\bFUCOMP\\b" << "\\bFUCOMPP\\b" <<
385 "\\bFCMOVB\\b" << "\\bFCMOVBE\\b" << "\\bFCMOVE\\b" << "\\bFCMOVNB\\b" <<
386 "\\bFCMOVNBE\\b" << "\\bFCMOVNE\\b" << "\\bFCMOVNU\\b" << "\\bFCMOVU\\b" <<
387 "\\bFCOMI\\b" << "\\bFCOMIP\\b" << "\\bFUCOMI\\b" << "\\bFUCOMIP\\b" <<
388 "\\bCDQE\\b" << "\\bCQO\\b" << "\\bMOVMSKPS\\b" << "\\bMOVMSKPD\\b" <<
389 "\\bPOPCNT\\b" << "\\bLZCNT\\b" << "\\bCMPSQ\\b" << "\\bSCASQ\\b" <<
390 "\\bMOVSQ\\b" << "\\bLODSQ\\b" << "\\bSTOSQ\\b" << "\\bJRCXZ\\b" <<
391 "\\bIRETQ\\b" << "\\bPUSHFQ\\b" << "\\bPOPFQ\\b" << "\\bCMPXCHG16B\\b" <<
392 "\\bJRCXZ\\b" << "\\bINSB\\b" << "\\bINSW\\b" << "\\bOUTSB\\b" <<
393 "\\bOUTSW\\b" << "\\bLFENCE\\b" << "\\bSFENCE\\b" << "\\bMFENCE\\b" <<
394 "\\bPREFETCH\\b" << "\\bPREFETCHL\\b" << "\\bPREFETCHW\\b" << "\\bCLFLUSH\\b" <<
395 "\\bSYSENTER\\b" << "\\bSYSEXIT\\b" << "\\bSYSCALL\\b" << "\\bSYSRET\\b";
396 foreach (const QString &pattern, keywordPatterns) {
397 rule.pattern = QRegExp(pattern);
398 rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
399 rule.format = keywordFormat;
400 highlightingRules.append(rule);
401 }
402
403 //! Labels
404 rule.pattern = QRegExp("\\S+:");
405 rule.format = labelFormat;
406 highlightingRules.append(rule);
407
408 //! Memory
409 rule.format = memoryFormat;
410 QStringList memoryPatterns;
411 rule.pattern = QRegExp("\\[");
412 highlightingRules.append(rule);
413 rule.pattern = QRegExp("\\]");
414 highlightingRules.append(rule);
415 memoryPatterns << "\\bddq\\b" <<
416 "\\bdb\\b" << "\\bdw\\b" << "\\bdd\\b" <<
417 "\\bdq\\b" << "\\bdt\\b" << "\\bdo\\b" <<
418 "\\bdy\\b" << "\\bequ\\b" << "\\bdf\\b" <<
419 "\\bptr\\b" <<
420 "\\bbyte\\b" << "\\bword\\b" <<
421 "\\bdword\\b" << "\\bqword\\b" <<
422 "\\btword\\b" << "\\boword\\b" <<
423 "\\byword\\b" << "\\bfword\\b" <<
424 "\\bmmword\\b" << "\\bsdword\\b" <<
425 "\\bsqword\\b" << "\\bsword\\b" <<
426 "\\bxmmword\\b" << "\\bymmword\\b" <<
427 "\\bsbyte\\b" << "\\btbyte\\b" <<
428 "\\bDEFAULT\\b" <<
429 "\\bABS\\b" << "\\bREL\\b";
430 foreach (const QString &pattern, memoryPatterns) {
431 rule.pattern = QRegExp(pattern);
432 rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
433 highlightingRules.append(rule);
434 }
435
436 //! Numbers
437 rule.format = numberFormat;
438 rule.pattern = QRegExp("\\b[\\-\\+]?\\d+[bod]?\\b");
439 highlightingRules.append(rule);
440 rule.pattern = QRegExp("\\b0[bo]\\d+\\b");
441 highlightingRules.append(rule);
442 //! Hexadecimal notation
443 rule.pattern = QRegExp("\\b[0-9A-Fa-f]+h\\b");
444 highlightingRules.append(rule);
445 //! Hexadecimal notation
446 rule.pattern = QRegExp("\\b0[xh][0-9A-Fa-f]+\\b");
447 highlightingRules.append(rule);
448
449 //registers
450 QStringList registerPatterns;
451 registerPatterns << "\\beax\\b" << "\\bebx\\b" << "\\becx\\b" <<
452 "\\bedx\\b" << "\\bebp\\b" << "\\besp\\b" <<
453 "\\bedi\\b" << "\\besi\\b" << "\\bax\\b" <<
454 "\\bbx\\b" << "\\bcx\\b" << "\\bdx\\b" <<
455 "\\bbp\\b" << "\\bsp\\b" << "\\bsi\\b" <<
456 "\\bdi\\b" << "\\bal\\b" << "\\bah\\b" <<
457 "\\bbl\\b" << "\\bbh\\b" << "\\bcl\\b" <<
458 "\\bch\\b" << "\\bdl\\b" << "\\bdh\\b" <<
459 "\\brax\\b" << "\\brbx\\b" << "\\brcx\\b" << //x64
460 "\\brdx\\b" << "\\brbp\\b" << "\\brsp\\b" <<
461 "\\brdi\\b" << "\\brsi\\b" << "\\bspl\\b" <<
462 "\\bbpl\\b" << "\\bsil\\b" << "\\bdil\\b" <<
463 "\\br8\\b" << "\\br8d\\b" << "\\br8w\\b" <<
464 "\\br8b\\b" << "\\br9\\b" << "\\br9d\\b" <<
465 "\\br9w\\b" << "\\br9b\\b" << "\\br10\\b" <<
466 "\\br10d\\b" << "\\br10w\\b" << "\\br10b\\b" <<
467 "\\br11\\b" << "\\br11d\\b" << "\\br11w\\b" <<
468 "\\br11b\\b" << "\\br12\\b" << "\\br12d\\b" <<
469 "\\br12w\\b" << "\\br12b\\b" << "\\br13\\b" <<
470 "\\br13d\\b" << "\\br13w\\b" << "\\br13b\\b" <<
471 "\\br14\\b" << "\\br14d\\b" << "\\br14w\\b" <<
472 "\\br14b\\b" << "\\br15\\b" << "\\br15d\\b" <<
473 "\\br15w\\b" << "\\br15b\\b";
474 foreach (const QString &pattern, registerPatterns) {
475 rule.pattern = QRegExp(pattern);
476 rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
477 rule.format = registerFormat;
478 highlightingRules.append(rule);
479 }
480
481 //! .labels and numbers with point
482 rule.pattern = QRegExp("\\.[^\\s:]+[^:]");
483 rule.format = labelWithDotFormat;
484 highlightingRules.append(rule);
485 rule.pattern = QRegExp("\\.[^\\s:]+:");
486 rule.format = labelFormat;
487 highlightingRules.append(rule);
488 rule.pattern = QRegExp("\\b[\\-\\+]?\\d+\\.\\d+\\b");
489 rule.format = numberFormat;
490 highlightingRules.append(rule);
491
492 //! System instructions and preprocessor commands
493 rule.format = systemFormat;
494 QStringList systemPatterns;
495 systemPatterns << "\\s\\.\\w+\\b" << "^\\.\\w+\\b" << "\\bSEGMENT\\b" << "\\bPUBLIC\\b" <<
496 "\\bEXTERN\\b" << "\\bEXTRN\\b" <<
497 "\\bALIAS\\b" << "\\bALIGN\\b" << "\\bASSUME\\b" <<
498 "\\bCATSTR\\b" << "\\bCOMM\\b" << "\\bCOMMENT\\b" <<
499 "\\bDOSSEG\\b" << "\\bECHO\\b" << "\\bELSE\\b" <<
500 "\\bELSEIF\\b" << "\\bELSEIF2\\b" << "\\bEND\\b" <<
501 "\\bENDM\\b" << "\\bENDP\\b" << "\\bENDS\\b" <<
502 "\\bEVEN\\b" << "\\bEXITM\\b" << "\\bEXTERNDEF\\b" <<
503 "\\bFOR\\b" << "\\bFORC\\b" << "\\bGOTO\\b" <<
504 "\\bGROUP\\b" << "\\bIF\\b" << "\\bIF2\\b" <<
505 "\\bIFB\\b" << "\\bIFDEF\\b" << "\\bIFDIF\\b" <<
506 "\\bIFE\\b" << "\\bIFIDN\\b" << "\\bIFNB\\b" <<
507 "\\bIFNDEF\\b" << "\\bINCLUDE\\b" << "\\bINCLUDELIB\\b" <<
508 "\\bINSTR\\b" << "\\bINVOKE\\b" << "\\bIRP\\b" <<
509 "\\bIRPC\\b" << "\\bLABEL\\b" << "\\bLOCAL\\b" <<
510 "\\bMACRO\\b" << "\\bNAME\\b" << "\\bOPTION\\b" <<
511 "\\bORG\\b" << "\\b%OUT\\b" << "\\bPAGE\\b" <<
512 "\\bPOPCONTEXT\\b" << "\\bPROC\\b" << "\\bPROTO\\b" <<
513 "\\bPURGE\\b" << "\\bPUSHCONTEXT\\b" << "\\bREAL10\\b" <<
514 "\\bREAL4\\b" << "\\bREAL8\\b" << "\\bRECORD\\b" <<
515 "\\bREPEAT\\b" << "\\bREPT\\b" << "\\bSIZESTR\\b" <<
516 "\\bSTRUC\\b" << "\\bSTRUCT\\b" << "\\bSUBSTR\\b" <<
517 "\\bSUBTITLE\\b" << "\\bSUBTTL\\b" << "\\bTEXTEQU\\b" <<
518 "\\bTITLE\\b" << "\\bTYPEDEF\\b" << "\\bUNION\\b" <<
519 "\\bWHILE\\b";
520 foreach (const QString &pattern, systemPatterns) {
521 rule.pattern = QRegExp(pattern);
522 rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
523 highlightingRules.append(rule);
524 }
525
526 //quotations
527 rule.pattern = QRegExp("\".*\"");
528 rule.format = quotationFormat;
529 rule.pattern.setMinimal(true);
530 highlightingRules.append(rule);
531
532 rule.pattern = QRegExp("'.*'");
533 rule.pattern.setMinimal(true);
534 highlightingRules.append(rule);
535
536 //comments
537 rule.pattern = QRegExp(";[^\n]*");
538 rule.isComment = true;
539 rule.format = commentFormat;
540 highlightingRules.append(rule);
541 multiLineComments = false;
542 commentStartExpression = QRegExp();
543 commentEndExpression = QRegExp();
544 }