Coverage Report

Created: 2025-08-26 06:30

/src/capstonenext/arch/Xtensa/XtensaInstPrinter.c
Line
Count
Source (jump to first uncovered line)
1
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
3
/*    Rot127 <unisono@quyllur.org> 2022-2023 */
4
/* Automatically translated source file from LLVM. */
5
6
/* LLVM-commit: <commit> */
7
/* LLVM-tag: <tag> */
8
9
/* Only small edits allowed. */
10
/* For multiple similar edits, please create a Patch for the translator. */
11
12
/* Capstone's C++ file translator: */
13
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
14
15
//===- XtensaInstPrinter.cpp - Convert Xtensa MCInst to asm syntax --------===//
16
//
17
//                     The LLVM Compiler Infrastructure
18
//
19
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
20
// See https://llvm.org/LICENSE.txt for license information.
21
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22
//
23
//===----------------------------------------------------------------------===//
24
//
25
// This class prints an Xtensa MCInst to a .s file.
26
//
27
//===----------------------------------------------------------------------===//
28
29
#include <stdio.h>
30
#include <string.h>
31
#include <stdlib.h>
32
#include <capstone/platform.h>
33
34
#include "../../MCInstPrinter.h"
35
#include "../../SStream.h"
36
#include "./priv.h"
37
#include "../../Mapping.h"
38
39
#include "XtensaMapping.h"
40
#include "../../MathExtras.h"
41
42
#define CONCAT(a, b) CONCAT_(a, b)
43
#define CONCAT_(a, b) a##_##b
44
45
#define DEBUG_TYPE "asm-printer"
46
static MnemonicBitsInfo getMnemonic(MCInst *MI, SStream *O);
47
static const char *getRegisterName(unsigned RegNo);
48
49
typedef MCRegister Register;
50
51
static void printRegName(SStream *O, MCRegister Reg)
52
18
{
53
18
  SStream_concat0(O, getRegisterName(Reg));
54
18
}
55
56
static void printOp(MCInst *MI, MCOperand *MC, SStream *O)
57
176k
{
58
176k
  if (MCOperand_isReg(MC))
59
166k
    SStream_concat0(O, getRegisterName(MCOperand_getReg(MC)));
60
9.91k
  else if (MCOperand_isImm(MC))
61
9.91k
    printInt64(O, MCOperand_getImm(MC));
62
0
  else if (MCOperand_isExpr(MC))
63
0
    printExpr(MCOperand_getExpr(MC), O);
64
0
  else
65
0
    CS_ASSERT("Invalid operand");
66
176k
}
67
68
static void printOperand(MCInst *MI, const int op_num, SStream *O)
69
166k
{
70
166k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Operand, op_num);
71
166k
  printOp(MI, MCInst_getOperand(MI, op_num), O);
72
166k
}
73
74
static inline void printMemOperand(MCInst *MI, int OpNum, SStream *OS)
75
9.91k
{
76
9.91k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_MemOperand, OpNum);
77
9.91k
  SStream_concat0(OS, getRegisterName(MCOperand_getReg(
78
9.91k
            MCInst_getOperand(MI, (OpNum)))));
79
9.91k
  SStream_concat0(OS, ", ");
80
9.91k
  printOp(MI, MCInst_getOperand(MI, OpNum + 1), OS);
81
9.91k
}
82
83
static inline void printBranchTarget(MCInst *MI, int OpNum, SStream *OS)
84
6.03k
{
85
6.03k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_BranchTarget, OpNum);
86
6.03k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
87
6.03k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
88
6.03k
    int64_t Val = MCOperand_getImm(MC) + 4;
89
6.03k
    SStream_concat0(OS, ". ");
90
6.03k
    if (Val > 0)
91
3.56k
      SStream_concat0(OS, "+");
92
93
6.03k
    printInt64(OS, Val);
94
6.03k
  } else if (MCOperand_isExpr(MC))
95
0
    CS_ASSERT_RET(0 && "unimplemented expr printing");
96
0
  else
97
0
    CS_ASSERT(0 && "Invalid operand");
98
6.03k
}
99
100
static inline void printLoopTarget(MCInst *MI, int OpNum, SStream *OS)
101
303
{
102
303
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_LoopTarget, OpNum);
103
303
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
104
303
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
105
303
    int64_t Val = MCOperand_getImm(MC) + 4;
106
303
    SStream_concat0(OS, ". ");
107
303
    if (Val > 0)
108
303
      SStream_concat0(OS, "+");
109
110
303
    printInt64(OS, Val);
111
303
  } else if (MCOperand_isExpr(MC))
112
0
    CS_ASSERT_RET(0 && "unimplemented expr printing");
113
0
  else
114
0
    CS_ASSERT(0 && "Invalid operand");
115
303
}
116
117
static inline void printJumpTarget(MCInst *MI, int OpNum, SStream *OS)
118
1.47k
{
119
1.47k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_JumpTarget, OpNum);
120
1.47k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
121
1.47k
  if (MCOperand_isImm(MC)) {
122
1.47k
    int64_t Val = MCOperand_getImm(MC) + 4;
123
1.47k
    SStream_concat0(OS, ". ");
124
1.47k
    if (Val > 0)
125
937
      SStream_concat0(OS, "+");
126
127
1.47k
    printInt64(OS, Val);
128
1.47k
  } else if (MCOperand_isExpr(MC))
129
0
    CS_ASSERT_RET(0 && "unimplemented expr printing");
130
0
  else
131
0
    CS_ASSERT(0 && "Invalid operand");
132
1.47k
  ;
133
1.47k
}
134
135
static inline void printCallOperand(MCInst *MI, int OpNum, SStream *OS)
136
4.76k
{
137
4.76k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_CallOperand, OpNum);
138
4.76k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
139
4.76k
  if (MCOperand_isImm(MC)) {
140
4.76k
    int64_t Val = MCOperand_getImm(MC) + 4;
141
4.76k
    SStream_concat0(OS, ". ");
142
4.76k
    if (Val > 0)
143
3.15k
      SStream_concat0(OS, "+");
144
145
4.76k
    printInt64(OS, Val);
146
4.76k
  } else if (MCOperand_isExpr(MC))
147
0
    CS_ASSERT_RET(0 && "unimplemented expr printing");
148
0
  else
149
0
    CS_ASSERT(0 && "Invalid operand");
150
4.76k
}
151
152
static inline void printL32RTarget(MCInst *MI, int OpNum, SStream *O)
153
5.63k
{
154
5.63k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_L32RTarget, OpNum);
155
5.63k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
156
5.63k
  if (MCOperand_isImm(MC)) {
157
5.63k
    SStream_concat0(O, ". ");
158
5.63k
    printInt64(O, Xtensa_L32R_Value(MI, OpNum));
159
5.63k
  } else if (MCOperand_isExpr(MC))
160
0
    CS_ASSERT_RET(0 && "unimplemented expr printing");
161
0
  else
162
0
    CS_ASSERT(0 && "Invalid operand");
163
5.63k
}
164
165
static inline void printImm8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
166
260
{
167
260
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_AsmOperand, OpNum);
168
260
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
169
260
    int64_t Value =
170
260
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
171
260
    CS_ASSERT(
172
260
      isIntN(8, Value) &&
173
260
      "Invalid argument, value must be in ranges [-128,127]");
174
260
    printInt64(O, Value);
175
260
  } else {
176
0
    printOperand(MI, OpNum, O);
177
0
  }
178
260
}
179
180
static inline void printImm8_sh8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
181
663
{
182
663
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_sh8_AsmOperand, OpNum);
183
663
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
184
663
    int64_t Value =
185
663
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
186
663
    CS_ASSERT(
187
663
      (isIntN(16, Value) && ((Value & 0xFF) == 0)) &&
188
663
      "Invalid argument, value must be multiples of 256 in range "
189
663
      "[-32768,32512]");
190
663
    printInt64(O, Value);
191
663
  } else
192
0
    printOperand(MI, OpNum, O);
193
663
}
194
195
static inline void printImm12_AsmOperand(MCInst *MI, int OpNum, SStream *O)
196
0
{
197
0
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12_AsmOperand, OpNum);
198
0
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
199
0
    int64_t Value =
200
0
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
201
0
    CS_ASSERT(
202
0
      (Value >= -2048 && Value <= 2047) &&
203
0
      "Invalid argument, value must be in ranges [-2048,2047]");
204
0
    printInt64(O, Value);
205
0
  } else
206
0
    printOperand(MI, OpNum, O);
207
0
}
208
209
static inline void printImm12m_AsmOperand(MCInst *MI, int OpNum, SStream *O)
210
762
{
211
762
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12m_AsmOperand, OpNum);
212
762
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
213
762
    int64_t Value =
214
762
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
215
762
    CS_ASSERT(
216
762
      (Value >= -2048 && Value <= 2047) &&
217
762
      "Invalid argument, value must be in ranges [-2048,2047]");
218
762
    printInt64(O, Value);
219
762
  } else
220
0
    printOperand(MI, OpNum, O);
221
762
}
222
223
static inline void printUimm4_AsmOperand(MCInst *MI, int OpNum, SStream *O)
224
2.23k
{
225
2.23k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm4_AsmOperand, OpNum);
226
2.23k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
227
2.23k
    int64_t Value =
228
2.23k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
229
2.23k
    CS_ASSERT((Value >= 0 && Value <= 15) && "Invalid argument");
230
2.23k
    printInt64(O, Value);
231
2.23k
  } else
232
0
    printOperand(MI, OpNum, O);
233
2.23k
}
234
235
static inline void printUimm5_AsmOperand(MCInst *MI, int OpNum, SStream *O)
236
2.57k
{
237
2.57k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm5_AsmOperand, OpNum);
238
2.57k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
239
2.57k
    int64_t Value =
240
2.57k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
241
2.57k
    CS_ASSERT((Value >= 0 && Value <= 31) && "Invalid argument");
242
2.57k
    printInt64(O, Value);
243
2.57k
  } else
244
0
    printOperand(MI, OpNum, O);
245
2.57k
}
246
247
static inline void printShimm1_31_AsmOperand(MCInst *MI, int OpNum, SStream *O)
248
0
{
249
0
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm1_31_AsmOperand, OpNum);
250
0
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
251
0
    int64_t Value =
252
0
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
253
0
    CS_ASSERT((Value >= 1 && Value <= 31) &&
254
0
        "Invalid argument, value must be in range [1,31]");
255
0
    printInt64(O, Value);
256
0
  } else
257
0
    printOperand(MI, OpNum, O);
258
0
}
259
260
static inline void printShimm0_31_AsmOperand(MCInst *MI, int OpNum, SStream *O)
261
306
{
262
306
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm0_31_AsmOperand, OpNum);
263
306
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
264
306
    int64_t Value =
265
306
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
266
306
    CS_ASSERT((Value >= 0 && Value <= 31) &&
267
306
        "Invalid argument, value must be in range [0,31]");
268
306
    printInt64(O, Value);
269
306
  } else
270
0
    printOperand(MI, OpNum, O);
271
306
}
272
273
static inline void printImm1_16_AsmOperand(MCInst *MI, int OpNum, SStream *O)
274
1.05k
{
275
1.05k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1_16_AsmOperand, OpNum);
276
1.05k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
277
1.05k
    int64_t Value =
278
1.05k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
279
1.05k
    CS_ASSERT((Value >= 1 && Value <= 16) &&
280
1.05k
        "Invalid argument, value must be in range [1,16]");
281
1.05k
    printInt64(O, Value);
282
1.05k
  } else
283
0
    printOperand(MI, OpNum, O);
284
1.05k
}
285
286
static inline void printImm1n_15_AsmOperand(MCInst *MI, int OpNum, SStream *O)
287
5.68k
{
288
5.68k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1n_15_AsmOperand, OpNum);
289
5.68k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
290
5.68k
    int64_t Value =
291
5.68k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
292
5.68k
    CS_ASSERT(
293
5.68k
      (Value >= -1 && (Value != 0) && Value <= 15) &&
294
5.68k
      "Invalid argument, value must be in ranges <-1,-1> or <1,15>");
295
5.68k
    printInt64(O, Value);
296
5.68k
  } else
297
0
    printOperand(MI, OpNum, O);
298
5.68k
}
299
300
static inline void printImm32n_95_AsmOperand(MCInst *MI, int OpNum, SStream *O)
301
1.12k
{
302
1.12k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm32n_95_AsmOperand, OpNum);
303
1.12k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
304
1.12k
    int64_t Value =
305
1.12k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
306
1.12k
    CS_ASSERT((Value >= -32 && Value <= 95) &&
307
1.12k
        "Invalid argument, value must be in ranges <-32,95>");
308
1.12k
    printInt64(O, Value);
309
1.12k
  } else
310
0
    printOperand(MI, OpNum, O);
311
1.12k
}
312
313
static inline void printImm8n_7_AsmOperand(MCInst *MI, int OpNum, SStream *O)
314
351
{
315
351
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8n_7_AsmOperand, OpNum);
316
351
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
317
351
    int64_t Value =
318
351
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
319
351
    CS_ASSERT((Value >= -8 && Value <= 7) &&
320
351
        "Invalid argument, value must be in ranges <-8,7>");
321
351
    printInt64(O, Value);
322
351
  } else
323
0
    printOperand(MI, OpNum, O);
324
351
}
325
326
static inline void printImm64n_4n_AsmOperand(MCInst *MI, int OpNum, SStream *O)
327
348
{
328
348
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm64n_4n_AsmOperand, OpNum);
329
348
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
330
348
    int64_t Value =
331
348
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
332
348
    CS_ASSERT((Value >= -64 && Value <= -4) &
333
348
          ((Value & 0x3) == 0) &&
334
348
        "Invalid argument, value must be in ranges <-64,-4>");
335
348
    printInt64(O, Value);
336
348
  } else
337
0
    printOperand(MI, OpNum, O);
338
348
}
339
340
static inline void printOffset8m32_AsmOperand(MCInst *MI, int OpNum, SStream *O)
341
1.10k
{
342
1.10k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset8m32_AsmOperand,
343
1.10k
             OpNum);
344
1.10k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
345
1.10k
    int64_t Value =
346
1.10k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
347
1.10k
    CS_ASSERT(
348
1.10k
      (Value >= 0 && Value <= 1020 && ((Value & 0x3) == 0)) &&
349
1.10k
      "Invalid argument, value must be multiples of four in range [0,1020]");
350
1.10k
    printInt64(O, Value);
351
1.10k
  } else
352
0
    printOperand(MI, OpNum, O);
353
1.10k
}
354
355
static inline void printEntry_Imm12_AsmOperand(MCInst *MI, int OpNum,
356
                 SStream *O)
357
342
{
358
342
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Entry_Imm12_AsmOperand,
359
342
             OpNum);
360
342
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
361
342
    int64_t Value =
362
342
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
363
342
    CS_ASSERT(
364
342
      (Value >= 0 && Value <= 32760) &&
365
342
      "Invalid argument, value must be multiples of eight in range "
366
342
      "<0,32760>");
367
342
    printInt64(O, Value);
368
342
  } else
369
0
    printOperand(MI, OpNum, O);
370
342
}
371
372
static inline void printB4const_AsmOperand(MCInst *MI, int OpNum, SStream *O)
373
1.04k
{
374
1.04k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4const_AsmOperand, OpNum);
375
1.04k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
376
1.04k
    int64_t Value =
377
1.04k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
378
379
1.04k
    switch (Value) {
380
214
    case -1:
381
239
    case 1:
382
247
    case 2:
383
283
    case 3:
384
301
    case 4:
385
303
    case 5:
386
534
    case 6:
387
666
    case 7:
388
674
    case 8:
389
679
    case 10:
390
690
    case 12:
391
705
    case 16:
392
708
    case 32:
393
718
    case 64:
394
997
    case 128:
395
1.04k
    case 256:
396
1.04k
      break;
397
0
    default:
398
0
      CS_ASSERT((0) && "Invalid B4const argument");
399
1.04k
    }
400
1.04k
    printInt64(O, Value);
401
1.04k
  } else
402
0
    printOperand(MI, OpNum, O);
403
1.04k
}
404
405
static inline void printB4constu_AsmOperand(MCInst *MI, int OpNum, SStream *O)
406
797
{
407
797
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4constu_AsmOperand, OpNum);
408
797
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
409
797
    int64_t Value =
410
797
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
411
412
797
    switch (Value) {
413
14
    case 32768:
414
15
    case 65536:
415
21
    case 2:
416
22
    case 3:
417
49
    case 4:
418
49
    case 5:
419
468
    case 6:
420
470
    case 7:
421
472
    case 8:
422
473
    case 10:
423
474
    case 12:
424
556
    case 16:
425
556
    case 32:
426
558
    case 64:
427
558
    case 128:
428
797
    case 256:
429
797
      break;
430
0
    default:
431
0
      CS_ASSERT((0) && "Invalid B4constu argument");
432
797
    }
433
797
    printInt64(O, Value);
434
797
  } else
435
0
    printOperand(MI, OpNum, O);
436
797
}
437
438
static inline void printImm7_22_AsmOperand(MCInst *MI, int OpNum, SStream *O)
439
102
{
440
102
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm7_22_AsmOperand, OpNum);
441
102
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
442
102
    int64_t Value =
443
102
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
444
102
    CS_ASSERT((Value >= 7 && Value <= 22) &&
445
102
        "Invalid argument, value must be in range <7,22>");
446
102
    printInt64(O, Value);
447
102
  } else
448
0
    printOperand(MI, OpNum, O);
449
102
}
450
451
static inline void printSelect_2_AsmOperand(MCInst *MI, int OpNum, SStream *O)
452
987
{
453
987
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_2_AsmOperand, OpNum);
454
987
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
455
987
    int64_t Value =
456
987
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
457
987
    CS_ASSERT((Value >= 0 && Value <= 1) &&
458
987
        "Invalid argument, value must be in range [0,1]");
459
987
    printInt64(O, Value);
460
987
  } else
461
0
    printOperand(MI, OpNum, O);
462
987
}
463
464
static inline void printSelect_4_AsmOperand(MCInst *MI, int OpNum, SStream *O)
465
1.54k
{
466
1.54k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_4_AsmOperand, OpNum);
467
1.54k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
468
1.54k
    int64_t Value =
469
1.54k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
470
1.54k
    CS_ASSERT((Value >= 0 && Value <= 3) &&
471
1.54k
        "Invalid argument, value must be in range [0,3]");
472
1.54k
    printInt64(O, Value);
473
1.54k
  } else
474
0
    printOperand(MI, OpNum, O);
475
1.54k
}
476
477
static inline void printSelect_8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
478
1.46k
{
479
1.46k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_8_AsmOperand, OpNum);
480
1.46k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
481
1.46k
    int64_t Value =
482
1.46k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
483
1.46k
    CS_ASSERT((Value >= 0 && Value <= 7) &&
484
1.46k
        "Invalid argument, value must be in range [0,7]");
485
1.46k
    printInt64(O, Value);
486
1.46k
  } else
487
0
    printOperand(MI, OpNum, O);
488
1.46k
}
489
490
static inline void printSelect_16_AsmOperand(MCInst *MI, int OpNum, SStream *O)
491
694
{
492
694
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_16_AsmOperand, OpNum);
493
694
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
494
694
    int64_t Value =
495
694
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
496
694
    CS_ASSERT((Value >= 0 && Value <= 15) &&
497
694
        "Invalid argument, value must be in range [0,15]");
498
694
    printInt64(O, Value);
499
694
  } else
500
0
    printOperand(MI, OpNum, O);
501
694
}
502
503
static inline void printSelect_256_AsmOperand(MCInst *MI, int OpNum, SStream *O)
504
222
{
505
222
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_256_AsmOperand,
506
222
             OpNum);
507
222
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
508
222
    int64_t Value =
509
222
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
510
222
    CS_ASSERT((Value >= 0 && Value <= 255) &&
511
222
        "Invalid argument, value must be in range [0,255]");
512
222
    printInt64(O, Value);
513
222
  } else
514
0
    printOperand(MI, OpNum, O);
515
222
}
516
517
static inline void printOffset_16_16_AsmOperand(MCInst *MI, int OpNum,
518
            SStream *O)
519
805
{
520
805
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_16_16_AsmOperand,
521
805
             OpNum);
522
805
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
523
805
    int64_t Value =
524
805
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
525
805
    CS_ASSERT(
526
805
      (Value >= -128 && Value <= 112 && (Value & 0xf) == 0) &&
527
805
      "Invalid argument, value must be in range [-128,112], first 4 bits "
528
805
      "should be zero");
529
805
    printInt64(O, Value);
530
805
  } else {
531
0
    printOperand(MI, OpNum, O);
532
0
  }
533
805
}
534
535
static inline void printOffset_256_8_AsmOperand(MCInst *MI, int OpNum,
536
            SStream *O)
537
1.68k
{
538
1.68k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_8_AsmOperand,
539
1.68k
             OpNum);
540
1.68k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
541
1.68k
    int64_t Value =
542
1.68k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
543
1.68k
    CS_ASSERT(
544
1.68k
      (Value >= -1024 && Value <= 1016 &&
545
1.68k
       (Value & 0x7) == 0) &&
546
1.68k
      "Invalid argument, value must be in range [-1024,1016], first 3 "
547
1.68k
      "bits should be zero");
548
1.68k
    printInt64(O, Value);
549
1.68k
  } else
550
0
    printOperand(MI, OpNum, O);
551
1.68k
}
552
553
static inline void printOffset_256_16_AsmOperand(MCInst *MI, int OpNum,
554
             SStream *O)
555
1.01k
{
556
1.01k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_16_AsmOperand,
557
1.01k
             OpNum);
558
1.01k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
559
1.01k
    int64_t Value =
560
1.01k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
561
1.01k
    CS_ASSERT(
562
1.01k
      (Value >= -2048 && Value <= 2032 &&
563
1.01k
       (Value & 0xf) == 0) &&
564
1.01k
      "Invalid argument, value must be in range [-2048,2032], first 4 "
565
1.01k
      "bits should be zero");
566
1.01k
    printInt64(O, Value);
567
1.01k
  } else {
568
0
    printOperand(MI, OpNum, O);
569
0
  }
570
1.01k
}
571
572
static inline void printOffset_256_4_AsmOperand(MCInst *MI, int OpNum,
573
            SStream *O)
574
884
{
575
884
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_4_AsmOperand,
576
884
             OpNum);
577
884
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
578
884
    int64_t Value =
579
884
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
580
884
    CS_ASSERT(
581
884
      (Value >= -512 && Value <= 508 && (Value & 0x3) == 0) &&
582
884
      "Invalid argument, value must be in range [-512,508], first 2 bits "
583
884
      "should be zero");
584
884
    printInt64(O, Value);
585
884
  } else
586
0
    printOperand(MI, OpNum, O);
587
884
}
588
589
static inline void printOffset_128_2_AsmOperand(MCInst *MI, int OpNum,
590
            SStream *O)
591
632
{
592
632
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_2_AsmOperand,
593
632
             OpNum);
594
632
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
595
632
    int64_t Value =
596
632
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
597
632
    CS_ASSERT(
598
632
      (Value >= 0 && Value <= 254 && (Value & 0x1) == 0) &&
599
632
      "Invalid argument, value must be in range [0,254], first bit should "
600
632
      "be zero");
601
632
    printInt64(O, Value);
602
632
  } else
603
0
    printOperand(MI, OpNum, O);
604
632
}
605
606
static inline void printOffset_128_1_AsmOperand(MCInst *MI, int OpNum,
607
            SStream *O)
608
38
{
609
38
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_1_AsmOperand,
610
38
             OpNum);
611
38
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
612
38
    int64_t Value =
613
38
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
614
38
    CS_ASSERT((Value >= 0 && Value <= 127) &&
615
38
        "Invalid argument, value must be in range [0,127]");
616
38
    printInt64(O, Value);
617
38
  } else
618
0
    printOperand(MI, OpNum, O);
619
38
}
620
621
static inline void printOffset_64_16_AsmOperand(MCInst *MI, int OpNum,
622
            SStream *O)
623
2.94k
{
624
2.94k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_64_16_AsmOperand,
625
2.94k
             OpNum);
626
2.94k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
627
2.94k
    int64_t Value =
628
2.94k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
629
2.94k
    CS_ASSERT(
630
2.94k
      (Value >= -512 && Value <= 496 && (Value & 0xf) == 0) &&
631
2.94k
      "Invalid argument, value must be in range [-512,496], first 4 bits "
632
2.94k
      "should be zero");
633
2.94k
    printInt64(O, Value);
634
2.94k
  } else
635
0
    printOperand(MI, OpNum, O);
636
2.94k
}
637
638
#define IMPL_printImmOperand(N, L, H, S) \
639
  static void printImmOperand_##N(MCInst *MI, int OpNum, SStream *O) \
640
7
  { \
641
7
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
642
7
               OpNum); \
643
7
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
644
7
    if (MCOperand_isImm(MC)) { \
645
7
      int64_t Value = MCOperand_getImm(MC); \
646
7
      CS_ASSERT((Value >= L && Value <= H && \
647
7
           ((Value % S) == 0)) && \
648
7
          "Invalid argument"); \
649
7
      printInt64(O, Value); \
650
7
    } else { \
651
0
      printOperand(MI, OpNum, O); \
652
0
    } \
653
7
  }
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus16_47_1
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus16_14_2
XtensaInstPrinter.c:printImmOperand_minus32_28_4
Line
Count
Source
640
4
  { \
641
4
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
642
4
               OpNum); \
643
4
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
644
4
    if (MCOperand_isImm(MC)) { \
645
4
      int64_t Value = MCOperand_getImm(MC); \
646
4
      CS_ASSERT((Value >= L && Value <= H && \
647
4
           ((Value % S) == 0)) && \
648
4
          "Invalid argument"); \
649
4
      printInt64(O, Value); \
650
4
    } else { \
651
0
      printOperand(MI, OpNum, O); \
652
0
    } \
653
4
  }
XtensaInstPrinter.c:printImmOperand_minus64_56_8
Line
Count
Source
640
3
  { \
641
3
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
642
3
               OpNum); \
643
3
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
644
3
    if (MCOperand_isImm(MC)) { \
645
3
      int64_t Value = MCOperand_getImm(MC); \
646
3
      CS_ASSERT((Value >= L && Value <= H && \
647
3
           ((Value % S) == 0)) && \
648
3
          "Invalid argument"); \
649
3
      printInt64(O, Value); \
650
3
    } else { \
651
0
      printOperand(MI, OpNum, O); \
652
0
    } \
653
3
  }
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_56_8
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_3_1
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_63_1
654
655
IMPL_printImmOperand(minus64_56_8, -64, 56, 8);
656
IMPL_printImmOperand(minus32_28_4, -32, 28, 4);
657
IMPL_printImmOperand(minus16_47_1, -16, 47, 1);
658
IMPL_printImmOperand(minus16_14_2, -16, 14, 2);
659
IMPL_printImmOperand(0_56_8, 0, 56, 8);
660
IMPL_printImmOperand(0_3_1, 0, 3, 1);
661
IMPL_printImmOperand(0_63_1, 0, 63, 1);
662
663
#include "XtensaGenAsmWriter.inc"
664
665
static void printInst(MCInst *MI, uint64_t Address, const char *Annot,
666
          SStream *O)
667
83.7k
{
668
83.7k
  unsigned Opcode = MCInst_getOpcode(MI);
669
670
83.7k
  switch (Opcode) {
671
723
  case Xtensa_WSR: {
672
    // INTERRUPT mnemonic is read-only, so use INTSET mnemonic instead
673
723
    Register SR = MCOperand_getReg(MCInst_getOperand(MI, (0)));
674
723
    if (SR == Xtensa_INTERRUPT) {
675
18
      Register Reg =
676
18
        MCOperand_getReg(MCInst_getOperand(MI, (1)));
677
18
      SStream_concat1(O, '\t');
678
18
      SStream_concat(O, "%s", "wsr");
679
18
      SStream_concat0(O, "\t");
680
681
18
      printRegName(O, Reg);
682
18
      SStream_concat(O, "%s", ", ");
683
18
      SStream_concat0(O, "intset");
684
18
      ;
685
18
      return;
686
18
    }
687
723
  }
688
83.7k
  }
689
83.7k
  printInstruction(MI, Address, O);
690
83.7k
}
691
692
void Xtensa_LLVM_printInstruction(MCInst *MI, uint64_t Address, SStream *O)
693
83.7k
{
694
83.7k
  printInst(MI, Address, NULL, O);
695
83.7k
}
696
697
const char *Xtensa_LLVM_getRegisterName(unsigned RegNo)
698
14.0k
{
699
14.0k
  return getRegisterName(RegNo);
700
14.0k
}