1 /*************************************************************************************************/
6 Copyright (C) Rich Talbot-Watkins 2007, 2008
8 This file is part of BeebAsm.
10 BeebAsm is free software: you can redistribute it and/or modify it under the terms of the GNU
11 General Public License as published by the Free Software Foundation, either version 3 of the
12 License, or (at your option) any later version.
14 BeebAsm is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
15 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along with BeebAsm, as
19 COPYING.txt. If not, see <http://www.gnu.org/licenses/>.
21 /*************************************************************************************************/
23 #ifndef ASMEXCEPTION_H_
24 #define ASMEXCEPTION_H_
30 /*************************************************************************************************/
34 Base class for Asm6502 exceptions
36 /*************************************************************************************************/
42 virtual ~AsmException() {}
44 virtual void Print() const = 0;
49 /*************************************************************************************************/
51 @class AsmException_FileError
53 Exception class used for all I/O errors
55 /*************************************************************************************************/
56 class AsmException_FileError
: public AsmException
60 explicit AsmException_FileError( const char* pFilename
)
61 : m_pFilename( pFilename
)
65 virtual ~AsmException_FileError() {}
67 virtual void Print() const;
69 virtual const char* Message() const
71 return "Unspecified file error.";
76 const char* m_pFilename
;
80 #define DEFINE_FILE_EXCEPTION( a, msg ) \
81 class AsmException_FileError_##a : public AsmException_FileError \
84 explicit AsmException_FileError_##a( const char* pFilename ) \
85 : AsmException_FileError( pFilename ) {} \
87 virtual ~AsmException_FileError_##a() {} \
89 virtual const char* Message() const { return msg; } \
93 DEFINE_FILE_EXCEPTION( OpenSourceFile
, "Could not open source file for reading." );
94 DEFINE_FILE_EXCEPTION( ReadSourceFile
, "Problem reading from source file." );
95 DEFINE_FILE_EXCEPTION( OpenDiscSource
, "Could not open disc image for reading." );
96 DEFINE_FILE_EXCEPTION( ReadDiscSource
, "Problem reading from disc image." );
97 DEFINE_FILE_EXCEPTION( OpenDiscDest
, "Could not create new disc image." );
98 DEFINE_FILE_EXCEPTION( WriteDiscDest
, "Could not write to disc image." );
99 DEFINE_FILE_EXCEPTION( OpenObj
, "Could not open object file for writing." );
100 DEFINE_FILE_EXCEPTION( WriteObj
, "Problem writing to object file." );
101 DEFINE_FILE_EXCEPTION( DiscFull
, "No room on DFS disc image full." );
102 DEFINE_FILE_EXCEPTION( BadName
, "Bad DFS filename." );
103 DEFINE_FILE_EXCEPTION( TooManyFiles
, "Too many files on DFS disc image (max 31)." );
104 DEFINE_FILE_EXCEPTION( FileExists
, "File already exists on DFS disc image." );
107 /*************************************************************************************************/
109 @class AsmException_SyntaxError
111 Base exception class used for all syntax errors
113 /*************************************************************************************************/
114 class AsmException_SyntaxError
: public AsmException
118 AsmException_SyntaxError()
119 : m_pFilename( NULL
),
124 AsmException_SyntaxError( std::string line
, int column
)
132 virtual ~AsmException_SyntaxError() {}
134 void SetFilename( const char* filename
) { if ( m_pFilename
== NULL
) m_pFilename
= filename
; }
135 void SetLineNumber( int lineNumber
) { if ( m_lineNumber
== 0 ) m_lineNumber
= lineNumber
; }
137 virtual void Print() const;
138 virtual const char* Message() const
140 return "Unspecified syntax error.";
148 const char* m_pFilename
;
153 #define DEFINE_SYNTAX_EXCEPTION( a, msg ) \
154 class AsmException_SyntaxError_##a : public AsmException_SyntaxError \
157 AsmException_SyntaxError_##a( std::string line, int column ) \
158 : AsmException_SyntaxError( line, column ) {} \
160 virtual ~AsmException_SyntaxError_##a() {} \
162 virtual const char* Message() const { return msg; } \
166 // high-level file parsing exceptions
167 DEFINE_SYNTAX_EXCEPTION( UnrecognisedToken
, "Unrecognised token." );
169 // expression parsing exceptions
170 DEFINE_SYNTAX_EXCEPTION( NumberTooBig
, "Number too big." );
171 DEFINE_SYNTAX_EXCEPTION( SymbolNotDefined
, "Symbol not defined." );
172 DEFINE_SYNTAX_EXCEPTION( BadHex
, "Bad hex." );
173 DEFINE_SYNTAX_EXCEPTION( BadBin
, "Bad binary expression." );
174 DEFINE_SYNTAX_EXCEPTION( MissingValue
, "Missing value in expression." );
175 DEFINE_SYNTAX_EXCEPTION( InvalidCharacter
, "Bad expression." );
176 DEFINE_SYNTAX_EXCEPTION( ExpressionTooComplex
, "Expression too complex." );
177 DEFINE_SYNTAX_EXCEPTION( MismatchedParentheses
, "Mismatched parentheses." );
178 DEFINE_SYNTAX_EXCEPTION( EmptyExpression
, "Expression not found." );
179 DEFINE_SYNTAX_EXCEPTION( DivisionByZero
, "Division by zero." );
180 DEFINE_SYNTAX_EXCEPTION( MissingQuote
, "Unterminated string." );
181 DEFINE_SYNTAX_EXCEPTION( MissingComma
, "Missing comma." );
182 DEFINE_SYNTAX_EXCEPTION( IllegalOperation
, "Operation attempted with invalid or out of range values." );
184 // assembler parsing exceptions
185 DEFINE_SYNTAX_EXCEPTION( NoImplied
, "Implied mode not allowed for this instruction." );
186 DEFINE_SYNTAX_EXCEPTION( ImmTooLarge
, "Immediate constants cannot be greater than 255." );
187 DEFINE_SYNTAX_EXCEPTION( ImmNegative
, "Constant cannot be negative." );
188 DEFINE_SYNTAX_EXCEPTION( UnexpectedComma
, "Unexpected comma enountered." );
189 DEFINE_SYNTAX_EXCEPTION( NoImmediate
, "Immediate mode not allowed for this instruction." );
190 DEFINE_SYNTAX_EXCEPTION( NoIndirect16
, "16-bit indirect mode not allowed for this instruction." );
191 DEFINE_SYNTAX_EXCEPTION( 6502Bug
, "JMP (addr) will not execute as intended due to the 6502 bug (addr = &xxFF)." );
192 DEFINE_SYNTAX_EXCEPTION( BadIndirect
, "Incorrectly formed indirect instruction." );
193 DEFINE_SYNTAX_EXCEPTION( NoIndirect
, "Indirect mode not allowed for this instruction." );
194 DEFINE_SYNTAX_EXCEPTION( NotZeroPage
, "Address is not in zero-page." );
195 DEFINE_SYNTAX_EXCEPTION( BranchOutOfRange
, "Branch out of range." );
196 DEFINE_SYNTAX_EXCEPTION( NoAbsolute
, "Absolute addressing mode not allowed for this instruction." );
197 DEFINE_SYNTAX_EXCEPTION( BadAbsolute
, "Syntax error in absolute instruction." );
198 DEFINE_SYNTAX_EXCEPTION( BadAddress
, "Out of range address." );
199 DEFINE_SYNTAX_EXCEPTION( BadIndexed
, "Syntax error in indexed instruction." );
200 DEFINE_SYNTAX_EXCEPTION( NoIndexedX
, "X indexed mode does not exist for this instruction." );
201 DEFINE_SYNTAX_EXCEPTION( NoIndexedY
, "Y indexed mode does not exist for this instruction." );
202 DEFINE_SYNTAX_EXCEPTION( LabelAlreadyDefined
, "Symbol already defined." );
203 DEFINE_SYNTAX_EXCEPTION( InvalidSymbolName
, "Invalid symbol name; must start with a letter and contain only numbers and underscore." );
204 DEFINE_SYNTAX_EXCEPTION( SecondPassProblem
, "Fatal error: the second assembler pass has generated different code to the first." );
206 // meta-language parsing exceptions
207 DEFINE_SYNTAX_EXCEPTION( NextWithoutFor
, "NEXT without FOR." );
208 DEFINE_SYNTAX_EXCEPTION( ForWithoutNext
, "FOR without NEXT." );
209 DEFINE_SYNTAX_EXCEPTION( BadStep
, "Step value cannot be zero." );
210 DEFINE_SYNTAX_EXCEPTION( TooManyFORs
, "Too many nested FORs or braces." );
211 DEFINE_SYNTAX_EXCEPTION( MismatchedBraces
, "Mismatched braces." );
212 DEFINE_SYNTAX_EXCEPTION( CantInclude
, "Cannot include a source file within a FOR loop or braced block." );
213 DEFINE_SYNTAX_EXCEPTION( ElseWithoutIf
, "ELSE without IF." );
214 DEFINE_SYNTAX_EXCEPTION( EndifWithoutIf
, "ENDIF without IF." );
215 DEFINE_SYNTAX_EXCEPTION( IfWithoutEndif
, "IF without ENDIF." );
216 DEFINE_SYNTAX_EXCEPTION( TooManyIFs
, "Too many nested IFs." );
217 DEFINE_SYNTAX_EXCEPTION( BadAlignment
, "Bad alignment." );
218 DEFINE_SYNTAX_EXCEPTION( OutOfRange
, "Out of range." );
219 DEFINE_SYNTAX_EXCEPTION( BackwardsSkip
, "Attempted to skip backwards to an address." );
223 /*************************************************************************************************/
225 @class AsmException_AssembleError
227 Base exception class used for all assembling errors
229 /*************************************************************************************************/
230 class AsmException_AssembleError
: public AsmException_SyntaxError
234 AsmException_AssembleError() {}
236 virtual ~AsmException_AssembleError() {}
238 void SetString( std::string line
) { m_line
= line
; }
239 void SetColumn( int column
) { m_column
= column
; }
241 virtual const char* Message() const
243 return "Unspecified assemble error.";
248 #define DEFINE_ASSEMBLE_EXCEPTION( a, msg ) \
249 class AsmException_AssembleError_##a : public AsmException_AssembleError \
252 AsmException_AssembleError_##a() {} \
253 virtual ~AsmException_AssembleError_##a() {} \
254 virtual const char* Message() const { return msg; } \
258 DEFINE_ASSEMBLE_EXCEPTION( OutOfMemory
, "Out of memory." );
259 DEFINE_ASSEMBLE_EXCEPTION( GuardHit
, "Guard point hit." );
260 DEFINE_ASSEMBLE_EXCEPTION( Overlap
, "Trying to assemble over existing code." );
261 DEFINE_ASSEMBLE_EXCEPTION( InconsistentCode
, "Assembled object code has changed between 1st and 2nd pass. Has a zero-page symbol been forward-declared?" );
262 DEFINE_ASSEMBLE_EXCEPTION( FileOpen
, "Error opening file." );
263 DEFINE_ASSEMBLE_EXCEPTION( FileRead
, "Error reading file." );
265 #endif // ASMEXCEPTION_H_