Coverage Report

Created: 2025-07-04 06:11

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