| 1 | // File: code.cpp |
| 2 | /* |
| 3 | Pep8-1 is a virtual machine for writing machine language and assembly |
| 4 | language programs. |
| 5 | |
| 6 | Copyright (C) 2009 J. Stanley Warford, Pepperdine University |
| 7 | |
| 8 | This program is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | #include "code.h" |
| 22 | #include "argument.h" |
| 23 | #include "pep.h" |
| 24 | #include "asm.h" |
| 25 | #include <QRegExp> |
| 26 | #include <QDebug> |
| 27 | |
| 28 | // appendObjectCode |
| 29 | void UnaryInstruction::appendObjectCode(QList<int> &objectCode) |
| 30 | { |
| 31 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 32 | objectCode.append(Pep::opCodeMap.value(mnemonic)); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | void NonUnaryInstruction::appendObjectCode(QList<int> &objectCode) |
| 37 | { |
| 38 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 39 | int instructionSpecifier = Pep::opCodeMap.value(mnemonic); |
| 40 | if (Pep::addrModeRequiredMap.value(mnemonic)) { |
| 41 | instructionSpecifier += Pep::aaaAddressField(addressingMode); |
| 42 | } |
| 43 | else { |
| 44 | instructionSpecifier += Pep::aAddressField(addressingMode); |
| 45 | } |
| 46 | objectCode.append(instructionSpecifier); |
| 47 | int operandSpecifier = argument->getArgumentValue(); |
| 48 | objectCode.append(operandSpecifier / 256); |
| 49 | objectCode.append(operandSpecifier % 256); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void DotAddrss::appendObjectCode(QList<int> &objectCode) |
| 54 | { |
| 55 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 56 | int symbolValue = Pep::symbolTable.value(argument->getArgumentString()); |
| 57 | objectCode.append(symbolValue / 256); |
| 58 | objectCode.append(symbolValue % 256); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void DotAscii::appendObjectCode(QList<int> &objectCode) |
| 63 | { |
| 64 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 65 | int value; |
| 66 | QString str = argument->getArgumentString(); |
| 67 | str.remove(0, 1); // Remove the leftmost double quote. |
| 68 | str.chop(1); // Remove the rightmost double quote. |
| 69 | while (str.length() > 0) { |
| 70 | Asm::unquotedStringToInt(str, value); |
| 71 | objectCode.append(value); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void DotBlock::appendObjectCode(QList<int> &objectCode) |
| 77 | { |
| 78 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 79 | for (int i = 0; i < argument->getArgumentValue(); i++) { |
| 80 | objectCode.append(0); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void DotBurn::appendObjectCode(QList<int> &) |
| 86 | { |
| 87 | // Does not generate code. |
| 88 | } |
| 89 | |
| 90 | void DotByte::appendObjectCode(QList<int> &objectCode) |
| 91 | { |
| 92 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 93 | objectCode.append(argument->getArgumentValue()); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void DotEnd::appendObjectCode(QList<int> &) |
| 98 | { |
| 99 | // Does not generate code. |
| 100 | } |
| 101 | |
| 102 | void DotEquate::appendObjectCode(QList<int> &) |
| 103 | { |
| 104 | // Does not generate code. |
| 105 | } |
| 106 | |
| 107 | void DotWord::appendObjectCode(QList<int> &objectCode) |
| 108 | { |
| 109 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 110 | int value = argument->getArgumentValue(); |
| 111 | objectCode.append(value / 256); |
| 112 | objectCode.append(value % 256); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | void CommentOnly::appendObjectCode(QList<int> &) |
| 117 | { |
| 118 | // Does not generate code. |
| 119 | } |
| 120 | |
| 121 | void BlankLine::appendObjectCode(QList<int> &) |
| 122 | { |
| 123 | // Does not generate code. |
| 124 | } |
| 125 | |
| 126 | void UnaryInstruction::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 127 | { |
| 128 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 129 | QString codeStr = QString("%1").arg(Pep::opCodeMap.value(mnemonic), 2, 16, QLatin1Char('0')).toUpper(); |
| 130 | if ((Pep::burnCount == 1) && (memAddress < Pep::romStartAddress)) { |
| 131 | codeStr = " "; |
| 132 | } |
| 133 | QString symbolStr = symbolDef; |
| 134 | if (symbolStr.length() > 0) { |
| 135 | symbolStr.append(":"); |
| 136 | } |
| 137 | QString mnemonStr = Pep::enumToMnemonMap.value(mnemonic); |
| 138 | QString lineStr = QString("%1%2%3%4%5") |
| 139 | .arg(memStr, -6, QLatin1Char(' ')) |
| 140 | .arg(codeStr, -7, QLatin1Char(' ')) |
| 141 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 142 | .arg(mnemonStr, -8, QLatin1Char(' ')) |
| 143 | .arg(" " + comment); |
| 144 | Pep::memAddrssToAssemblerListing->insert(memAddress, assemblerListingList.size()); |
| 145 | Pep::listingRowChecked->insert(assemblerListingList.size(), Qt::Unchecked); |
| 146 | assemblerListingList.append(lineStr); |
| 147 | listingTraceList.append(lineStr); |
| 148 | hasCheckBox.append(true); |
| 149 | } |
| 150 | |
| 151 | void NonUnaryInstruction::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 152 | { |
| 153 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 154 | int temp = Pep::opCodeMap.value(mnemonic); |
| 155 | temp += Pep::addrModeRequiredMap.value(mnemonic) ? Pep::aaaAddressField(addressingMode) : Pep::aAddressField(addressingMode); |
| 156 | QString codeStr = QString("%1").arg(temp, 2, 16, QLatin1Char('0')).toUpper(); |
| 157 | QString oprndNumStr = QString("%1").arg(argument->getArgumentValue(), 4, 16, QLatin1Char('0')).toUpper(); |
| 158 | if ((Pep::burnCount == 1) && (memAddress < Pep::romStartAddress)) { |
| 159 | codeStr = " "; |
| 160 | oprndNumStr = " "; |
| 161 | } |
| 162 | QString symbolStr = symbolDef; |
| 163 | if (symbolStr.length() > 0) { |
| 164 | symbolStr.append(":"); |
| 165 | } |
| 166 | QString mnemonStr = Pep::enumToMnemonMap.value(mnemonic); |
| 167 | QString oprndStr = argument->getArgumentString(); |
| 168 | if (Pep::addrModeRequiredMap.value(mnemonic)) { |
| 169 | oprndStr.append("," + Pep::intToAddrMode(addressingMode)); |
| 170 | } |
| 171 | else if (addressingMode == Enu::X) { |
| 172 | oprndStr.append("," + Pep::intToAddrMode(addressingMode)); |
| 173 | } |
| 174 | QString lineStr = QString("%1%2%3%4%5%6%7") |
| 175 | .arg(memStr, -6, QLatin1Char(' ')) |
| 176 | .arg(codeStr, -2) |
| 177 | .arg(oprndNumStr, -5, QLatin1Char(' ')) |
| 178 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 179 | .arg(mnemonStr, -8, QLatin1Char(' ')) |
| 180 | .arg(oprndStr, -12) |
| 181 | .arg(comment); |
| 182 | Pep::memAddrssToAssemblerListing->insert(memAddress, assemblerListingList.size()); |
| 183 | Pep::listingRowChecked->insert(assemblerListingList.size(), Qt::Unchecked); |
| 184 | assemblerListingList.append(lineStr); |
| 185 | listingTraceList.append(lineStr); |
| 186 | hasCheckBox.append(true); |
| 187 | } |
| 188 | |
| 189 | void DotAddrss::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 190 | { |
| 191 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 192 | int symbolValue = Pep::symbolTable.value(argument->getArgumentString()); |
| 193 | QString codeStr = QString("%1").arg(symbolValue, 4, 16, QLatin1Char('0')).toUpper(); |
| 194 | if ((Pep::burnCount == 1) && (memAddress < Pep::romStartAddress)) { |
| 195 | codeStr = " "; |
| 196 | } |
| 197 | QString symbolStr = symbolDef; |
| 198 | if (symbolStr.length() > 0) { |
| 199 | symbolStr.append(":"); |
| 200 | } |
| 201 | QString dotStr = ".ADDRSS"; |
| 202 | QString oprndStr = argument->getArgumentString(); |
| 203 | QString lineStr = QString("%1%2%3%4%5%6") |
| 204 | .arg(memStr, -6, QLatin1Char(' ')) |
| 205 | .arg(codeStr, -7, QLatin1Char(' ')) |
| 206 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 207 | .arg(dotStr, -8, QLatin1Char(' ')) |
| 208 | .arg(oprndStr, -12) |
| 209 | .arg(comment); |
| 210 | assemblerListingList.append(lineStr); |
| 211 | listingTraceList.append(lineStr); |
| 212 | hasCheckBox.append(false); |
| 213 | } |
| 214 | |
| 215 | void DotAscii::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 216 | { |
| 217 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 218 | QString str = argument->getArgumentString(); |
| 219 | str.remove(0, 1); // Remove the leftmost double quote. |
| 220 | str.chop(1); // Remove the rightmost double quote. |
| 221 | int value; |
| 222 | QString codeStr = ""; |
| 223 | while ((str.length() > 0) && (codeStr.length() < 6)) { |
| 224 | Asm::unquotedStringToInt(str, value); |
| 225 | codeStr.append(QString("%1").arg(value, 2, 16, QLatin1Char('0')).toUpper()); |
| 226 | } |
| 227 | if ((Pep::burnCount == 1) && (memAddress < Pep::romStartAddress)) { |
| 228 | codeStr = " "; |
| 229 | } |
| 230 | QString symbolStr = symbolDef; |
| 231 | if (symbolStr.length() > 0) { |
| 232 | symbolStr.append(":"); |
| 233 | } |
| 234 | QString dotStr = ".ASCII"; |
| 235 | QString oprndStr = argument->getArgumentString(); |
| 236 | QString lineStr = QString("%1%2%3%4%5%6") |
| 237 | .arg(memStr, -6, QLatin1Char(' ')) |
| 238 | .arg(codeStr, -7, QLatin1Char(' ')) |
| 239 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 240 | .arg(dotStr, -8, QLatin1Char(' ')) |
| 241 | .arg(oprndStr, -12) |
| 242 | .arg(comment); |
| 243 | assemblerListingList.append(lineStr); |
| 244 | listingTraceList.append(lineStr); |
| 245 | hasCheckBox.append(false); |
| 246 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 247 | while (str.length() > 0) { |
| 248 | codeStr = ""; |
| 249 | while ((str.length() > 0) && (codeStr.length() < 6)) { |
| 250 | Asm::unquotedStringToInt(str, value); |
| 251 | codeStr.append(QString("%1").arg(value, 2, 16, QLatin1Char('0')).toUpper()); |
| 252 | } |
| 253 | lineStr = QString(" %1").arg(codeStr, -7, QLatin1Char(' ')); |
| 254 | assemblerListingList.append(lineStr); |
| 255 | listingTraceList.append(lineStr); |
| 256 | hasCheckBox.append(false); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void DotBlock::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 262 | { |
| 263 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 264 | int numBytes = argument->getArgumentValue(); |
| 265 | QString codeStr = ""; |
| 266 | while ((numBytes > 0) && (codeStr.length() < 6)) { |
| 267 | codeStr.append("00"); |
| 268 | numBytes--; |
| 269 | } |
| 270 | if ((Pep::burnCount == 1) && (memAddress < Pep::romStartAddress)) { |
| 271 | codeStr = " "; |
| 272 | } |
| 273 | QString symbolStr = symbolDef; |
| 274 | if (symbolStr.length() > 0) { |
| 275 | symbolStr.append(":"); |
| 276 | } |
| 277 | QString dotStr = ".BLOCK"; |
| 278 | QString oprndStr = argument->getArgumentString(); |
| 279 | QString lineStr = QString("%1%2%3%4%5%6") |
| 280 | .arg(memStr, -6, QLatin1Char(' ')) |
| 281 | .arg(codeStr, -7, QLatin1Char(' ')) |
| 282 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 283 | .arg(dotStr, -8, QLatin1Char(' ')) |
| 284 | .arg(oprndStr, -12) |
| 285 | .arg(comment); |
| 286 | assemblerListingList.append(lineStr); |
| 287 | listingTraceList.append(lineStr); |
| 288 | hasCheckBox.append(false); |
| 289 | if ((Pep::burnCount == 0) || ((Pep::burnCount == 1) && (memAddress >= Pep::romStartAddress))) { |
| 290 | while (numBytes > 0) { |
| 291 | codeStr = ""; |
| 292 | while ((numBytes > 0) && (codeStr.length() < 6)) { |
| 293 | codeStr.append("00"); |
| 294 | numBytes--; |
| 295 | } |
| 296 | lineStr = QString(" %1").arg(codeStr, -7, QLatin1Char(' ')); |
| 297 | assemblerListingList.append(lineStr); |
| 298 | listingTraceList.append(lineStr); |
| 299 | hasCheckBox.append(false); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | void DotBurn::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 305 | { |
| 306 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 307 | QString symbolStr = symbolDef; |
| 308 | if (symbolStr.length() > 0) { |
| 309 | symbolStr.append(":"); |
| 310 | } |
| 311 | QString dotStr = ".BURN"; |
| 312 | QString oprndStr = argument->getArgumentString(); |
| 313 | QString lineStr = QString("%1 %2%3%4%5") |
| 314 | .arg(memStr, -6, QLatin1Char(' ')) |
| 315 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 316 | .arg(dotStr, -8, QLatin1Char(' ')) |
| 317 | .arg(oprndStr, -12) |
| 318 | .arg(comment); |
| 319 | assemblerListingList.append(lineStr); |
| 320 | listingTraceList.append(lineStr); |
| 321 | hasCheckBox.append(false); |
| 322 | } |
| 323 | |
| 324 | void DotByte::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 325 | { |
| 326 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 327 | QString codeStr = QString("%1").arg(argument->getArgumentValue(), 2, 16, QLatin1Char('0')).toUpper(); |
| 328 | if ((Pep::burnCount == 1) && (memAddress < Pep::romStartAddress)) { |
| 329 | codeStr = " "; |
| 330 | } |
| 331 | QString symbolStr = symbolDef; |
| 332 | if (symbolStr.length() > 0) { |
| 333 | symbolStr.append(":"); |
| 334 | } |
| 335 | QString dotStr = ".BYTE"; |
| 336 | QString oprndStr = argument->getArgumentString(); |
| 337 | if (oprndStr.startsWith("0x")) { |
| 338 | oprndStr.remove(2, 2); // Display only the last two hex characters |
| 339 | } |
| 340 | QString lineStr = QString("%1%2%3%4%5%6") |
| 341 | .arg(memStr, -6, QLatin1Char(' ')) |
| 342 | .arg(codeStr, -7, QLatin1Char(' ')) |
| 343 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 344 | .arg(dotStr, -8, QLatin1Char(' ')) |
| 345 | .arg(oprndStr, -12) |
| 346 | .arg(comment); |
| 347 | assemblerListingList.append(lineStr); |
| 348 | listingTraceList.append(lineStr); |
| 349 | hasCheckBox.append(false); |
| 350 | } |
| 351 | |
| 352 | void DotEnd::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 353 | { |
| 354 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 355 | QString symbolStr = symbolDef; |
| 356 | if (symbolStr.length() > 0) { |
| 357 | symbolStr.append(":"); |
| 358 | } |
| 359 | QString dotStr = ".END"; |
| 360 | QString lineStr = QString("%1 %2%3 %4") |
| 361 | .arg(memStr, -6, QLatin1Char(' ')) |
| 362 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 363 | .arg(dotStr, -8, QLatin1Char(' ')) |
| 364 | .arg(comment); |
| 365 | assemblerListingList.append(lineStr); |
| 366 | listingTraceList.append(lineStr); |
| 367 | hasCheckBox.append(false); |
| 368 | } |
| 369 | |
| 370 | void DotEquate::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 371 | { |
| 372 | QString symbolStr = symbolDef; |
| 373 | if (symbolStr.length() > 0) { |
| 374 | symbolStr.append(":"); |
| 375 | } |
| 376 | QString dotStr = ".EQUATE"; |
| 377 | QString oprndStr = argument->getArgumentString(); |
| 378 | QString lineStr = QString(" %1%2%3%4") |
| 379 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 380 | .arg(dotStr, -8, QLatin1Char(' ')) |
| 381 | .arg(oprndStr, -12) |
| 382 | .arg(comment); |
| 383 | assemblerListingList.append(lineStr); |
| 384 | listingTraceList.append(lineStr); |
| 385 | hasCheckBox.append(false); |
| 386 | } |
| 387 | |
| 388 | void DotWord::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 389 | { |
| 390 | QString memStr = QString("%1").arg(memAddress, 4, 16, QLatin1Char('0')).toUpper(); |
| 391 | QString codeStr = QString("%1").arg(argument->getArgumentValue(), 4, 16, QLatin1Char('0')).toUpper(); |
| 392 | if ((Pep::burnCount == 1) && (memAddress < Pep::romStartAddress)) { |
| 393 | codeStr = " "; |
| 394 | } |
| 395 | QString symbolStr = symbolDef; |
| 396 | if (symbolStr.length() > 0) { |
| 397 | symbolStr.append(":"); |
| 398 | } |
| 399 | QString dotStr = ".WORD"; |
| 400 | QString oprndStr = argument->getArgumentString(); |
| 401 | QString lineStr = QString("%1%2%3%4%5%6") |
| 402 | .arg(memStr, -6, QLatin1Char(' ')) |
| 403 | .arg(codeStr, -7, QLatin1Char(' ')) |
| 404 | .arg(symbolStr, -9, QLatin1Char(' ')) |
| 405 | .arg(dotStr, -8, QLatin1Char(' ')) |
| 406 | .arg(oprndStr, -12) |
| 407 | .arg(comment); |
| 408 | assemblerListingList.append(lineStr); |
| 409 | listingTraceList.append(lineStr); |
| 410 | hasCheckBox.append(false); |
| 411 | } |
| 412 | |
| 413 | void CommentOnly::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 414 | { |
| 415 | assemblerListingList.append(" " + comment); |
| 416 | listingTraceList.append(" " + comment); |
| 417 | hasCheckBox.append(false); |
| 418 | } |
| 419 | |
| 420 | void BlankLine::appendSourceLine(QStringList &assemblerListingList, QStringList &listingTraceList, QList<bool> &hasCheckBox) |
| 421 | { |
| 422 | assemblerListingList.append(""); |
| 423 | listingTraceList.append(""); |
| 424 | hasCheckBox.append(false); |
| 425 | } |
| 426 | |
| 427 | bool DotBlock::processFormatTraceTags(int &sourceLine, QString &errorString) { |
| 428 | if (symbolDef.size() == 0) { |
| 429 | return true; |
| 430 | } |
| 431 | int pos = Asm::rxFormatTag.indexIn(comment); |
| 432 | if (pos > -1) { |
| 433 | QString formatTag = Asm::rxFormatTag.cap(0); |
| 434 | Enu::ESymbolFormat tagType = Asm::formatTagType(formatTag); |
| 435 | int multiplier = Asm::formatMultiplier(formatTag); |
| 436 | if (argument->getArgumentValue() != Asm::tagNumBytes(tagType) * multiplier) { |
| 437 | errorString = ";WARNING: Format tag does not match number of bytes allocated by .BLOCK."; |
| 438 | sourceLine = sourceCodeLine; |
| 439 | return false; |
| 440 | } |
| 441 | Pep::symbolFormat.insert(symbolDef, tagType); |
| 442 | Pep::symbolFormatMultiplier.insert(symbolDef, multiplier); |
| 443 | Pep::blockSymbols.append(symbolDef); |
| 444 | } |
| 445 | return true; |
| 446 | } |
| 447 | |
| 448 | bool DotEquate::processFormatTraceTags(int &, QString &) { |
| 449 | if (symbolDef.size() == 0) { |
| 450 | return true; |
| 451 | } |
| 452 | int pos = Asm::rxFormatTag.indexIn(comment); |
| 453 | if (pos > -1) { |
| 454 | QString formatTag = Asm::rxFormatTag.cap(0); |
| 455 | Pep::symbolFormat.insert(symbolDef, Asm::formatTagType(formatTag)); |
| 456 | Pep::symbolFormatMultiplier.insert(symbolDef, Asm::formatMultiplier(formatTag)); |
| 457 | Pep::equateSymbols.append(symbolDef); |
| 458 | } |
| 459 | return true; |
| 460 | } |
| 461 | |
| 462 | bool DotBlock::processSymbolTraceTags(int &sourceLine, QString &errorString) { |
| 463 | // For global structs. |
| 464 | if (symbolDef.size() == 0) { |
| 465 | return true; |
| 466 | } |
| 467 | if (Pep::blockSymbols.contains(symbolDef)) { |
| 468 | return true; // Format tag takes precedence over symbol tags. |
| 469 | } |
| 470 | int numBytesAllocated = argument->getArgumentValue(); |
| 471 | QString symbol; |
| 472 | QStringList list; |
| 473 | int numBytesListed = 0; |
| 474 | int pos = 0; |
| 475 | while ((pos = Asm::rxSymbolTag.indexIn(comment, pos)) != -1) { |
| 476 | symbol = Asm::rxSymbolTag.cap(1); |
| 477 | if (!Pep::equateSymbols.contains(symbol)) { |
| 478 | errorString = ";WARNING: " + symbol + " not specified in .EQUATE."; |
| 479 | sourceLine = sourceCodeLine; |
| 480 | return false; |
| 481 | } |
| 482 | numBytesListed += Asm::tagNumBytes(Pep::symbolFormat.value(symbol)) * Pep::symbolFormatMultiplier.value(symbol); |
| 483 | list.append(symbol); |
| 484 | pos += Asm::rxSymbolTag.matchedLength(); |
| 485 | } |
| 486 | if (numBytesAllocated != numBytesListed && numBytesListed > 0) { |
| 487 | errorString = ";WARNING: Number of bytes allocated (" + QString("%1").arg(numBytesAllocated) + |
| 488 | ") not equal to number of bytes listed in trace tag (" + QString("%1").arg(numBytesListed) + ")."; |
| 489 | sourceLine = sourceCodeLine; |
| 490 | return false; |
| 491 | } |
| 492 | Pep::blockSymbols.append(symbolDef); |
| 493 | Pep::globalStructSymbols.insert(symbolDef, list); |
| 494 | return true; |
| 495 | } |
| 496 | |
| 497 | bool UnaryInstruction::processSymbolTraceTags(int &sourceLine, QString &errorString) { |
| 498 | int numBytesDeallocated; |
| 499 | switch (mnemonic) { |
| 500 | case Enu::RET1: |
| 501 | numBytesDeallocated = 1; |
| 502 | break; |
| 503 | case Enu::RET2: |
| 504 | numBytesDeallocated = 2; |
| 505 | break; |
| 506 | case Enu::RET3: |
| 507 | numBytesDeallocated = 3; |
| 508 | break; |
| 509 | case Enu::RET4: |
| 510 | numBytesDeallocated = 4; |
| 511 | break; |
| 512 | case Enu::RET5: |
| 513 | numBytesDeallocated = 5; |
| 514 | break; |
| 515 | case Enu::RET6: |
| 516 | numBytesDeallocated = 6; |
| 517 | break; |
| 518 | case Enu::RET7: |
| 519 | numBytesDeallocated = 7; |
| 520 | break; |
| 521 | default: |
| 522 | return true; |
| 523 | } |
| 524 | QString symbol; |
| 525 | QStringList list; |
| 526 | int numBytesListed = 0; |
| 527 | int pos = 0; |
| 528 | while ((pos = Asm::rxSymbolTag.indexIn(comment, pos)) != -1) { |
| 529 | symbol = Asm::rxSymbolTag.cap(1); |
| 530 | if (!Pep::equateSymbols.contains(symbol)) { |
| 531 | errorString = ";WARNING: " + symbol + " not specified in .EQUATE."; |
| 532 | sourceLine = sourceCodeLine; |
| 533 | return false; |
| 534 | } |
| 535 | numBytesListed += Asm::tagNumBytes(Pep::symbolFormat.value(symbol)) * Pep::symbolFormatMultiplier.value(symbol); |
| 536 | list.append(symbol); |
| 537 | pos += Asm::rxSymbolTag.matchedLength(); |
| 538 | } |
| 539 | if (numBytesDeallocated != numBytesListed) { |
| 540 | errorString = ";WARNING: Number of bytes deallocated (" + QString("%1").arg(numBytesDeallocated) + |
| 541 | ") not equal to number of bytes listed in trace tag (" + QString("%1").arg(numBytesListed) + ")."; |
| 542 | sourceLine = sourceCodeLine; |
| 543 | return false; |
| 544 | } |
| 545 | Pep::symbolTraceList.insert(memAddress, list); |
| 546 | return true; |
| 547 | } |
| 548 | |
| 549 | bool NonUnaryInstruction::processSymbolTraceTags(int &sourceLine, QString &errorString) { |
| 550 | if (mnemonic == Enu::ADDSP || mnemonic == Enu::SUBSP) { |
| 551 | int numBytesAllocated; |
| 552 | if (addressingMode != Enu::I) { |
| 553 | errorString = ";WARNING: Stack trace not possible unless immediate addressing is specified."; |
| 554 | sourceLine = sourceCodeLine; |
| 555 | return false; |
| 556 | } |
| 557 | numBytesAllocated = argument->getArgumentValue(); |
| 558 | QString symbol; |
| 559 | QStringList list; |
| 560 | int numBytesListed = 0; |
| 561 | int pos = 0; |
| 562 | while ((pos = Asm::rxSymbolTag.indexIn(comment, pos)) != -1) { |
| 563 | symbol = Asm::rxSymbolTag.cap(1); |
| 564 | if (!Pep::equateSymbols.contains(symbol)) { |
| 565 | errorString = ";WARNING: " + symbol + " not specified in .EQUATE."; |
| 566 | sourceLine = sourceCodeLine; |
| 567 | return false; |
| 568 | } |
| 569 | numBytesListed += Asm::tagNumBytes(Pep::symbolFormat.value(symbol)) * Pep::symbolFormatMultiplier.value(symbol); |
| 570 | list.append(symbol); |
| 571 | pos += Asm::rxSymbolTag.matchedLength(); |
| 572 | } |
| 573 | if (numBytesAllocated != numBytesListed) { |
| 574 | QString message = (mnemonic == Enu::ADDSP) ? "deallocated" : "allocated"; |
| 575 | errorString = ";WARNING: Number of bytes " + message + " (" + QString("%1").arg(numBytesAllocated) + |
| 576 | ") not equal to number of bytes listed in trace tag (" + QString("%1").arg(numBytesListed) + ")."; |
| 577 | sourceLine = sourceCodeLine; |
| 578 | return false; |
| 579 | } |
| 580 | Pep::symbolTraceList.insert(memAddress, list); |
| 581 | return true; |
| 582 | } |
| 583 | else if (mnemonic == Enu::CALL && argument->getArgumentString() == "new") { |
| 584 | int pos = 0; |
| 585 | QString symbol; |
| 586 | QStringList list; |
| 587 | while ((pos = Asm::rxSymbolTag.indexIn(comment, pos)) != -1) { |
| 588 | symbol = Asm::rxSymbolTag.cap(1); |
| 589 | if (!Pep::equateSymbols.contains(symbol) && !Pep::blockSymbols.contains(symbol)) { |
| 590 | errorString = ";WARNING: " + symbol + " not specified in .EQUATE."; |
| 591 | sourceLine = sourceCodeLine; |
| 592 | return false; |
| 593 | } |
| 594 | list.append(symbol); |
| 595 | Pep::symbolTraceList.insert(memAddress, list); |
| 596 | pos += Asm::rxSymbolTag.matchedLength(); |
| 597 | } |
| 598 | return true; |
| 599 | } |
| 600 | else { |
| 601 | return true; |
| 602 | } |
| 603 | } |