Debian Codegraph @

asm.h

raw symbols SCIP
1 // File: asm.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 ASM_H
23 #define ASM_H
24
25 #include <QRegExp>
26 #include "enu.h"
27
28 class Code; // Forward declaration for argument of processSourceLine.
29
30 class Asm
31 {
32 public:
33 // Lexical tokens
34 enum ELexicalToken
35 {
36 LT_ADDRESSING_MODE, LT_CHAR_CONSTANT, LT_COMMENT, LT_DEC_CONSTANT, LT_DOT_COMMAND,
37 LT_EMPTY, LT_HEX_CONSTANT, LT_IDENTIFIER, LT_STRING_CONSTANT, LT_SYMBOL_DEF
38 };
39
40 enum ParseState
41 {
42 PS_ADDRESSING_MODE, PS_CLOSE, PS_COMMENT, PS_DOT_ADDRSS, PS_DOT_ASCII, PS_DOT_BLOCK,
43 PS_DOT_BURN, PS_DOT_BYTE, PS_DOT_END, PS_DOT_EQUATE, PS_DOT_WORD, PS_FINISH,
44 PS_INSTRUCTION, PS_START, PS_STRING, PS_SYMBOL_DEF
45 };
46
47 // Regular expressions for lexical analysis
48 static QRegExp rxAddrMode;
49 static QRegExp rxCharConst;
50 static QRegExp rxComment;
51 static QRegExp rxDecConst;
52 static QRegExp rxDotCommand;
53 static QRegExp rxHexConst;
54 static QRegExp rxIdentifier;
55 static QRegExp rxStringConst;
56
57 // Regular expressions for trace tag analysis
58 static QRegExp rxFormatTag;
59 static QRegExp rxSymbolTag;
60 static QRegExp rxArrayMultiplier;
61
62 static bool getToken(QString &sourceLine, ELexicalToken &token, QString &tokenString);
63 // Pre: sourceLine has one line of source code.
64 // Post: If the next token is valid, the string of characters representing the next token are deleted from the
65 // beginning of sourceLine and returned in tokenString, true is returned, and token is set to the token type.
66 // Post: If false is returned, then tokenString is set to the lexical error message.
67
68 static bool processSourceLine(QString sourceLine, int lineNum, Code *&code, QString &errorString, bool &dotEndDetected);
69 // Pre: sourceLine has one line of source code.
70 // Pre: lineNum is the line number of the source code.
71 // Post: If the source line is valid, true is returned and code is set to the source code for the line.
72 // Post: dotEndDetected is set to true if .END is processed. Otherwise it is set to false.
73 // Post: Pep::byteCount is incremented by the number of bytes generated.
74 // Post: If the source line is not valid, false is returned and errorString is set to the error message.
75
76 static QList<QString> listOfReferencedSymbols;
77 static QList<int> listOfReferencedSymbolLineNums;
78
79 static bool startsWithHexPrefix(QString str);
80 // Post: Returns true if str starts with the characters 0x or 0X. Otherwise returns false.
81
82 static Enu::EAddrMode stringToAddrMode(QString str);
83 // Post: Returns the addressing mode integer defined in Pep from its string representation.
84
85 static int charStringToInt(QString str);
86 // Pre: str is enclosed in single quotes.
87 // Post: Returns the ASCII integer value of the character accounting for \ quoted characters.
88
89 static int string2ArgumentToInt(QString str);
90 // Pre: str is enclosed in double quotes and contains at most two possibly quoted characters.
91 // Post: Returns the two-byte ASCII integer value for the string.
92
93 static void unquotedStringToInt(QString &str, int &value);
94 // Pre: str is a character or string stripped of its single or double quotes.
95 // Post: The sequence of characters representing the first possibly \ quoted character
96 // is stripped from the beginning of str.
97 // Post: value is the ASCII integer value of the first possibly \ quoted character.
98
99 static int byteStringLength(QString str);
100 // Pre: str is a double quoted string.
101 // Post: Returns the byte length of str accounting for possibly \ quoted characters.
102
103 static Enu::ESymbolFormat formatTagType(QString formatTag);
104 // Pre: formatTag is a valid format trace tag.
105 // Post: Returns the enumerated trace tag format type.
106
107 static int tagNumBytes(Enu::ESymbolFormat symbolFormat);
108 // Pre: symbolFormat is a valid format trace tag type.
109 // Post: Returns the corresponding integer number of bytes.
110
111 static int formatMultiplier(QString formatTag);
112 // Pre: format tag is a valid format trace tag.
113 // Post: If the format tag specifies an array, returns the array multiplier.
114 // Otherwise, returns 1.
115
116 };
117
118 #endif // ASM_H