Coverage Report

Created: 2025-07-09 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
175k
{
58
175k
  if (MCOperand_isReg(MC))
59
163k
    SStream_concat0(O, getRegisterName(MCOperand_getReg(MC)));
60
12.0k
  else if (MCOperand_isImm(MC))
61
12.0k
    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
175k
}
67
68
static void printOperand(MCInst *MI, const int op_num, SStream *O)
69
163k
{
70
163k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Operand, op_num);
71
163k
  printOp(MI, MCInst_getOperand(MI, op_num), O);
72
163k
}
73
74
static inline void printMemOperand(MCInst *MI, int OpNum, SStream *OS)
75
12.0k
{
76
12.0k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_MemOperand, OpNum);
77
12.0k
  SStream_concat0(OS, getRegisterName(MCOperand_getReg(
78
12.0k
            MCInst_getOperand(MI, (OpNum)))));
79
12.0k
  SStream_concat0(OS, ", ");
80
12.0k
  printOp(MI, MCInst_getOperand(MI, OpNum + 1), OS);
81
12.0k
}
82
83
static inline void printBranchTarget(MCInst *MI, int OpNum, SStream *OS)
84
5.43k
{
85
5.43k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_BranchTarget, OpNum);
86
5.43k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
87
5.43k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
88
5.43k
    int64_t Val = MCOperand_getImm(MC) + 4;
89
5.43k
    SStream_concat0(OS, ". ");
90
5.43k
    if (Val > 0)
91
2.45k
      SStream_concat0(OS, "+");
92
93
5.43k
    printInt64(OS, Val);
94
5.43k
  } 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.43k
}
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.62k
{
119
1.62k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_JumpTarget, OpNum);
120
1.62k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
121
1.62k
  if (MCOperand_isImm(MC)) {
122
1.62k
    int64_t Val = MCOperand_getImm(MC) + 4;
123
1.62k
    SStream_concat0(OS, ". ");
124
1.62k
    if (Val > 0)
125
745
      SStream_concat0(OS, "+");
126
127
1.62k
    printInt64(OS, Val);
128
1.62k
  } 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.62k
  ;
133
1.62k
}
134
135
static inline void printCallOperand(MCInst *MI, int OpNum, SStream *OS)
136
3.14k
{
137
3.14k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_CallOperand, OpNum);
138
3.14k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
139
3.14k
  if (MCOperand_isImm(MC)) {
140
3.14k
    int64_t Val = MCOperand_getImm(MC) + 4;
141
3.14k
    SStream_concat0(OS, ". ");
142
3.14k
    if (Val > 0)
143
1.49k
      SStream_concat0(OS, "+");
144
145
3.14k
    printInt64(OS, Val);
146
3.14k
  } 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.14k
}
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
442
{
182
442
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_sh8_AsmOperand, OpNum);
183
442
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
184
442
    int64_t Value =
185
442
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
186
442
    CS_ASSERT(
187
442
      (isIntN(16, Value) && ((Value & 0xFF) == 0)) &&
188
442
      "Invalid argument, value must be multiples of 256 in range "
189
442
      "[-32768,32512]");
190
442
    printInt64(O, Value);
191
442
  } else
192
0
    printOperand(MI, OpNum, O);
193
442
}
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
439
{
211
439
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12m_AsmOperand, OpNum);
212
439
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
213
439
    int64_t Value =
214
439
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
215
439
    CS_ASSERT(
216
439
      (Value >= -2048 && Value <= 2047) &&
217
439
      "Invalid argument, value must be in ranges [-2048,2047]");
218
439
    printInt64(O, Value);
219
439
  } else
220
0
    printOperand(MI, OpNum, O);
221
439
}
222
223
static inline void printUimm4_AsmOperand(MCInst *MI, int OpNum, SStream *O)
224
1.64k
{
225
1.64k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm4_AsmOperand, OpNum);
226
1.64k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
227
1.64k
    int64_t Value =
228
1.64k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
229
1.64k
    CS_ASSERT((Value >= 0 && Value <= 15) && "Invalid argument");
230
1.64k
    printInt64(O, Value);
231
1.64k
  } else
232
0
    printOperand(MI, OpNum, O);
233
1.64k
}
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
476
{
262
476
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm0_31_AsmOperand, OpNum);
263
476
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
264
476
    int64_t Value =
265
476
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
266
476
    CS_ASSERT((Value >= 0 && Value <= 31) &&
267
476
        "Invalid argument, value must be in range [0,31]");
268
476
    printInt64(O, Value);
269
476
  } else
270
0
    printOperand(MI, OpNum, O);
271
476
}
272
273
static inline void printImm1_16_AsmOperand(MCInst *MI, int OpNum, SStream *O)
274
690
{
275
690
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1_16_AsmOperand, OpNum);
276
690
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
277
690
    int64_t Value =
278
690
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
279
690
    CS_ASSERT((Value >= 1 && Value <= 16) &&
280
690
        "Invalid argument, value must be in range [1,16]");
281
690
    printInt64(O, Value);
282
690
  } else
283
0
    printOperand(MI, OpNum, O);
284
690
}
285
286
static inline void printImm1n_15_AsmOperand(MCInst *MI, int OpNum, SStream *O)
287
4.28k
{
288
4.28k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1n_15_AsmOperand, OpNum);
289
4.28k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
290
4.28k
    int64_t Value =
291
4.28k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
292
4.28k
    CS_ASSERT(
293
4.28k
      (Value >= -1 && (Value != 0) && Value <= 15) &&
294
4.28k
      "Invalid argument, value must be in ranges <-1,-1> or <1,15>");
295
4.28k
    printInt64(O, Value);
296
4.28k
  } else
297
0
    printOperand(MI, OpNum, O);
298
4.28k
}
299
300
static inline void printImm32n_95_AsmOperand(MCInst *MI, int OpNum, SStream *O)
301
1.71k
{
302
1.71k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm32n_95_AsmOperand, OpNum);
303
1.71k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
304
1.71k
    int64_t Value =
305
1.71k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
306
1.71k
    CS_ASSERT((Value >= -32 && Value <= 95) &&
307
1.71k
        "Invalid argument, value must be in ranges <-32,95>");
308
1.71k
    printInt64(O, Value);
309
1.71k
  } else
310
0
    printOperand(MI, OpNum, O);
311
1.71k
}
312
313
static inline void printImm8n_7_AsmOperand(MCInst *MI, int OpNum, SStream *O)
314
238
{
315
238
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8n_7_AsmOperand, OpNum);
316
238
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
317
238
    int64_t Value =
318
238
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
319
238
    CS_ASSERT((Value >= -8 && Value <= 7) &&
320
238
        "Invalid argument, value must be in ranges <-8,7>");
321
238
    printInt64(O, Value);
322
238
  } else
323
0
    printOperand(MI, OpNum, O);
324
238
}
325
326
static inline void printImm64n_4n_AsmOperand(MCInst *MI, int OpNum, SStream *O)
327
547
{
328
547
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm64n_4n_AsmOperand, OpNum);
329
547
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
330
547
    int64_t Value =
331
547
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
332
547
    CS_ASSERT((Value >= -64 && Value <= -4) &
333
547
          ((Value & 0x3) == 0) &&
334
547
        "Invalid argument, value must be in ranges <-64,-4>");
335
547
    printInt64(O, Value);
336
547
  } else
337
0
    printOperand(MI, OpNum, O);
338
547
}
339
340
static inline void printOffset8m32_AsmOperand(MCInst *MI, int OpNum, SStream *O)
341
1.02k
{
342
1.02k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset8m32_AsmOperand,
343
1.02k
             OpNum);
344
1.02k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
345
1.02k
    int64_t Value =
346
1.02k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
347
1.02k
    CS_ASSERT(
348
1.02k
      (Value >= 0 && Value <= 1020 && ((Value & 0x3) == 0)) &&
349
1.02k
      "Invalid argument, value must be multiples of four in range [0,1020]");
350
1.02k
    printInt64(O, Value);
351
1.02k
  } else
352
0
    printOperand(MI, OpNum, O);
353
1.02k
}
354
355
static inline void printEntry_Imm12_AsmOperand(MCInst *MI, int OpNum,
356
                 SStream *O)
357
371
{
358
371
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Entry_Imm12_AsmOperand,
359
371
             OpNum);
360
371
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
361
371
    int64_t Value =
362
371
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
363
371
    CS_ASSERT(
364
371
      (Value >= 0 && Value <= 32760) &&
365
371
      "Invalid argument, value must be multiples of eight in range "
366
371
      "<0,32760>");
367
371
    printInt64(O, Value);
368
371
  } else
369
0
    printOperand(MI, OpNum, O);
370
371
}
371
372
static inline void printB4const_AsmOperand(MCInst *MI, int OpNum, SStream *O)
373
848
{
374
848
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4const_AsmOperand, OpNum);
375
848
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
376
848
    int64_t Value =
377
848
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
378
379
848
    switch (Value) {
380
174
    case -1:
381
178
    case 1:
382
216
    case 2:
383
246
    case 3:
384
248
    case 4:
385
250
    case 5:
386
456
    case 6:
387
529
    case 7:
388
530
    case 8:
389
534
    case 10:
390
757
    case 12:
391
763
    case 16:
392
766
    case 32:
393
782
    case 64:
394
834
    case 128:
395
848
    case 256:
396
848
      break;
397
0
    default:
398
0
      CS_ASSERT((0) && "Invalid B4const argument");
399
848
    }
400
848
    printInt64(O, Value);
401
848
  } else
402
0
    printOperand(MI, OpNum, O);
403
848
}
404
405
static inline void printB4constu_AsmOperand(MCInst *MI, int OpNum, SStream *O)
406
234
{
407
234
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4constu_AsmOperand, OpNum);
408
234
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
409
234
    int64_t Value =
410
234
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
411
412
234
    switch (Value) {
413
4
    case 32768:
414
4
    case 65536:
415
11
    case 2:
416
13
    case 3:
417
14
    case 4:
418
15
    case 5:
419
29
    case 6:
420
30
    case 7:
421
30
    case 8:
422
31
    case 10:
423
35
    case 12:
424
90
    case 16:
425
92
    case 32:
426
93
    case 64:
427
93
    case 128:
428
234
    case 256:
429
234
      break;
430
0
    default:
431
0
      CS_ASSERT((0) && "Invalid B4constu argument");
432
234
    }
433
234
    printInt64(O, Value);
434
234
  } else
435
0
    printOperand(MI, OpNum, O);
436
234
}
437
438
static inline void printImm7_22_AsmOperand(MCInst *MI, int OpNum, SStream *O)
439
86
{
440
86
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm7_22_AsmOperand, OpNum);
441
86
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
442
86
    int64_t Value =
443
86
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
444
86
    CS_ASSERT((Value >= 7 && Value <= 22) &&
445
86
        "Invalid argument, value must be in range <7,22>");
446
86
    printInt64(O, Value);
447
86
  } else
448
0
    printOperand(MI, OpNum, O);
449
86
}
450
451
static inline void printSelect_2_AsmOperand(MCInst *MI, int OpNum, SStream *O)
452
1.13k
{
453
1.13k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_2_AsmOperand, OpNum);
454
1.13k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
455
1.13k
    int64_t Value =
456
1.13k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
457
1.13k
    CS_ASSERT((Value >= 0 && Value <= 1) &&
458
1.13k
        "Invalid argument, value must be in range [0,1]");
459
1.13k
    printInt64(O, Value);
460
1.13k
  } else
461
0
    printOperand(MI, OpNum, O);
462
1.13k
}
463
464
static inline void printSelect_4_AsmOperand(MCInst *MI, int OpNum, SStream *O)
465
1.75k
{
466
1.75k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_4_AsmOperand, OpNum);
467
1.75k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
468
1.75k
    int64_t Value =
469
1.75k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
470
1.75k
    CS_ASSERT((Value >= 0 && Value <= 3) &&
471
1.75k
        "Invalid argument, value must be in range [0,3]");
472
1.75k
    printInt64(O, Value);
473
1.75k
  } else
474
0
    printOperand(MI, OpNum, O);
475
1.75k
}
476
477
static inline void printSelect_8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
478
1.95k
{
479
1.95k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_8_AsmOperand, OpNum);
480
1.95k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
481
1.95k
    int64_t Value =
482
1.95k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
483
1.95k
    CS_ASSERT((Value >= 0 && Value <= 7) &&
484
1.95k
        "Invalid argument, value must be in range [0,7]");
485
1.95k
    printInt64(O, Value);
486
1.95k
  } else
487
0
    printOperand(MI, OpNum, O);
488
1.95k
}
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
642
{
505
642
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_256_AsmOperand,
506
642
             OpNum);
507
642
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
508
642
    int64_t Value =
509
642
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
510
642
    CS_ASSERT((Value >= 0 && Value <= 255) &&
511
642
        "Invalid argument, value must be in range [0,255]");
512
642
    printInt64(O, Value);
513
642
  } else
514
0
    printOperand(MI, OpNum, O);
515
642
}
516
517
static inline void printOffset_16_16_AsmOperand(MCInst *MI, int OpNum,
518
            SStream *O)
519
767
{
520
767
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_16_16_AsmOperand,
521
767
             OpNum);
522
767
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
523
767
    int64_t Value =
524
767
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
525
767
    CS_ASSERT(
526
767
      (Value >= -128 && Value <= 112 && (Value & 0xf) == 0) &&
527
767
      "Invalid argument, value must be in range [-128,112], first 4 bits "
528
767
      "should be zero");
529
767
    printInt64(O, Value);
530
767
  } else {
531
0
    printOperand(MI, OpNum, O);
532
0
  }
533
767
}
534
535
static inline void printOffset_256_8_AsmOperand(MCInst *MI, int OpNum,
536
            SStream *O)
537
1.85k
{
538
1.85k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_8_AsmOperand,
539
1.85k
             OpNum);
540
1.85k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
541
1.85k
    int64_t Value =
542
1.85k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
543
1.85k
    CS_ASSERT(
544
1.85k
      (Value >= -1024 && Value <= 1016 &&
545
1.85k
       (Value & 0x7) == 0) &&
546
1.85k
      "Invalid argument, value must be in range [-1024,1016], first 3 "
547
1.85k
      "bits should be zero");
548
1.85k
    printInt64(O, Value);
549
1.85k
  } else
550
0
    printOperand(MI, OpNum, O);
551
1.85k
}
552
553
static inline void printOffset_256_16_AsmOperand(MCInst *MI, int OpNum,
554
             SStream *O)
555
975
{
556
975
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_16_AsmOperand,
557
975
             OpNum);
558
975
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
559
975
    int64_t Value =
560
975
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
561
975
    CS_ASSERT(
562
975
      (Value >= -2048 && Value <= 2032 &&
563
975
       (Value & 0xf) == 0) &&
564
975
      "Invalid argument, value must be in range [-2048,2032], first 4 "
565
975
      "bits should be zero");
566
975
    printInt64(O, Value);
567
975
  } else {
568
0
    printOperand(MI, OpNum, O);
569
0
  }
570
975
}
571
572
static inline void printOffset_256_4_AsmOperand(MCInst *MI, int OpNum,
573
            SStream *O)
574
645
{
575
645
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_4_AsmOperand,
576
645
             OpNum);
577
645
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
578
645
    int64_t Value =
579
645
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
580
645
    CS_ASSERT(
581
645
      (Value >= -512 && Value <= 508 && (Value & 0x3) == 0) &&
582
645
      "Invalid argument, value must be in range [-512,508], first 2 bits "
583
645
      "should be zero");
584
645
    printInt64(O, Value);
585
645
  } else
586
0
    printOperand(MI, OpNum, O);
587
645
}
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
91
{
609
91
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_1_AsmOperand,
610
91
             OpNum);
611
91
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
612
91
    int64_t Value =
613
91
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
614
91
    CS_ASSERT((Value >= 0 && Value <= 127) &&
615
91
        "Invalid argument, value must be in range [0,127]");
616
91
    printInt64(O, Value);
617
91
  } else
618
0
    printOperand(MI, OpNum, O);
619
91
}
620
621
static inline void printOffset_64_16_AsmOperand(MCInst *MI, int OpNum,
622
            SStream *O)
623
3.41k
{
624
3.41k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_64_16_AsmOperand,
625
3.41k
             OpNum);
626
3.41k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
627
3.41k
    int64_t Value =
628
3.41k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
629
3.41k
    CS_ASSERT(
630
3.41k
      (Value >= -512 && Value <= 496 && (Value & 0xf) == 0) &&
631
3.41k
      "Invalid argument, value must be in range [-512,496], first 4 bits "
632
3.41k
      "should be zero");
633
3.41k
    printInt64(O, Value);
634
3.41k
  } else
635
0
    printOperand(MI, OpNum, O);
636
3.41k
}
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.0k
{
668
79.0k
  unsigned Opcode = MCInst_getOpcode(MI);
669
670
79.0k
  switch (Opcode) {
671
773
  case Xtensa_WSR: {
672
    // INTERRUPT mnemonic is read-only, so use INTSET mnemonic instead
673
773
    Register SR = MCOperand_getReg(MCInst_getOperand(MI, (0)));
674
773
    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
773
  }
688
79.0k
  }
689
78.9k
  printInstruction(MI, Address, O);
690
78.9k
}
691
692
void Xtensa_LLVM_printInstruction(MCInst *MI, uint64_t Address, SStream *O)
693
79.0k
{
694
79.0k
  printInst(MI, Address, NULL, O);
695
79.0k
}
696
697
const char *Xtensa_LLVM_getRegisterName(unsigned RegNo)
698
8.60k
{
699
8.60k
  return getRegisterName(RegNo);
700
8.60k
}