Coverage Report

Created: 2025-07-18 06:43

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