1 |
34 |
Agner |
/**************************** error.h ************************************
|
2 |
|
|
* Author: Agner Fog
|
3 |
|
|
* Date created: 2017-04-17
|
4 |
|
|
* Last modified: 2021-03-30
|
5 |
|
|
* Version: 1.11
|
6 |
|
|
* Project: Binary tools for ForwardCom instruction set
|
7 |
|
|
* Module: error.h
|
8 |
|
|
* Description:
|
9 |
|
|
* Header file for error handler error.cpp
|
10 |
|
|
*
|
11 |
|
|
* Copyright 2006-2021 GNU General Public License http://www.gnu.org/licenses
|
12 |
|
|
*****************************************************************************/
|
13 |
|
|
#pragma once
|
14 |
|
|
|
15 |
|
|
// Error id numbers, general errors
|
16 |
|
|
const int ERR_MULTIPLE_COMMANDS = 100;
|
17 |
|
|
const int ERR_OUTFILE_IGNORED = 101;
|
18 |
|
|
const int ERR_EMPTY_OPTION = 102;
|
19 |
|
|
const int ERR_UNKNOWN_OPTION = 103;
|
20 |
|
|
const int ERR_UNKNOWN_ERROR_NUM = 104;
|
21 |
|
|
const int ERR_MULTIPLE_IO_FILES = 105;
|
22 |
|
|
const int ERR_DUMP_NOT_SUPPORTED = 106;
|
23 |
|
|
const int ERR_INPUT_FILE = 107;
|
24 |
|
|
const int ERR_OUTPUT_FILE = 108;
|
25 |
|
|
const int ERR_UNKNOWN_FILE_TYPE = 109;
|
26 |
|
|
const int ERR_FILE_SIZE = 110;
|
27 |
|
|
const int ERR_FILE_NAME_LONG = 111;
|
28 |
|
|
const int ERR_FILES_SAME_NAME = 112;
|
29 |
|
|
const int ERR_TOO_MANY_RESP_FILES = 112;
|
30 |
|
|
|
31 |
|
|
const int ERR_MEMORY_ALLOCATION = 120;
|
32 |
|
|
const int ERR_CONTAINER_INDEX = 121;
|
33 |
|
|
const int ERR_CONTAINER_OVERFLOW = 122;
|
34 |
|
|
const int ERR_INDEX_OUT_OF_RANGE = 123;
|
35 |
|
|
|
36 |
|
|
const int ERR_ELF_RECORD_SIZE = 130;
|
37 |
|
|
const int ERR_ELF_SYMTAB_MISSING = 131;
|
38 |
|
|
const int ERR_ELF_INDEX_RANGE = 132;
|
39 |
|
|
const int ERR_ELF_UNKNOWN_SECTION = 133;
|
40 |
|
|
const int ERR_ELF_STRING_TABLE = 134;
|
41 |
|
|
const int ERR_ELF_NO_SECTIONS = 135;
|
42 |
|
|
|
43 |
|
|
const int ERR_INSTRUCTION_LIST_SYNTAX = 140;
|
44 |
|
|
const int ERR_INSTRUCTION_LIST_QUOTE = 141;
|
45 |
|
|
|
46 |
|
|
const int ERR_LIBRARY_FILE_TYPE = 200;
|
47 |
|
|
const int ERR_LIBRARY_FILE_CORRUPT = 201;
|
48 |
|
|
const int ERR_DUPLICATE_NAME_COMMANDL = 202;
|
49 |
|
|
const int ERR_DUPLICATE_NAME_IN_LIB = 203;
|
50 |
|
|
const int ERR_DUPLICATE_SYMBOL_IN_LIB = 204;
|
51 |
|
|
const int ERR_NO_SYMTAB_IN_LIB = 205;
|
52 |
|
|
const int ERR_MEMBER_NOT_FOUND_DEL = 206;
|
53 |
|
|
const int ERR_MEMBER_NOT_FOUND_EXTRACT = 207;
|
54 |
|
|
const int ERR_LIBRARY_LIST_ONLY = 208;
|
55 |
|
|
const int ERR_LIBRARY_MEMBER_TYPE = 209;
|
56 |
|
|
|
57 |
|
|
const int ERR_LINK_LIST_ONLY = 300;
|
58 |
|
|
const int ERR_LINK_FILE_TYPE = 301;
|
59 |
|
|
const int ERR_LINK_FILE_TYPE_LIB = 302;
|
60 |
|
|
const int ERR_LINK_FILE_TYPE_EXE = 303;
|
61 |
|
|
const int ERR_LINK_COMMUNAL = 304;
|
62 |
|
|
const int ERR_LINK_DUPLICATE_SYMBOL = 305;
|
63 |
|
|
const int ERR_LINK_DIFFERENT_BASE = 306;
|
64 |
|
|
const int ERR_LINK_MISALIGNED_TARGET = 307;
|
65 |
|
|
const int ERR_LINK_OVERFLOW = 308;
|
66 |
|
|
const int ERR_LINK_RELOCATION_OVERFLOW = 309;
|
67 |
|
|
const int ERR_LINK_REGUSE = 310;
|
68 |
|
|
const int ERR_LINK_MODULE_NOT_FOUND = 311;
|
69 |
|
|
const int ERR_EVENT_SIZE = 312;
|
70 |
|
|
const int ERR_REL_SYMBOL_NOT_FOUND = 313;
|
71 |
|
|
const int ERR_CANT_RELINK_MODULE = 314;
|
72 |
|
|
const int ERR_CANT_RELINK_LIBRARY = 315;
|
73 |
|
|
const int ERR_RELINK_MODULE_NOT_FOUND = 316;
|
74 |
|
|
const int ERR_RELINK_LIBRARY_NOT_FOUND = 317;
|
75 |
|
|
const int ERR_RELINK_BASE_POINTER_MOD = 318;
|
76 |
|
|
const int ERR_INPUT_NOT_RELINKABLE = 319;
|
77 |
|
|
const int ERR_LINK_UNRESOLVED = 320;
|
78 |
|
|
const int ERR_LINK_UNRESOLVED_WARN = 321;
|
79 |
|
|
|
80 |
|
|
const int ERR_TOO_MANY_ERRORS = 500;
|
81 |
|
|
const int ERR_BIG_ENDIAN = 501;
|
82 |
|
|
const int ERR_INTERNAL = 502;
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
// Error id numbers during assembly
|
86 |
|
|
const int ERR_CONTROL_CHAR = 0x100; // illegal control character
|
87 |
|
|
const int ERR_ILLEGAL_CHAR = 0x101; // illegal character
|
88 |
|
|
const int ERR_COMMENT_BEGIN = 0x102; // unmatched comment begin
|
89 |
|
|
const int ERR_COMMENT_END = 0x103; // unmatched comment end
|
90 |
|
|
const int ERR_BRACKET_BEGIN = 0x104; // unmatched begin bracket
|
91 |
|
|
const int ERR_BRACKET_END = 0x105; // unmatched end bracket
|
92 |
|
|
const int ERR_QUOTE_BEGIN = 0x106; // unmatched quote begin
|
93 |
|
|
const int ERR_QUESTION_MARK = 0x108; // unmatched '?'
|
94 |
|
|
const int ERR_COLON = 0x109; // unmatched ':'
|
95 |
|
|
const int ERR_SYMBOL_DEFINED = 0x10A; // symbol already defined
|
96 |
|
|
const int ERR_SYMBOL_UNDEFINED = 0x10B; // symbol not defined
|
97 |
|
|
const int ERR_UNFINISHED_VAR = 0x10C; // unfinished variable declaration
|
98 |
|
|
const int ERR_MISSING_EXPR = 0x10D; // unfinished variable declaration
|
99 |
|
|
const int ERR_MULTIDIMENSIONAL = 0x110; // multidimensional array not allowed
|
100 |
|
|
const int ERR_CONFLICT_ARRAYSZ = 0x111; // conflicting array size
|
101 |
|
|
const int ERR_CONFLICT_TYPE = 0x112; // conflicting array type
|
102 |
|
|
const int ERR_CONDITION = 0x113; // incorrect condition for ?: operator
|
103 |
|
|
const int ERR_OVERFLOW = 0x114; // overflow in asseble-time calculation
|
104 |
|
|
const int ERR_WRONG_TYPE = 0x115; // wrong type for operator
|
105 |
|
|
const int ERR_WRONG_TYPE_VAR = 0x116; // wrong or mismatched type for variable
|
106 |
|
|
const int ERR_WRONG_OPERANDS = 0x117; // wrong operands for this instruction
|
107 |
|
|
const int ERR_MISSING_DESTINATION = 0x118; // destination required
|
108 |
|
|
const int ERR_NO_DESTINATION = 0x119; // should not have destination
|
109 |
|
|
const int ERR_NOT_OP_AMBIGUOUS = 0x11A; // '!' operator on register or memory is ambiguous
|
110 |
|
|
const int ERR_TOO_COMPLEX = 0x11B; // expression is too complex for a single instruction
|
111 |
|
|
const int ERR_MASK_NOT_REGISTER = 0x11C; // mask must be a register
|
112 |
|
|
const int ERR_FALLBACK_WRONG = 0x11D; // fallback must be a register or zero
|
113 |
|
|
const int ERR_CONSTANT_TOO_LARGE = 0x11E; // immediate constant too large for specified type
|
114 |
|
|
const int ERR_ALIGNMENT = 0x11F; // alignment too high or not a power of 2
|
115 |
|
|
const int ERR_SECTION_DIFFERENT_TYPE = 0x120; // redefinition of section is different type
|
116 |
|
|
const int ERR_EXPECT_COLON = 0x121; // expect colon after label
|
117 |
|
|
const int ERR_STRING_TYPE = 0x122; // string must have type int8
|
118 |
|
|
const int ERR_NONZERO_IN_BSS = 0x123; // nonzero value in uninitialized section
|
119 |
|
|
const int ERR_SYMBOL_REDEFINED = 0x124; // symbol has been assigned more than one value
|
120 |
|
|
const int ERR_EXPORT_EXPRESSION = 0x125; // cannot export expression
|
121 |
|
|
const int ERR_CANNOT_EXPORT = 0x126; // cannot export this type of symbol
|
122 |
|
|
const int ERR_CODE_WO_SECTION = 0x127; // code without section
|
123 |
|
|
const int ERR_DATA_WO_SECTION = 0x128; // data without section
|
124 |
|
|
const int ERR_MIX_DATA_AND_CODE = 0x129; // mixing data and code in same section
|
125 |
|
|
const int ERR_MUST_BE_CONSTANT = 0x12A; // option value must be constant
|
126 |
|
|
const int ERR_MEM_COMPONENT_TWICE = 0x140; // component of memory operand specified twice
|
127 |
|
|
const int ERR_SCALE_FACTOR = 0x141; // wrong scale factor
|
128 |
|
|
const int ERR_MUST_BE_GP = 0x142; // length or broadcast must be general purpose register
|
129 |
|
|
const int ERR_LIMIT_AND_OFFSET = 0x143; // cannot have both limit and offset
|
130 |
|
|
const int ERR_NOT_INSIDE_MEM = 0x144; // mask option not allowed inside memory operand
|
131 |
|
|
const int ERR_TOO_MANY_OPERANDS = 0x145; // too many operands
|
132 |
|
|
const int ERR_TOO_FEW_OPERANDS = 0x146; // too many operands
|
133 |
|
|
const int ERR_OPERANDS_WRONG_ORDER = 0x147; // operands in wrong order
|
134 |
|
|
const int ERR_BOTH_MEM_AND_IMMEDIATE = 0x148; // cannot have both memory operand and immediate constant
|
135 |
|
|
const int ERR_BOTH_MEM_AND_OPTIONS = 0x149; // cannot have both memory operand and options
|
136 |
|
|
const int ERR_UNFINISHED_INSTRUCTION = 0x14A; // unfinished instruction code
|
137 |
|
|
const int ERR_TYPE_MISSING = 0x14B; // type must be specified
|
138 |
|
|
const int ERR_MASK_FALLBACK_TYPE = 0x14C; // mask and fallback must have same type as destination
|
139 |
|
|
const int ERR_NEG_INDEX_LENGTH = 0x14D; // length must be the same as negative index
|
140 |
|
|
const int ERR_INDEX_AND_LENGTH = 0x14E; // cannot have length/broadcast and index
|
141 |
|
|
const int ERR_MASK_REGISTER = 0x14F; // mask register number > 6
|
142 |
|
|
const int ERR_LIMIT_TOO_HIGH = 0x150; // limit on memory operand too high
|
143 |
|
|
const int ERR_NO_INSTRUCTION_FIT = 0x151; // no version of this instruction fits the specified operands
|
144 |
|
|
const int ERR_CANNOT_SWAP_VECT = 0x152; // cannot change the order of vector registers
|
145 |
|
|
const int ERR_EXPECT_JUMP_TARGET = 0x158; // expecting jump target
|
146 |
|
|
const int ERR_JUMP_TARGET_MISALIGN = 0x159; // jump target offset must be divisible by 4
|
147 |
|
|
const int ERR_ABS_RELOCATION = 0x15a; // absolute address not allowed here
|
148 |
|
|
const int ERR_ABS_RELOCATION_WARN = 0x15b; // absolute address allowed, but not recommended. make warning
|
149 |
|
|
const int ERR_RELOCATION_DOMAIN = 0x15c; // cannot calculate difference between two symbols in different domains
|
150 |
|
|
const int ERR_WRONG_REG_TYPE = 0x160; // wrong type for register operand
|
151 |
|
|
const int ERR_CONFLICT_OPTIONS = 0x161; // conflicting options on memory operand
|
152 |
|
|
const int ERR_VECTOR_OPTION = 0x162; // vector option applied to non-vector operands
|
153 |
|
|
const int ERR_LENGTH_OPTION_MISS = 0x163; // vector memory operand must have scalar, length, or broadcast option
|
154 |
|
|
const int ERR_DEST_BROADCAST = 0x164; // memory destination operand cannot have broadcast
|
155 |
|
|
const int ERR_OFFSET_TOO_LARGE = 0x165; // address offset too large
|
156 |
|
|
const int ERR_LIMIT_TOO_LARGE = 0x166; // index limit too large
|
157 |
|
|
const int ERR_IMMEDIATE_TOO_LARGE = 0x167; // instruction format does not have space for full-size constant and option/signbits
|
158 |
|
|
const int ERR_TOO_LARGE_FOR_JUMP = 0x168; // jump instruction does not have space for full-size constant
|
159 |
|
|
const int ERR_CANNOT_HAVE_OPTION = 0x169; // this instruction cannot have options
|
160 |
|
|
const int ERR_CANNOT_HAVEFALLBACK1 = 0x16A; // cannot have fallback register
|
161 |
|
|
const int ERR_CANNOT_HAVEFALLBACK2 = 0x16B; // cannot have fallback != destination with this memory operand
|
162 |
|
|
const int ERR_3OP_AND_FALLBACK = 0x16C; // cannot have fallback != destination with three operands
|
163 |
|
|
const int ERR_3OP_AND_MEM = 0x16D; // the first source register must be the same as the destination when there is a memory operand with index or vector
|
164 |
|
|
const int ERR_R28_30_BASE = 0x16E; // cannot use r28-r30 as base pointer with more than 8 bits offset
|
165 |
|
|
const int ERR_NO_BASE = 0x16F; // memory operand has no base pointer
|
166 |
|
|
const int ERR_MEM_WO_BRACKET = 0x170; // memory operand requires [] bracket
|
167 |
|
|
const int ERR_UNKNOWN = 0x171; // unknown error during assembly
|
168 |
|
|
const int ERR_UNMATCHED_END = 0x210; // unmatched end
|
169 |
|
|
const int ERR_SECTION_MISS_END = 0x211; // missing end of section
|
170 |
|
|
const int ERR_FUNCTION_MISS_END = 0x212; // missing end of function
|
171 |
|
|
const int ERR_ELSE_WO_IF = 0x222; // else without if
|
172 |
|
|
const int ERR_EXPECT_PARENTHESIS = 0x223; // expecting parenthesis after if, for, while, switch
|
173 |
|
|
const int ERR_EXPECT_BRACKET = 0x224; // expecting bracket after if, for, while, switch()
|
174 |
|
|
const int ERR_EXPECT_LOGICAL = 0x225; // expecting logical expression in if() or while()
|
175 |
|
|
const int ERR_MEM_NOT_ALLOWED = 0x226; // cannot have memory operand
|
176 |
|
|
//const int ERR_MUST_BE_POW2 = 0x227; // constant must have only one bit set
|
177 |
|
|
const int ERR_WHILE_EXPECTED = 0x228; // 'while' expected after 'do'
|
178 |
|
|
const int ERR_MISPLACED_BREAK = 0x229; // nothing: to break out of
|
179 |
|
|
const int ERR_MISPLACED_CONTINUE = 0x22A; // no loop to continue
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
// Structure for defining error message texts
|
184 |
|
|
struct SErrorText {
|
185 |
|
|
int errorNumber; // Error number
|
186 |
|
|
int status; // bit 0-3 = severity: 0 = ignore, 1 = warning, 2 = error, 9 = abort
|
187 |
|
|
// bit 8 = error number not found
|
188 |
|
|
char const * text; // Error text
|
189 |
|
|
};
|
190 |
|
|
|
191 |
|
|
// General error routine for reporting warning and error messages to STDERR output
|
192 |
|
|
class CErrorReporter {
|
193 |
|
|
public:
|
194 |
|
|
CErrorReporter(); // Default constructor
|
195 |
|
|
static SErrorText *FindError(int ErrorNumber);// Search for error in ErrorTexts
|
196 |
|
|
void submit(int ErrorNumber); // Print error message
|
197 |
|
|
void submit(int ErrorNumber, int extra); // Print error message with extra info
|
198 |
|
|
void submit(int ErrorNumber, int, int); // Print error message with two extra numbers inserted
|
199 |
|
|
void submit(int ErrorNumber, char const * extra); // Print error message with extra info
|
200 |
|
|
void submit(int ErrorNumber, char const *, char const *); // Print error message with two extra text fields inserted
|
201 |
|
|
void submit(int ErrorNumber, char const * extra1, char const * extra2, char const * extra3);// Print error message with three extra text fields
|
202 |
|
|
void submit(int ErrorNumber, int, char const *); // Print error message with two extra text fields inserted
|
203 |
|
|
int number(); // Get number of errors
|
204 |
|
|
int getWorstError(); // Get highest warning or error number encountered
|
205 |
|
|
void clearError(int ErrorNumber); // Ignore further occurrences of this error
|
206 |
|
|
protected:
|
207 |
|
|
int numErrors; // Number of errors detected
|
208 |
|
|
int numWarnings; // Number of warnings detected
|
209 |
|
|
int worstError; // Highest error number encountered
|
210 |
|
|
int maxWarnings; // Max number of warning messages to pring
|
211 |
|
|
int maxErrors; // Max number of error messages to print
|
212 |
|
|
void handleError(SErrorText * err, char const * text); // Used by submit function
|
213 |
|
|
};
|
214 |
|
|
|
215 |
|
|
extern CErrorReporter err; // Error handling object is in error.cpp
|
216 |
|
|
extern SErrorText errorTexts[]; // List of error texts
|
217 |
|
|
|
218 |
|
|
|