Coverage Report

Created: 2026-03-13 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/Xtensa/XtensaInstPrinter.c
Line
Count
Source
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
14
{
53
14
  SStream_concat0(O, getRegisterName(Reg));
54
14
}
55
56
static void printOp(MCInst *MI, MCOperand *MC, SStream *O)
57
140k
{
58
140k
  if (MCOperand_isReg(MC))
59
133k
    SStream_concat0(O, getRegisterName(MCOperand_getReg(MC)));
60
7.47k
  else if (MCOperand_isImm(MC))
61
7.47k
    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(0 && "Invalid operand");
66
140k
}
67
68
static void printOperand(MCInst *MI, const int op_num, SStream *O)
69
133k
{
70
133k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Operand, op_num);
71
133k
  printOp(MI, MCInst_getOperand(MI, op_num), O);
72
133k
}
73
74
static inline void printMemOperand(MCInst *MI, int OpNum, SStream *OS)
75
7.47k
{
76
7.47k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_MemOperand, OpNum);
77
7.47k
  SStream_concat0(OS, getRegisterName(MCOperand_getReg(
78
7.47k
            MCInst_getOperand(MI, (OpNum)))));
79
7.47k
  SStream_concat0(OS, ", ");
80
7.47k
  printOp(MI, MCInst_getOperand(MI, OpNum + 1), OS);
81
7.47k
}
82
83
static inline void printBranchTarget(MCInst *MI, int OpNum, SStream *OS)
84
10.7k
{
85
10.7k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_BranchTarget, OpNum);
86
10.7k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
87
10.7k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
88
10.7k
    int64_t Val = MCOperand_getImm(MC) + 4;
89
10.7k
    SStream_concat0(OS, ". ");
90
10.7k
    if (Val > 0)
91
5.72k
      SStream_concat0(OS, "+");
92
93
10.7k
    printInt64(OS, Val);
94
10.7k
  } 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
10.7k
}
99
100
static inline void printLoopTarget(MCInst *MI, int OpNum, SStream *OS)
101
54
{
102
54
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_LoopTarget, OpNum);
103
54
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
104
54
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
105
54
    int64_t Val = MCOperand_getImm(MC) + 4;
106
54
    SStream_concat0(OS, ". ");
107
54
    if (Val > 0)
108
54
      SStream_concat0(OS, "+");
109
110
54
    printInt64(OS, Val);
111
54
  } 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
54
}
116
117
static inline void printJumpTarget(MCInst *MI, int OpNum, SStream *OS)
118
646
{
119
646
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_JumpTarget, OpNum);
120
646
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
121
646
  if (MCOperand_isImm(MC)) {
122
646
    int64_t Val = MCOperand_getImm(MC) + 4;
123
646
    SStream_concat0(OS, ". ");
124
646
    if (Val > 0)
125
268
      SStream_concat0(OS, "+");
126
127
646
    printInt64(OS, Val);
128
646
  } 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
646
  ;
133
646
}
134
135
static inline void printCallOperand(MCInst *MI, int OpNum, SStream *OS)
136
3.01k
{
137
3.01k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_CallOperand, OpNum);
138
3.01k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
139
3.01k
  if (MCOperand_isImm(MC)) {
140
3.01k
    int64_t Val = MCOperand_getImm(MC) + 4;
141
3.01k
    SStream_concat0(OS, ". ");
142
3.01k
    if (Val > 0)
143
1.55k
      SStream_concat0(OS, "+");
144
145
3.01k
    printInt64(OS, Val);
146
3.01k
  } 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
3.01k
}
151
152
static inline void printL32RTarget(MCInst *MI, int OpNum, SStream *O)
153
4.15k
{
154
4.15k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_L32RTarget, OpNum);
155
4.15k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
156
4.15k
  if (MCOperand_isImm(MC)) {
157
4.15k
    SStream_concat0(O, ". ");
158
4.15k
    printInt64(O, Xtensa_L32R_Value(MI, OpNum));
159
4.15k
  } 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
4.15k
}
164
165
static inline void printImm8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
166
331
{
167
331
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_AsmOperand, OpNum);
168
331
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
169
331
    int64_t Value =
170
331
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
171
331
    CS_ASSERT_RET(
172
331
      isIntN(8, Value) &&
173
331
      "Invalid argument, value must be in ranges [-128,127]");
174
331
    printInt64(O, Value);
175
331
  } else {
176
0
    printOperand(MI, OpNum, O);
177
0
  }
178
331
}
179
180
static inline void printImm8_sh8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
181
268
{
182
268
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_sh8_AsmOperand, OpNum);
183
268
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
184
268
    int64_t Value =
185
268
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
186
268
    CS_ASSERT_RET(
187
268
      (isIntN(16, Value) && ((Value & 0xFF) == 0)) &&
188
268
      "Invalid argument, value must be multiples of 256 in range "
189
268
      "[-32768,32512]");
190
268
    printInt64(O, Value);
191
268
  } else
192
0
    printOperand(MI, OpNum, O);
193
268
}
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_RET(
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
356
{
211
356
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12m_AsmOperand, OpNum);
212
356
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
213
356
    int64_t Value =
214
356
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
215
356
    CS_ASSERT_RET(
216
356
      (Value >= -2048 && Value <= 2047) &&
217
356
      "Invalid argument, value must be in ranges [-2048,2047]");
218
356
    printInt64(O, Value);
219
356
  } else
220
0
    printOperand(MI, OpNum, O);
221
356
}
222
223
static inline void printUimm4_AsmOperand(MCInst *MI, int OpNum, SStream *O)
224
1.26k
{
225
1.26k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm4_AsmOperand, OpNum);
226
1.26k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
227
1.26k
    int64_t Value =
228
1.26k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
229
1.26k
    CS_ASSERT_RET((Value >= 0 && Value <= 15) &&
230
1.26k
            "Invalid argument");
231
1.26k
    printInt64(O, Value);
232
1.26k
  } else
233
0
    printOperand(MI, OpNum, O);
234
1.26k
}
235
236
static inline void printUimm5_AsmOperand(MCInst *MI, int OpNum, SStream *O)
237
2.08k
{
238
2.08k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm5_AsmOperand, OpNum);
239
2.08k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
240
2.08k
    int64_t Value =
241
2.08k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
242
2.08k
    CS_ASSERT_RET((Value >= 0 && Value <= 31) &&
243
2.08k
            "Invalid argument");
244
2.08k
    printInt64(O, Value);
245
2.08k
  } else
246
0
    printOperand(MI, OpNum, O);
247
2.08k
}
248
249
static inline void printShimm1_31_AsmOperand(MCInst *MI, int OpNum, SStream *O)
250
0
{
251
0
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm1_31_AsmOperand, OpNum);
252
0
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
253
0
    int64_t Value =
254
0
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
255
0
    CS_ASSERT_RET(
256
0
      (Value >= 1 && Value <= 31) &&
257
0
      "Invalid argument, value must be in range [1,31]");
258
0
    printInt64(O, Value);
259
0
  } else
260
0
    printOperand(MI, OpNum, O);
261
0
}
262
263
static inline void printShimm0_31_AsmOperand(MCInst *MI, int OpNum, SStream *O)
264
419
{
265
419
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm0_31_AsmOperand, OpNum);
266
419
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
267
419
    int64_t Value =
268
419
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
269
419
    CS_ASSERT_RET(
270
419
      (Value >= 0 && Value <= 31) &&
271
419
      "Invalid argument, value must be in range [0,31]");
272
109
    printInt64(O, Value);
273
109
  } else
274
0
    printOperand(MI, OpNum, O);
275
419
}
276
277
static inline void printImm1_16_AsmOperand(MCInst *MI, int OpNum, SStream *O)
278
741
{
279
741
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1_16_AsmOperand, OpNum);
280
741
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
281
741
    int64_t Value =
282
741
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
283
741
    CS_ASSERT_RET(
284
741
      (Value >= 1 && Value <= 16) &&
285
741
      "Invalid argument, value must be in range [1,16]");
286
741
    printInt64(O, Value);
287
741
  } else
288
0
    printOperand(MI, OpNum, O);
289
741
}
290
291
static inline void printImm1n_15_AsmOperand(MCInst *MI, int OpNum, SStream *O)
292
3.91k
{
293
3.91k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1n_15_AsmOperand, OpNum);
294
3.91k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
295
3.91k
    int64_t Value =
296
3.91k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
297
3.91k
    CS_ASSERT_RET(
298
3.91k
      (Value >= -1 && (Value != 0) && Value <= 15) &&
299
3.91k
      "Invalid argument, value must be in ranges <-1,-1> or <1,15>");
300
3.91k
    printInt64(O, Value);
301
3.91k
  } else
302
0
    printOperand(MI, OpNum, O);
303
3.91k
}
304
305
static inline void printImm32n_95_AsmOperand(MCInst *MI, int OpNum, SStream *O)
306
1.50k
{
307
1.50k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm32n_95_AsmOperand, OpNum);
308
1.50k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
309
1.50k
    int64_t Value =
310
1.50k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
311
1.50k
    CS_ASSERT_RET(
312
1.50k
      (Value >= -32 && Value <= 95) &&
313
1.50k
      "Invalid argument, value must be in ranges <-32,95>");
314
1.50k
    printInt64(O, Value);
315
1.50k
  } else
316
0
    printOperand(MI, OpNum, O);
317
1.50k
}
318
319
static inline void printImm8n_7_AsmOperand(MCInst *MI, int OpNum, SStream *O)
320
780
{
321
780
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8n_7_AsmOperand, OpNum);
322
780
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
323
780
    int64_t Value =
324
780
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
325
780
    CS_ASSERT_RET(
326
780
      (Value >= -8 && Value <= 7) &&
327
780
      "Invalid argument, value must be in ranges <-8,7>");
328
780
    printInt64(O, Value);
329
780
  } else
330
0
    printOperand(MI, OpNum, O);
331
780
}
332
333
static inline void printImm64n_4n_AsmOperand(MCInst *MI, int OpNum, SStream *O)
334
96
{
335
96
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm64n_4n_AsmOperand, OpNum);
336
96
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
337
96
    int64_t Value =
338
96
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
339
96
    CS_ASSERT_RET(
340
96
      (Value >= -64 && Value <= -4) & ((Value & 0x3) == 0) &&
341
96
      "Invalid argument, value must be in ranges <-64,-4>");
342
96
    printInt64(O, Value);
343
96
  } else
344
0
    printOperand(MI, OpNum, O);
345
96
}
346
347
static inline void printOffset8m32_AsmOperand(MCInst *MI, int OpNum, SStream *O)
348
1.20k
{
349
1.20k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset8m32_AsmOperand,
350
1.20k
             OpNum);
351
1.20k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
352
1.20k
    int64_t Value =
353
1.20k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
354
1.20k
    CS_ASSERT_RET(
355
1.20k
      (Value >= 0 && Value <= 1020 && ((Value & 0x3) == 0)) &&
356
1.20k
      "Invalid argument, value must be multiples of four in range [0,1020]");
357
1.20k
    printInt64(O, Value);
358
1.20k
  } else
359
0
    printOperand(MI, OpNum, O);
360
1.20k
}
361
362
static inline void printEntry_Imm12_AsmOperand(MCInst *MI, int OpNum,
363
                 SStream *O)
364
884
{
365
884
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Entry_Imm12_AsmOperand,
366
884
             OpNum);
367
884
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
368
884
    int64_t Value =
369
884
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
370
884
    CS_ASSERT_RET(
371
884
      (Value >= 0 && Value <= 32760) &&
372
884
      "Invalid argument, value must be multiples of eight in range "
373
884
      "<0,32760>");
374
884
    printInt64(O, Value);
375
884
  } else
376
0
    printOperand(MI, OpNum, O);
377
884
}
378
379
static inline void printB4const_AsmOperand(MCInst *MI, int OpNum, SStream *O)
380
3.40k
{
381
3.40k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4const_AsmOperand, OpNum);
382
3.40k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
383
3.40k
    int64_t Value =
384
3.40k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
385
386
3.40k
    switch (Value) {
387
162
    case -1:
388
789
    case 1:
389
994
    case 2:
390
1.15k
    case 3:
391
1.42k
    case 4:
392
1.52k
    case 5:
393
2.04k
    case 6:
394
2.28k
    case 7:
395
2.49k
    case 8:
396
2.58k
    case 10:
397
2.82k
    case 12:
398
3.11k
    case 16:
399
3.11k
    case 32:
400
3.13k
    case 64:
401
3.35k
    case 128:
402
3.40k
    case 256:
403
3.40k
      break;
404
0
    default:
405
0
      CS_ASSERT_RET((0) && "Invalid B4const argument");
406
3.40k
    }
407
3.40k
    printInt64(O, Value);
408
3.40k
  } else
409
0
    printOperand(MI, OpNum, O);
410
3.40k
}
411
412
static inline void printB4constu_AsmOperand(MCInst *MI, int OpNum, SStream *O)
413
3.86k
{
414
3.86k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4constu_AsmOperand, OpNum);
415
3.86k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
416
3.86k
    int64_t Value =
417
3.86k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
418
419
3.86k
    switch (Value) {
420
172
    case 32768:
421
422
    case 65536:
422
764
    case 2:
423
860
    case 3:
424
911
    case 4:
425
989
    case 5:
426
1.16k
    case 6:
427
1.20k
    case 7:
428
1.25k
    case 8:
429
1.31k
    case 10:
430
1.36k
    case 12:
431
3.36k
    case 16:
432
3.43k
    case 32:
433
3.56k
    case 64:
434
3.59k
    case 128:
435
3.86k
    case 256:
436
3.86k
      break;
437
0
    default:
438
0
      CS_ASSERT_RET((0) && "Invalid B4constu argument");
439
3.86k
    }
440
3.86k
    printInt64(O, Value);
441
3.86k
  } else
442
0
    printOperand(MI, OpNum, O);
443
3.86k
}
444
445
static inline void printImm7_22_AsmOperand(MCInst *MI, int OpNum, SStream *O)
446
98
{
447
98
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm7_22_AsmOperand, OpNum);
448
98
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
449
98
    int64_t Value =
450
98
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
451
98
    CS_ASSERT_RET(
452
98
      (Value >= 7 && Value <= 22) &&
453
98
      "Invalid argument, value must be in range <7,22>");
454
98
    printInt64(O, Value);
455
98
  } else
456
0
    printOperand(MI, OpNum, O);
457
98
}
458
459
static inline void printSelect_2_AsmOperand(MCInst *MI, int OpNum, SStream *O)
460
854
{
461
854
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_2_AsmOperand, OpNum);
462
854
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
463
854
    int64_t Value =
464
854
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
465
854
    CS_ASSERT_RET((Value >= 0 && Value <= 1) &&
466
854
            "Invalid argument, value must be in range [0,1]");
467
854
    printInt64(O, Value);
468
854
  } else
469
0
    printOperand(MI, OpNum, O);
470
854
}
471
472
static inline void printSelect_4_AsmOperand(MCInst *MI, int OpNum, SStream *O)
473
1.34k
{
474
1.34k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_4_AsmOperand, OpNum);
475
1.34k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
476
1.34k
    int64_t Value =
477
1.34k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
478
1.34k
    CS_ASSERT_RET((Value >= 0 && Value <= 3) &&
479
1.34k
            "Invalid argument, value must be in range [0,3]");
480
1.34k
    printInt64(O, Value);
481
1.34k
  } else
482
0
    printOperand(MI, OpNum, O);
483
1.34k
}
484
485
static inline void printSelect_8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
486
881
{
487
881
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_8_AsmOperand, OpNum);
488
881
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
489
881
    int64_t Value =
490
881
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
491
881
    CS_ASSERT_RET((Value >= 0 && Value <= 7) &&
492
881
            "Invalid argument, value must be in range [0,7]");
493
881
    printInt64(O, Value);
494
881
  } else
495
0
    printOperand(MI, OpNum, O);
496
881
}
497
498
static inline void printSelect_16_AsmOperand(MCInst *MI, int OpNum, SStream *O)
499
170
{
500
170
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_16_AsmOperand, OpNum);
501
170
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
502
170
    int64_t Value =
503
170
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
504
170
    CS_ASSERT_RET(
505
170
      (Value >= 0 && Value <= 15) &&
506
170
      "Invalid argument, value must be in range [0,15]");
507
170
    printInt64(O, Value);
508
170
  } else
509
0
    printOperand(MI, OpNum, O);
510
170
}
511
512
static inline void printSelect_256_AsmOperand(MCInst *MI, int OpNum, SStream *O)
513
63
{
514
63
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_256_AsmOperand,
515
63
             OpNum);
516
63
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
517
63
    int64_t Value =
518
63
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
519
63
    CS_ASSERT_RET(
520
63
      (Value >= 0 && Value <= 255) &&
521
63
      "Invalid argument, value must be in range [0,255]");
522
63
    printInt64(O, Value);
523
63
  } else
524
0
    printOperand(MI, OpNum, O);
525
63
}
526
527
static inline void printOffset_16_16_AsmOperand(MCInst *MI, int OpNum,
528
            SStream *O)
529
269
{
530
269
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_16_16_AsmOperand,
531
269
             OpNum);
532
269
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
533
269
    int64_t Value =
534
269
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
535
269
    CS_ASSERT_RET(
536
269
      (Value >= -128 && Value <= 112 && (Value & 0xf) == 0) &&
537
269
      "Invalid argument, value must be in range [-128,112], first 4 bits "
538
269
      "should be zero");
539
137
    printInt64(O, Value);
540
137
  } else {
541
0
    printOperand(MI, OpNum, O);
542
0
  }
543
269
}
544
545
static inline void printOffset_256_8_AsmOperand(MCInst *MI, int OpNum,
546
            SStream *O)
547
1.73k
{
548
1.73k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_8_AsmOperand,
549
1.73k
             OpNum);
550
1.73k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
551
1.73k
    int64_t Value =
552
1.73k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
553
1.73k
    CS_ASSERT_RET(
554
1.73k
      (Value >= -1024 && Value <= 1016 &&
555
1.73k
       (Value & 0x7) == 0) &&
556
1.73k
      "Invalid argument, value must be in range [-1024,1016], first 3 "
557
1.73k
      "bits should be zero");
558
1.11k
    printInt64(O, Value);
559
1.11k
  } else
560
0
    printOperand(MI, OpNum, O);
561
1.73k
}
562
563
static inline void printOffset_256_16_AsmOperand(MCInst *MI, int OpNum,
564
             SStream *O)
565
862
{
566
862
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_16_AsmOperand,
567
862
             OpNum);
568
862
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
569
862
    int64_t Value =
570
862
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
571
862
    CS_ASSERT_RET(
572
862
      (Value >= -2048 && Value <= 2032 &&
573
862
       (Value & 0xf) == 0) &&
574
862
      "Invalid argument, value must be in range [-2048,2032], first 4 "
575
862
      "bits should be zero");
576
553
    printInt64(O, Value);
577
553
  } else {
578
0
    printOperand(MI, OpNum, O);
579
0
  }
580
862
}
581
582
static inline void printOffset_256_4_AsmOperand(MCInst *MI, int OpNum,
583
            SStream *O)
584
384
{
585
384
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_4_AsmOperand,
586
384
             OpNum);
587
384
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
588
384
    int64_t Value =
589
384
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
590
384
    CS_ASSERT_RET(
591
384
      (Value >= -512 && Value <= 508 && (Value & 0x3) == 0) &&
592
384
      "Invalid argument, value must be in range [-512,508], first 2 bits "
593
384
      "should be zero");
594
224
    printInt64(O, Value);
595
224
  } else
596
0
    printOperand(MI, OpNum, O);
597
384
}
598
599
static inline void printOffset_128_2_AsmOperand(MCInst *MI, int OpNum,
600
            SStream *O)
601
683
{
602
683
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_2_AsmOperand,
603
683
             OpNum);
604
683
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
605
683
    int64_t Value =
606
683
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
607
683
    CS_ASSERT_RET(
608
683
      (Value >= 0 && Value <= 254 && (Value & 0x1) == 0) &&
609
683
      "Invalid argument, value must be in range [0,254], first bit should "
610
683
      "be zero");
611
683
    printInt64(O, Value);
612
683
  } else
613
0
    printOperand(MI, OpNum, O);
614
683
}
615
616
static inline void printOffset_128_1_AsmOperand(MCInst *MI, int OpNum,
617
            SStream *O)
618
511
{
619
511
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_1_AsmOperand,
620
511
             OpNum);
621
511
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
622
511
    int64_t Value =
623
511
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
624
511
    CS_ASSERT_RET(
625
511
      (Value >= 0 && Value <= 127) &&
626
511
      "Invalid argument, value must be in range [0,127]");
627
511
    printInt64(O, Value);
628
511
  } else
629
0
    printOperand(MI, OpNum, O);
630
511
}
631
632
static inline void printOffset_64_16_AsmOperand(MCInst *MI, int OpNum,
633
            SStream *O)
634
2.30k
{
635
2.30k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_64_16_AsmOperand,
636
2.30k
             OpNum);
637
2.30k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
638
2.30k
    int64_t Value =
639
2.30k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
640
2.30k
    CS_ASSERT_RET(
641
2.30k
      (Value >= -512 && Value <= 496 && (Value & 0xf) == 0) &&
642
2.30k
      "Invalid argument, value must be in range [-512,496], first 4 bits "
643
2.30k
      "should be zero");
644
1.43k
    printInt64(O, Value);
645
1.43k
  } else
646
0
    printOperand(MI, OpNum, O);
647
2.30k
}
648
649
#define IMPL_printImmOperand(N, L, H, S) \
650
  static void printImmOperand_##N(MCInst *MI, int OpNum, SStream *O) \
651
43
  { \
652
43
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
653
43
               OpNum); \
654
43
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
655
43
    if (MCOperand_isImm(MC)) { \
656
43
      int64_t Value = MCOperand_getImm(MC); \
657
43
      CS_ASSERT_RET((Value >= L && Value <= H && \
658
43
               ((Value % S) == 0)) && \
659
43
              "Invalid argument"); \
660
43
      printInt64(O, Value); \
661
17
    } else { \
662
0
      printOperand(MI, OpNum, O); \
663
0
    } \
664
43
  }
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
651
25
  { \
652
25
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
653
25
               OpNum); \
654
25
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
655
25
    if (MCOperand_isImm(MC)) { \
656
25
      int64_t Value = MCOperand_getImm(MC); \
657
25
      CS_ASSERT_RET((Value >= L && Value <= H && \
658
25
               ((Value % S) == 0)) && \
659
25
              "Invalid argument"); \
660
25
      printInt64(O, Value); \
661
17
    } else { \
662
0
      printOperand(MI, OpNum, O); \
663
0
    } \
664
25
  }
XtensaInstPrinter.c:printImmOperand_minus64_56_8
Line
Count
Source
651
18
  { \
652
18
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
653
18
               OpNum); \
654
18
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
655
18
    if (MCOperand_isImm(MC)) { \
656
18
      int64_t Value = MCOperand_getImm(MC); \
657
18
      CS_ASSERT_RET((Value >= L && Value <= H && \
658
18
               ((Value % S) == 0)) && \
659
18
              "Invalid argument"); \
660
18
      printInt64(O, Value); \
661
0
    } else { \
662
0
      printOperand(MI, OpNum, O); \
663
0
    } \
664
18
  }
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_56_8
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_3_1
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_63_1
665
666
IMPL_printImmOperand(minus64_56_8, -64, 56, 8);
667
IMPL_printImmOperand(minus32_28_4, -32, 28, 4);
668
IMPL_printImmOperand(minus16_47_1, -16, 47, 1);
669
IMPL_printImmOperand(minus16_14_2, -16, 14, 2);
670
IMPL_printImmOperand(0_56_8, 0, 56, 8);
671
IMPL_printImmOperand(0_3_1, 0, 3, 1);
672
IMPL_printImmOperand(0_63_1, 0, 63, 1);
673
674
#include "XtensaGenAsmWriter.inc"
675
676
static void printInst(MCInst *MI, uint64_t Address, const char *Annot,
677
          SStream *O)
678
68.3k
{
679
68.3k
  unsigned Opcode = MCInst_getOpcode(MI);
680
681
68.3k
  switch (Opcode) {
682
411
  case Xtensa_WSR: {
683
    // INTERRUPT mnemonic is read-only, so use INTSET mnemonic instead
684
411
    Register SR = MCOperand_getReg(MCInst_getOperand(MI, (0)));
685
411
    if (SR == Xtensa_INTERRUPT) {
686
14
      Register Reg =
687
14
        MCOperand_getReg(MCInst_getOperand(MI, (1)));
688
14
      SStream_concat1(O, '\t');
689
14
      SStream_concat(O, "%s", "wsr");
690
14
      SStream_concat0(O, "\t");
691
692
14
      printRegName(O, Reg);
693
14
      SStream_concat(O, "%s", ", ");
694
14
      SStream_concat0(O, "intset");
695
14
      ;
696
14
      return;
697
14
    }
698
411
  }
699
68.3k
  }
700
68.3k
  printInstruction(MI, Address, O);
701
68.3k
}
702
703
void Xtensa_LLVM_printInstruction(MCInst *MI, uint64_t Address, SStream *O)
704
68.3k
{
705
68.3k
  printInst(MI, Address, NULL, O);
706
68.3k
}
707
708
const char *Xtensa_LLVM_getRegisterName(unsigned RegNo)
709
10.1k
{
710
10.1k
  return getRegisterName(RegNo);
711
10.1k
}