]>
git.proxmox.com Git - mirror_qemu.git/blob - target/hexagon/idef-parser/parser-helpers.h
2766296417632e42d8b49353a597f685a1edaf11
2 * Copyright(c) 2019-2022 rev.ng Labs Srl. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 #ifndef PARSER_HELPERS_H
19 #define PARSER_HELPERS_H
31 #include "tcg/tcg-cond.h"
33 #include "idef-parser.tab.h"
34 #include "idef-parser.yy.h"
35 #include "idef-parser.h"
37 /* Decomment this to disable yyasserts */
40 #define ERR_LINE_CONTEXT 40
42 #define START_COMMENT "/" "*"
43 #define END_COMMENT "*" "/"
45 void yyerror(YYLTYPE
*locp
,
46 yyscan_t scanner
__attribute__((unused
)),
51 #define yyassert(context, locp, condition, msg) \
53 yyerror(locp, (context)->scanner, (context), (msg)); \
57 bool is_direct_predicate(HexValue
*value
);
59 bool is_inside_ternary(Context
*c
);
65 void str_print(Context
*c
, YYLTYPE
*locp
, const char *string
);
67 void uint8_print(Context
*c
, YYLTYPE
*locp
, uint8_t *num
);
69 void uint64_print(Context
*c
, YYLTYPE
*locp
, uint64_t *num
);
71 void int_print(Context
*c
, YYLTYPE
*locp
, int *num
);
73 void uint_print(Context
*c
, YYLTYPE
*locp
, unsigned *num
);
75 void tmp_print(Context
*c
, YYLTYPE
*locp
, HexTmp
*tmp
);
77 void pred_print(Context
*c
, YYLTYPE
*locp
, HexPred
*pred
, bool is_dotnew
);
79 void reg_compose(Context
*c
, YYLTYPE
*locp
, HexReg
*reg
, char reg_id
[5]);
81 void reg_print(Context
*c
, YYLTYPE
*locp
, HexReg
*reg
);
83 void imm_print(Context
*c
, YYLTYPE
*locp
, HexImm
*imm
);
85 void var_print(Context
*c
, YYLTYPE
*locp
, HexVar
*var
);
87 void rvalue_print(Context
*c
, YYLTYPE
*locp
, void *pointer
);
89 void out_assert(Context
*c
, YYLTYPE
*locp
, void *dummy
);
92 * Copies output code buffer into stdout
94 void commit(Context
*c
);
96 #define OUT_IMPL(c, locp, x) \
99 uint8_t: uint8_print, \
100 uint64_t: uint64_print, \
102 unsigned: uint_print, \
103 HexValue: rvalue_print, \
104 default: out_assert \
108 #define FE_1(c, locp, WHAT, X) WHAT(c, locp, X)
109 #define FE_2(c, locp, WHAT, X, ...) \
110 WHAT(c, locp, X)FE_1(c, locp, WHAT, __VA_ARGS__)
111 #define FE_3(c, locp, WHAT, X, ...) \
112 WHAT(c, locp, X)FE_2(c, locp, WHAT, __VA_ARGS__)
113 #define FE_4(c, locp, WHAT, X, ...) \
114 WHAT(c, locp, X)FE_3(c, locp, WHAT, __VA_ARGS__)
115 #define FE_5(c, locp, WHAT, X, ...) \
116 WHAT(c, locp, X)FE_4(c, locp, WHAT, __VA_ARGS__)
117 #define FE_6(c, locp, WHAT, X, ...) \
118 WHAT(c, locp, X)FE_5(c, locp, WHAT, __VA_ARGS__)
119 #define FE_7(c, locp, WHAT, X, ...) \
120 WHAT(c, locp, X)FE_6(c, locp, WHAT, __VA_ARGS__)
121 #define FE_8(c, locp, WHAT, X, ...) \
122 WHAT(c, locp, X)FE_7(c, locp, WHAT, __VA_ARGS__)
123 #define FE_9(c, locp, WHAT, X, ...) \
124 WHAT(c, locp, X)FE_8(c, locp, WHAT, __VA_ARGS__)
125 /* repeat as needed */
127 #define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, NAME, ...) NAME
129 #define FOR_EACH(c, locp, action, ...) \
131 GET_MACRO(__VA_ARGS__, \
140 FE_1)(c, locp, action, \
144 #define OUT(c, locp, ...) FOR_EACH((c), (locp), OUT_IMPL, __VA_ARGS__)
146 const char *cmp_swap(Context
*c
, YYLTYPE
*locp
, const char *type
);
149 * Temporary values creation
152 HexValue
gen_tmp(Context
*c
,
155 HexSignedness signedness
);
157 HexValue
gen_tmp_value(Context
*c
,
161 HexSignedness signedness
);
163 HexValue
gen_imm_value(Context
*c
__attribute__((unused
)),
167 HexSignedness signedness
);
169 HexValue
gen_imm_qemu_tmp(Context
*c
, YYLTYPE
*locp
, unsigned bit_width
,
170 HexSignedness signedness
);
172 void gen_rvalue_free(Context
*c
, YYLTYPE
*locp
, HexValue
*rvalue
);
174 HexValue
rvalue_materialize(Context
*c
, YYLTYPE
*locp
, HexValue
*rvalue
);
176 HexValue
gen_rvalue_extend(Context
*c
, YYLTYPE
*locp
, HexValue
*rvalue
);
178 HexValue
gen_rvalue_truncate(Context
*c
, YYLTYPE
*locp
, HexValue
*rvalue
);
180 void gen_varid_allocate(Context
*c
,
184 HexSignedness signedness
);
187 * Code generation functions
190 HexValue
gen_bin_cmp(Context
*c
,
196 HexValue
gen_bin_op(Context
*c
,
202 HexValue
gen_cast_op(Context
*c
,
205 unsigned target_width
,
206 HexSignedness signedness
);
209 * gen_extend_op extends a region of src_width_ptr bits stored in a
210 * value_ptr to the size of dst_width. Note: src_width_ptr is a
211 * HexValue * to handle the special case where it is unknown at
214 HexValue
gen_extend_op(Context
*c
,
219 HexSignedness signedness
);
221 void gen_rdeposit_op(Context
*c
,
228 void gen_deposit_op(Context
*c
,
235 HexValue
gen_rextract_op(Context
*c
,
241 HexValue
gen_extract_op(Context
*c
,
245 HexExtract
*extract
);
247 HexValue
gen_read_reg(Context
*c
, YYLTYPE
*locp
, HexValue
*reg
);
249 void gen_write_reg(Context
*c
, YYLTYPE
*locp
, HexValue
*reg
, HexValue
*value
);
251 void gen_assign(Context
*c
,
256 HexValue
gen_convround(Context
*c
,
260 HexValue
gen_round(Context
*c
,
265 HexValue
gen_convround_n(Context
*c
,
271 * Circular addressing mode with auto-increment
273 void gen_circ_op(Context
*c
,
279 HexValue
gen_locnt_op(Context
*c
, YYLTYPE
*locp
, HexValue
*src
);
281 HexValue
gen_ctpop_op(Context
*c
, YYLTYPE
*locp
, HexValue
*src
);
283 HexValue
gen_rotl(Context
*c
, YYLTYPE
*locp
, HexValue
*src
, HexValue
*n
);
285 HexValue
gen_deinterleave(Context
*c
, YYLTYPE
*locp
, HexValue
*mixed
);
287 HexValue
gen_interleave(Context
*c
,
292 HexValue
gen_carry_from_add(Context
*c
,
298 void gen_addsat64(Context
*c
,
304 void gen_inst(Context
*c
, GString
*iname
);
306 void gen_inst_init_args(Context
*c
, YYLTYPE
*locp
);
308 void gen_inst_code(Context
*c
, YYLTYPE
*locp
);
310 void gen_pred_assign(Context
*c
, YYLTYPE
*locp
, HexValue
*left_pred
,
311 HexValue
*right_pred
);
313 void gen_cancel(Context
*c
, YYLTYPE
*locp
);
315 void gen_load_cancel(Context
*c
, YYLTYPE
*locp
);
317 void gen_load(Context
*c
, YYLTYPE
*locp
, HexValue
*size
,
318 HexSignedness signedness
, HexValue
*ea
, HexValue
*dst
);
320 void gen_store(Context
*c
, YYLTYPE
*locp
, HexValue
*size
, HexValue
*ea
,
323 void gen_sethalf(Context
*c
, YYLTYPE
*locp
, HexCast
*sh
, HexValue
*n
,
324 HexValue
*dst
, HexValue
*value
);
326 void gen_setbits(Context
*c
, YYLTYPE
*locp
, HexValue
*hi
, HexValue
*lo
,
327 HexValue
*dst
, HexValue
*value
);
329 unsigned gen_if_cond(Context
*c
, YYLTYPE
*locp
, HexValue
*cond
);
331 unsigned gen_if_else(Context
*c
, YYLTYPE
*locp
, unsigned index
);
333 HexValue
gen_rvalue_pred(Context
*c
, YYLTYPE
*locp
, HexValue
*pred
);
335 HexValue
gen_rvalue_var(Context
*c
, YYLTYPE
*locp
, HexValue
*var
);
337 HexValue
gen_rvalue_mpy(Context
*c
, YYLTYPE
*locp
, HexMpy
*mpy
, HexValue
*op1
,
340 HexValue
gen_rvalue_not(Context
*c
, YYLTYPE
*locp
, HexValue
*value
);
342 HexValue
gen_rvalue_notl(Context
*c
, YYLTYPE
*locp
, HexValue
*value
);
344 HexValue
gen_rvalue_sat(Context
*c
, YYLTYPE
*locp
, HexSat
*sat
, HexValue
*n
,
347 HexValue
gen_rvalue_fscr(Context
*c
, YYLTYPE
*locp
, HexValue
*value
);
349 HexValue
gen_rvalue_abs(Context
*c
, YYLTYPE
*locp
, HexValue
*value
);
351 HexValue
gen_rvalue_neg(Context
*c
, YYLTYPE
*locp
, HexValue
*value
);
353 HexValue
gen_rvalue_brev(Context
*c
, YYLTYPE
*locp
, HexValue
*value
);
355 HexValue
gen_rvalue_ternary(Context
*c
, YYLTYPE
*locp
, HexValue
*cond
,
356 HexValue
*true_branch
, HexValue
*false_branch
);
358 const char *cond_to_str(TCGCond cond
);
360 void emit_header(Context
*c
);
362 void emit_arg(Context
*c
, YYLTYPE
*locp
, HexValue
*arg
);
364 void emit_footer(Context
*c
);
366 void track_string(Context
*c
, GString
*s
);
368 void free_variables(Context
*c
, YYLTYPE
*locp
);
370 void free_instruction(Context
*c
);
372 void assert_signedness(Context
*c
,
374 HexSignedness signedness
);
376 #endif /* PARSER_HELPERS_h */