Coverage Report

Created: 2025-07-11 06:32

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