| 1 | // File: argument.h |
| 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 | |
| 22 | #ifndef ARGUMENT_H |
| 23 | #define ARGUMENT_H |
| 24 | |
| 25 | #include "asm.h" |
| 26 | #include "pep.h" |
| 27 | |
| 28 | // Abstract Argument class |
| 29 | class Argument |
| 30 | { |
| 31 | friend class Asm; |
| 32 | public: |
| 33 | virtual ~Argument() { } |
| 34 | virtual int getArgumentValue() = 0; |
| 35 | virtual QString getArgumentString() = 0; |
| 36 | }; |
| 37 | |
| 38 | // Concrete argument classes |
| 39 | // All methods are defined in this argument.h file. |
| 40 | class CharArgument: public Argument |
| 41 | { |
| 42 | friend class Asm; |
| 43 | private: |
| 44 | QString charValue; |
| 45 | public: |
| 46 | CharArgument(QString cValue) { charValue = cValue; } |
| 47 | int getArgumentValue() { return Asm::charStringToInt(charValue); } |
| 48 | QString getArgumentString() { return charValue; } |
| 49 | }; |
| 50 | |
| 51 | class DecArgument: public Argument |
| 52 | { |
| 53 | private: |
| 54 | int decValue; |
| 55 | public: |
| 56 | DecArgument(int dValue) { decValue = dValue; } |
| 57 | int getArgumentValue() { return decValue; } |
| 58 | QString getArgumentString() { |
| 59 | int temp = decValue >= 32768 ? decValue - 65536 : decValue; |
| 60 | return QString("%1").arg(temp); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | class UnsignedDecArgument: public Argument |
| 65 | { |
| 66 | private: |
| 67 | int decValue; |
| 68 | public: |
| 69 | UnsignedDecArgument(int dValue) { decValue = dValue; } |
| 70 | int getArgumentValue() { return decValue; } |
| 71 | QString getArgumentString() { |
| 72 | return QString("%1").arg(decValue); |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | class HexArgument: public Argument |
| 77 | { |
| 78 | private: |
| 79 | int hexValue; |
| 80 | public: |
| 81 | HexArgument(int hValue) { hexValue = hValue; } |
| 82 | int getArgumentValue() { return hexValue; } |
| 83 | QString getArgumentString() { return "0x" + QString("%1").arg(hexValue, 4, 16, QLatin1Char('0')).toUpper(); } |
| 84 | }; |
| 85 | |
| 86 | class StringArgument: public Argument |
| 87 | { |
| 88 | private: |
| 89 | QString stringValue; |
| 90 | public: |
| 91 | StringArgument(QString sValue) { stringValue = sValue; } |
| 92 | int getArgumentValue() { return Asm::string2ArgumentToInt(stringValue); } |
| 93 | QString getArgumentString() { return stringValue; } |
| 94 | }; |
| 95 | |
| 96 | class SymbolRefArgument: public Argument |
| 97 | { |
| 98 | private: |
| 99 | QString symbolRefValue; |
| 100 | public: |
| 101 | SymbolRefArgument(QString sRefValue) { symbolRefValue = sRefValue; } |
| 102 | int getArgumentValue() { return Pep::symbolTable.value(symbolRefValue); } |
| 103 | QString getArgumentString() { return symbolRefValue; } |
| 104 | }; |
| 105 | |
| 106 | #endif // ARGUMENT_H |