Debian Codegraph @

src/fcml_common_lex.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 #ifndef FCML_COMMON_LEX_H_
21 #define FCML_COMMON_LEX_H_
22
23 #include <fcml_common.h>
24 #include <fcml_types.h>
25
26 #include "fcml_env_int.h"
27 #include "fcml_parser_utils.h"
28
29 /* GPR */
30 #define FCML_FM_GPRS_8_REG(x) { fcml_fn_pu_parse_register(FCML_REG_GPR, \
31 FCML_DS_8, x, FCML_FALSE, &(yylval->reg_value) ); \
32 return FCML_TK_REG_GPR; }
33
34 #define FCML_FM_GPRS_8_X_REG(x) { fcml_fn_pu_parse_register(FCML_REG_GPR, \
35 FCML_DS_8, x, FCML_TRUE, &(yylval->reg_value) ); \
36 return FCML_TK_REG_GPR; }
37
38 #define FCML_FM_GPRS_16_REG(x) { fcml_fn_pu_parse_register(FCML_REG_GPR, \
39 FCML_DS_16, x, FCML_FALSE, &(yylval->reg_value) ); \
40 return FCML_TK_REG_GPR; }
41
42 #define FCML_FM_GPRS_32_REG(x) { fcml_fn_pu_parse_register(FCML_REG_GPR, \
43 FCML_DS_32, x, FCML_FALSE, &(yylval->reg_value) ); \
44 return FCML_TK_REG_GPR; }
45
46 #define FCML_FM_GPRS_64_REG(x) { fcml_fn_pu_parse_register(FCML_REG_GPR, \
47 FCML_DS_64, x, FCML_FALSE, &(yylval->reg_value) ); \
48 return FCML_TK_REG_GPR; }
49
50 /* SIMD */
51 #define FCML_FM_SIMD_64_REG(x) { fcml_fn_pu_parse_register(FCML_REG_SIMD, \
52 FCML_DS_64, x, FCML_FALSE, &(yylval->reg_value) ); \
53 return FCML_TK_REG_SIMD; }
54
55 #define FCML_FM_SIMD_128_REG(x) { fcml_fn_pu_parse_register(FCML_REG_SIMD, \
56 FCML_DS_128, x, FCML_FALSE, &(yylval->reg_value) ); \
57 return FCML_TK_REG_SIMD; }
58
59 #define FCML_FM_SIMD_256_REG(x) { fcml_fn_pu_parse_register(FCML_REG_SIMD, \
60 FCML_DS_256, x, FCML_FALSE, &(yylval->reg_value) ); \
61 return FCML_TK_REG_SIMD; }
62
63 #define FCML_FM_SIMD_512_REG(x) { fcml_fn_pu_parse_register(FCML_REG_SIMD, \
64 FCML_DS_512, x, FCML_FALSE, &(yylval->reg_value) ); \
65 return FCML_TK_REG_SIMD; }
66
67 /* FPU */
68 #define FCML_FM_FPU_REG(x) { fcml_fn_pu_parse_register(FCML_REG_FPU, \
69 FCML_DS_UNDEF, x, FCML_FALSE, &(yylval->reg_value) ); \
70 return FCML_TK_REG_FPU; }
71
72 /* Control registers. */
73 #define FCML_FM_CR_REG(x) { fcml_fn_pu_parse_register(FCML_REG_CR, \
74 FCML_DS_UNDEF, x, FCML_FALSE, &(yylval->reg_value) ); \
75 return FCML_TK_REG_CR; }
76
77 /* Debug registers. */
78 #define FCML_FM_DR_REG(x) { fcml_fn_pu_parse_register(FCML_REG_DR, \
79 FCML_DS_UNDEF, x, FCML_FALSE, &(yylval->reg_value) ); \
80 return FCML_TK_REG_DR; }
81
82 /* Segment registers. */
83 #define FCML_FM_SEG_REG(x) { fcml_fn_pu_parse_register(FCML_REG_SEG, \
84 FCML_DS_UNDEF, x, FCML_FALSE, &(yylval->reg_value) ); \
85 return FCML_TK_REG_SEG; }
86
87 /* Opmask registers. */
88 #define FCML_FM_OPMASK_REG(x) { fcml_fn_pu_parse_register(FCML_REG_OPMASK, \
89 FCML_DS_64, x, FCML_FALSE, &(yylval->reg_value) ); \
90 return FCML_TK_REG_OPMASK; }
91
92 /* RIP */
93 #define FCML_FM_RIP { fcml_fn_pu_parse_register(FCML_REG_IP, \
94 FCML_DS_64, FCML_REG_UNDEFINED, FCML_FALSE, &(yylval->reg_value) ); \
95 return FCML_TK_REG_RIP; }
96
97 /* AVX-512 Broadcast. */
98 #define FCML_FM_BCAST_DECORATOR(x) { yylval->int_value = x; \
99 return FCML_TK_DECORATOR_BCAST; }
100
101 /* AVX-512 Embedded rounding. */
102 #define FCML_FM_ER_DECORATOR(x) { yylval->int_value = x; \
103 return FCML_TK_DECORATOR_ER; }
104
105 /* AVX-512 Opmask registers decorators. */
106 #define FCML_FM_OPMASK_REG_DECORATOR(x) { \
107 fcml_fn_pu_parse_register(FCML_REG_OPMASK, \
108 FCML_DS_64, x, FCML_FALSE, &(yylval->reg_value) ); \
109 return FCML_TK_OPMASK_REG_DECORATOR; }
110
111 #define YY_USER_ACTION \
112 yylloc->first_line = yylloc->last_line; \
113 yylloc->first_column = yylloc->last_column; \
114 for(int i = 0; yytext[i] != '\0'; i++) { \
115 if(yytext[i] == '\n') { \
116 yylloc->last_line++; \
117 yylloc->last_column = 0; \
118 } \
119 else { \
120 yylloc->last_column++; \
121 } \
122 }
123
124 #endif /* FCML_COMMON_LEX_H_ */