Debian Codegraph @

include/fcml_errors.h

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /** @file fcml_errors.h
21 * Global error handling related declarations.
22 * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved.
23 * This project is released under the GNU Lesser General Public License.
24 */
25
26 #ifndef FCML_ASM_ERRORS_H_
27 #define FCML_ASM_ERRORS_H_
28
29 #include "fcml_lib_export.h"
30
31 #include "fcml_types.h"
32
33 /**
34 * @defgroup ERRORS_GROUP Global error codes
35 * Describes all available global error codes.
36 * @{
37 */
38
39 /** All global error codes are placed here. */
40 enum fcml_en_ceh_error_globals {
41 /** Operation succeed. */
42 FCML_CEH_GEC_NO_ERROR = 0,
43 /** There is not enough memory to complete operation. */
44 FCML_CEH_GEC_OUT_OF_MEMORY = 1,
45 /** Invalid function arguments. */
46 FCML_CEH_GEC_INVALID_INPUT = 2,
47 /** An internal error occurred. Enable tracing in order to get more
48 * detailed information. */
49 FCML_CEH_GEC_INTERNAL_ERROR = 3,
50 /** Component hasn't been initialized yet. */
51 FCML_CEH_GEC_NOT_INITIALIZED = 4,
52 /** Incomplete instruction. */
53 FCML_CEH_GEC_EOF = 5,
54 /** Used mainly in case of integers and offsets. */
55 FCML_CEH_GEC_VALUE_OUT_OF_RANGE = 6,
56 /** Chosen operation is not supported in case of given configuration. */
57 FCML_CEH_GEC_FEATURE_NOT_SUPPORTED = 7,
58 /** Unsupported operating mode. For instance encoded instruction needs 16
59 * bit operating mode, but we are in 64 bit mode. */
60 FCML_CEH_GEC_INVALID_OPERATING_MODE = 8,
61 /** Chosen addressing form can not be encoded as for example ModR/M field. */
62 FCML_CEH_GEC_INVALID_ADDRESSING_FORM = 9,
63 /** Unsupported instruction form (Instruction may be supported, but not
64 * with given set of operands). */
65 FCML_CEH_GEC_INVALID_INSTRUCTION_FORM = 10,
66 /** Instruction do not support one of the defined operands. */
67 FCML_CEH_GEC_INVALID_OPPERAND = 11,
68 /** Unknown mnemonic. */
69 FCML_CEH_GEC_UNKNOWN_MNEMONIC = 12,
70 /** Operand size (Operand size attribute) is not allowed in given context. */
71 FCML_CEH_GEC_INVALID_OPPERAND_SIZE = 13,
72 /** Address size (Address size attribute) is not allowed in given context. */
73 FCML_CEH_GEC_INVALID_ADDRESS_SIZE = 14,
74 /** User chosen unsupported addressing form */
75 FCML_CEH_GEC_UNKNOWN_INSTRUCTION = 15,
76 /** Assembler can return this error code if there is not allowed prefix
77 * defined for given instruction. */
78 FCML_CEH_GEC_INVALID_PREFIX = 16,
79 /** Wrong register type. */
80 FCML_CEH_GEC_INVALID_REGISTER_TYPE = 17,
81 /** Wrong register. */
82 FCML_CEH_GEC_INVALID_REGISTER = 18,
83 /** Error returned by parsers when there is undefined symbol used. */
84 FCML_CEH_GEC_UNDEFINED_SYMBOL = 19,
85 /** Labels are not supported. */
86 FCML_CEH_GEC_UNSUPPORTED_LABEL_DECLARATION = 20,
87 /** Required operand decorator is missing. */
88 FCML_CEH_GEC_MISSING_DECORATOR = 21,
89 /** Given operand decorator is not supported by operand. */
90 FCML_CEH_GEC_NOT_SUPPORTED_DECORATOR = 22,
91 /** Gap between operands found. */
92 FCML_CEH_GEC_INVALID_INSTRUCTION_MODEL = 23,
93 /* Decorator is invalid. For example wrong register type is used in
94 * opmask decorator. */
95 FCML_CEH_GEC_INVALID_OPERAND_DECORATOR = 24
96 };
97
98 /** @} */
99
100 /**
101 * @defgroup MESSAGE_ERRORS_GROUP Error codes for textual messages
102 * Describes all available error codes dedicated to textual errors.
103 * @{
104 */
105
106 /** Error codes dedicated to textual messages.
107 * In some cases they are a bit more detailed than corresponding
108 * global error codes returned in case of errors. Remember that global
109 * error codes also can be used in place of error codes for textual
110 * messages. It is why they use different code ranges.
111 */
112 enum fcml_en_ceh_message_errors {
113 /** Segment register can not be overridden. */
114 FCML_CEH_MEC_ERROR_ILLEGAL_SEG_REG_OVERRIDE = 1000,
115 /** To many operands passed to parser. */
116 FCML_CEH_MEC_ERROR_TO_MANY_OPERANDS = 1001,
117 /** Unsupported pseudo-op value. */
118 FCML_CEH_MEC_ERROR_INVALID_PSEUDO_OPCODE_VALUE = 1002,
119 /** HLE prefix is not allowed in given context. */
120 FCML_CEH_MEC_ERROR_HLE_PREFIX_NOT_ALLOWED = 1003,
121 /** There is more than one HLE prefix. */
122 FCML_CEH_MEC_ERROR_HLE_MORE_THAN_ONE_PREFIX = 1004,
123 /** Expression attempts to divide by 0 */
124 FCML_CEH_MEC_ERROR_DIVISION_BY_0 = 1005,
125 /** Wrong value type used in given context. For example float used
126 * in place of integer. */
127 FCML_CEH_MEC_ERROR_WRONG_VALUE_FORMAT = 1006,
128 /** Value out of range, for example 32 bit value used as
129 * segment selector. */
130 FCML_CEH_MEC_ERROR_VALUE_OUT_OF_RANGE = 1007,
131 /** Syntax error from parser. */
132 FCML_CEH_MEC_ERROR_INVALID_SYNTAX = 1008,
133 /** Wrong register type used in place of segment register. */
134 FCML_CEH_MEC_ERROR_INVALID_REGISTER_TYPE_SEG = 1009,
135 /** Symbol is already defined in parser's symbol table. */
136 FCML_CEH_MEC_ERROR_SYMBOL_ALREADY_DEFINED = 1010,
137 /** Symbol is undefined. */
138 FCML_CEH_MEC_ERROR_UNDEFINED_SYMBOL = 1011,
139 /** Parsed line exceed maximal allowed length. */
140 FCML_CEH_MEC_ERROR_PARSED_LINE_TOO_LONG = 1012,
141 /** Invalid vector length size. */
142 FCML_CEH_MEC_ERROR_INVALID_VECTOR_LENGTH = 1013
143 };
144
145 /** Codes for textual warnings. */
146 enum fcml_en_ceh_message_warnings {
147 /** Value out of range */
148 FCML_CEH_MEW_WARN_VALUE_OUT_OF_RANGE = 2000,
149 /** Invalid addressing mode. */
150 FCML_CEH_MEW_WARN_INVALID_ADDRESSING_MODE = 2001
151 };
152
153 /** @} */
154
155 /** All error codes should be held in variables of this type. */
156 typedef fcml_uint16_t fcml_ceh_error;
157
158 /** Error levels. */
159 typedef enum fcml_en_ceh_error_level {
160 /** Warnings are reported when processing does not need to be stopped. */
161 FCML_EN_CEH_EL_WARN,
162 /** Errors are reported when something more important happened and
163 * processing should be stopped. */
164 FCML_EN_CEH_EL_ERROR
165 } fcml_en_ceh_error_level;
166
167 /** Information about one particular error/warning. */
168 typedef struct fcml_st_ceh_error_info {
169 /** Next error/warning on the list. */
170 struct fcml_st_ceh_error_info *next_error;
171 /** Error message. */
172 fcml_string message;
173 /** Error code */
174 fcml_ceh_error code;
175 /** Error level. */
176 fcml_en_ceh_error_level level;
177 } fcml_st_ceh_error_info;
178
179 /** Container for all collected errors and warnings. */
180 typedef struct fcml_st_ceh_error_container {
181 /** All errors and warnings going here. */
182 fcml_st_ceh_error_info *errors;
183 /** Pointer to the last error/warning on the list. */
184 fcml_st_ceh_error_info *last_error;
185 } fcml_st_ceh_error_container;
186
187 #endif /* FCML_ASM_ERRORS_H_ */