Coverage Report

Created: 2026-03-03 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/Xtensa/XtensaInstPrinter.c
Line
Count
Source
1
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
3
/*    Rot127 <unisono@quyllur.org> 2022-2023 */
4
/* Automatically translated source file from LLVM. */
5
6
/* LLVM-commit: <commit> */
7
/* LLVM-tag: <tag> */
8
9
/* Only small edits allowed. */
10
/* For multiple similar edits, please create a Patch for the translator. */
11
12
/* Capstone's C++ file translator: */
13
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
14
15
//===- XtensaInstPrinter.cpp - Convert Xtensa MCInst to asm syntax --------===//
16
//
17
//                     The LLVM Compiler Infrastructure
18
//
19
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
20
// See https://llvm.org/LICENSE.txt for license information.
21
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22
//
23
//===----------------------------------------------------------------------===//
24
//
25
// This class prints an Xtensa MCInst to a .s file.
26
//
27
//===----------------------------------------------------------------------===//
28
29
#include <stdio.h>
30
#include <string.h>
31
#include <stdlib.h>
32
#include <capstone/platform.h>
33
34
#include "../../MCInstPrinter.h"
35
#include "../../SStream.h"
36
#include "./priv.h"
37
#include "../../Mapping.h"
38
39
#include "XtensaMapping.h"
40
#include "../../MathExtras.h"
41
42
#define CONCAT(a, b) CONCAT_(a, b)
43
#define CONCAT_(a, b) a##_##b
44
45
#define DEBUG_TYPE "asm-printer"
46
static MnemonicBitsInfo getMnemonic(MCInst *MI, SStream *O);
47
static const char *getRegisterName(unsigned RegNo);
48
49
typedef MCRegister Register;
50
51
static void printRegName(SStream *O, MCRegister Reg)
52
0
{
53
0
  SStream_concat0(O, getRegisterName(Reg));
54
0
}
55
56
static void printOp(MCInst *MI, MCOperand *MC, SStream *O)
57
52.6k
{
58
52.6k
  if (MCOperand_isReg(MC))
59
50.2k
    SStream_concat0(O, getRegisterName(MCOperand_getReg(MC)));
60
2.38k
  else if (MCOperand_isImm(MC))
61
2.38k
    printInt64(O, MCOperand_getImm(MC));
62
0
  else if (MCOperand_isExpr(MC))
63
0
    printExpr(MCOperand_getExpr(MC), O);
64
0
  else
65
0
    CS_ASSERT(0 && "Invalid operand");
66
52.6k
}
67
68
static void printOperand(MCInst *MI, const int op_num, SStream *O)
69
50.2k
{
70
50.2k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Operand, op_num);
71
50.2k
  printOp(MI, MCInst_getOperand(MI, op_num), O);
72
50.2k
}
73
74
static inline void printMemOperand(MCInst *MI, int OpNum, SStream *OS)
75
2.38k
{
76
2.38k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_MemOperand, OpNum);
77
2.38k
  SStream_concat0(OS, getRegisterName(MCOperand_getReg(
78
2.38k
            MCInst_getOperand(MI, (OpNum)))));
79
2.38k
  SStream_concat0(OS, ", ");
80
2.38k
  printOp(MI, MCInst_getOperand(MI, OpNum + 1), OS);
81
2.38k
}
82
83
static inline void printBranchTarget(MCInst *MI, int OpNum, SStream *OS)
84
4.53k
{
85
4.53k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_BranchTarget, OpNum);
86
4.53k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
87
4.53k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
88
4.53k
    int64_t Val = MCOperand_getImm(MC) + 4;
89
4.53k
    SStream_concat0(OS, ". ");
90
4.53k
    if (Val > 0)
91
2.37k
      SStream_concat0(OS, "+");
92
93
4.53k
    printInt64(OS, Val);
94
4.53k
  } 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.53k
}
99
100
static inline void printLoopTarget(MCInst *MI, int OpNum, SStream *OS)
101
11
{
102
11
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_LoopTarget, OpNum);
103
11
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
104
11
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
105
11
    int64_t Val = MCOperand_getImm(MC) + 4;
106
11
    SStream_concat0(OS, ". ");
107
11
    if (Val > 0)
108
11
      SStream_concat0(OS, "+");
109
110
11
    printInt64(OS, Val);
111
11
  } 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
11
}
116
117
static inline void printJumpTarget(MCInst *MI, int OpNum, SStream *OS)
118
438
{
119
438
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_JumpTarget, OpNum);
120
438
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
121
438
  if (MCOperand_isImm(MC)) {
122
438
    int64_t Val = MCOperand_getImm(MC) + 4;
123
438
    SStream_concat0(OS, ". ");
124
438
    if (Val > 0)
125
136
      SStream_concat0(OS, "+");
126
127
438
    printInt64(OS, Val);
128
438
  } 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
438
  ;
133
438
}
134
135
static inline void printCallOperand(MCInst *MI, int OpNum, SStream *OS)
136
1.16k
{
137
1.16k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_CallOperand, OpNum);
138
1.16k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
139
1.16k
  if (MCOperand_isImm(MC)) {
140
1.16k
    int64_t Val = MCOperand_getImm(MC) + 4;
141
1.16k
    SStream_concat0(OS, ". ");
142
1.16k
    if (Val > 0)
143
575
      SStream_concat0(OS, "+");
144
145
1.16k
    printInt64(OS, Val);
146
1.16k
  } 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
1.16k
}
151
152
static inline void printL32RTarget(MCInst *MI, int OpNum, SStream *O)
153
2.37k
{
154
2.37k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_L32RTarget, OpNum);
155
2.37k
  MCOperand *MC = MCInst_getOperand(MI, (OpNum));
156
2.37k
  if (MCOperand_isImm(MC)) {
157
2.37k
    SStream_concat0(O, ". ");
158
2.37k
    printInt64(O, Xtensa_L32R_Value(MI, OpNum));
159
2.37k
  } 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
2.37k
}
164
165
static inline void printImm8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
166
130
{
167
130
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_AsmOperand, OpNum);
168
130
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
169
130
    int64_t Value =
170
130
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
171
130
    CS_ASSERT_RET(
172
130
      isIntN(8, Value) &&
173
130
      "Invalid argument, value must be in ranges [-128,127]");
174
130
    printInt64(O, Value);
175
130
  } else {
176
0
    printOperand(MI, OpNum, O);
177
0
  }
178
130
}
179
180
static inline void printImm8_sh8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
181
69
{
182
69
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_sh8_AsmOperand, OpNum);
183
69
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
184
69
    int64_t Value =
185
69
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
186
69
    CS_ASSERT_RET(
187
69
      (isIntN(16, Value) && ((Value & 0xFF) == 0)) &&
188
69
      "Invalid argument, value must be multiples of 256 in range "
189
69
      "[-32768,32512]");
190
69
    printInt64(O, Value);
191
69
  } else
192
0
    printOperand(MI, OpNum, O);
193
69
}
194
195
static inline void printImm12_AsmOperand(MCInst *MI, int OpNum, SStream *O)
196
0
{
197
0
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12_AsmOperand, OpNum);
198
0
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
199
0
    int64_t Value =
200
0
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
201
0
    CS_ASSERT_RET(
202
0
      (Value >= -2048 && Value <= 2047) &&
203
0
      "Invalid argument, value must be in ranges [-2048,2047]");
204
0
    printInt64(O, Value);
205
0
  } else
206
0
    printOperand(MI, OpNum, O);
207
0
}
208
209
static inline void printImm12m_AsmOperand(MCInst *MI, int OpNum, SStream *O)
210
100
{
211
100
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12m_AsmOperand, OpNum);
212
100
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
213
100
    int64_t Value =
214
100
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
215
100
    CS_ASSERT_RET(
216
100
      (Value >= -2048 && Value <= 2047) &&
217
100
      "Invalid argument, value must be in ranges [-2048,2047]");
218
100
    printInt64(O, Value);
219
100
  } else
220
0
    printOperand(MI, OpNum, O);
221
100
}
222
223
static inline void printUimm4_AsmOperand(MCInst *MI, int OpNum, SStream *O)
224
306
{
225
306
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm4_AsmOperand, OpNum);
226
306
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
227
306
    int64_t Value =
228
306
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
229
306
    CS_ASSERT_RET((Value >= 0 && Value <= 15) &&
230
306
            "Invalid argument");
231
306
    printInt64(O, Value);
232
306
  } else
233
0
    printOperand(MI, OpNum, O);
234
306
}
235
236
static inline void printUimm5_AsmOperand(MCInst *MI, int OpNum, SStream *O)
237
571
{
238
571
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm5_AsmOperand, OpNum);
239
571
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
240
571
    int64_t Value =
241
571
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
242
571
    CS_ASSERT_RET((Value >= 0 && Value <= 31) &&
243
571
            "Invalid argument");
244
571
    printInt64(O, Value);
245
571
  } else
246
0
    printOperand(MI, OpNum, O);
247
571
}
248
249
static inline void printShimm1_31_AsmOperand(MCInst *MI, int OpNum, SStream *O)
250
0
{
251
0
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm1_31_AsmOperand, OpNum);
252
0
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
253
0
    int64_t Value =
254
0
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
255
0
    CS_ASSERT_RET(
256
0
      (Value >= 1 && Value <= 31) &&
257
0
      "Invalid argument, value must be in range [1,31]");
258
0
    printInt64(O, Value);
259
0
  } else
260
0
    printOperand(MI, OpNum, O);
261
0
}
262
263
static inline void printShimm0_31_AsmOperand(MCInst *MI, int OpNum, SStream *O)
264
276
{
265
276
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm0_31_AsmOperand, OpNum);
266
276
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
267
276
    int64_t Value =
268
276
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
269
276
    CS_ASSERT_RET(
270
276
      (Value >= 0 && Value <= 31) &&
271
276
      "Invalid argument, value must be in range [0,31]");
272
76
    printInt64(O, Value);
273
76
  } else
274
0
    printOperand(MI, OpNum, O);
275
276
}
276
277
static inline void printImm1_16_AsmOperand(MCInst *MI, int OpNum, SStream *O)
278
297
{
279
297
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1_16_AsmOperand, OpNum);
280
297
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
281
297
    int64_t Value =
282
297
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
283
297
    CS_ASSERT_RET(
284
297
      (Value >= 1 && Value <= 16) &&
285
297
      "Invalid argument, value must be in range [1,16]");
286
297
    printInt64(O, Value);
287
297
  } else
288
0
    printOperand(MI, OpNum, O);
289
297
}
290
291
static inline void printImm1n_15_AsmOperand(MCInst *MI, int OpNum, SStream *O)
292
1.37k
{
293
1.37k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1n_15_AsmOperand, OpNum);
294
1.37k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
295
1.37k
    int64_t Value =
296
1.37k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
297
1.37k
    CS_ASSERT_RET(
298
1.37k
      (Value >= -1 && (Value != 0) && Value <= 15) &&
299
1.37k
      "Invalid argument, value must be in ranges <-1,-1> or <1,15>");
300
1.37k
    printInt64(O, Value);
301
1.37k
  } else
302
0
    printOperand(MI, OpNum, O);
303
1.37k
}
304
305
static inline void printImm32n_95_AsmOperand(MCInst *MI, int OpNum, SStream *O)
306
343
{
307
343
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm32n_95_AsmOperand, OpNum);
308
343
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
309
343
    int64_t Value =
310
343
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
311
343
    CS_ASSERT_RET(
312
343
      (Value >= -32 && Value <= 95) &&
313
343
      "Invalid argument, value must be in ranges <-32,95>");
314
343
    printInt64(O, Value);
315
343
  } else
316
0
    printOperand(MI, OpNum, O);
317
343
}
318
319
static inline void printImm8n_7_AsmOperand(MCInst *MI, int OpNum, SStream *O)
320
240
{
321
240
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8n_7_AsmOperand, OpNum);
322
240
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
323
240
    int64_t Value =
324
240
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
325
240
    CS_ASSERT_RET(
326
240
      (Value >= -8 && Value <= 7) &&
327
240
      "Invalid argument, value must be in ranges <-8,7>");
328
240
    printInt64(O, Value);
329
240
  } else
330
0
    printOperand(MI, OpNum, O);
331
240
}
332
333
static inline void printImm64n_4n_AsmOperand(MCInst *MI, int OpNum, SStream *O)
334
41
{
335
41
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm64n_4n_AsmOperand, OpNum);
336
41
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
337
41
    int64_t Value =
338
41
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
339
41
    CS_ASSERT_RET(
340
41
      (Value >= -64 && Value <= -4) & ((Value & 0x3) == 0) &&
341
41
      "Invalid argument, value must be in ranges <-64,-4>");
342
41
    printInt64(O, Value);
343
41
  } else
344
0
    printOperand(MI, OpNum, O);
345
41
}
346
347
static inline void printOffset8m32_AsmOperand(MCInst *MI, int OpNum, SStream *O)
348
165
{
349
165
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset8m32_AsmOperand,
350
165
             OpNum);
351
165
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
352
165
    int64_t Value =
353
165
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
354
165
    CS_ASSERT_RET(
355
165
      (Value >= 0 && Value <= 1020 && ((Value & 0x3) == 0)) &&
356
165
      "Invalid argument, value must be multiples of four in range [0,1020]");
357
165
    printInt64(O, Value);
358
165
  } else
359
0
    printOperand(MI, OpNum, O);
360
165
}
361
362
static inline void printEntry_Imm12_AsmOperand(MCInst *MI, int OpNum,
363
                 SStream *O)
364
443
{
365
443
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Entry_Imm12_AsmOperand,
366
443
             OpNum);
367
443
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
368
443
    int64_t Value =
369
443
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
370
443
    CS_ASSERT_RET(
371
443
      (Value >= 0 && Value <= 32760) &&
372
443
      "Invalid argument, value must be multiples of eight in range "
373
443
      "<0,32760>");
374
443
    printInt64(O, Value);
375
443
  } else
376
0
    printOperand(MI, OpNum, O);
377
443
}
378
379
static inline void printB4const_AsmOperand(MCInst *MI, int OpNum, SStream *O)
380
1.49k
{
381
1.49k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4const_AsmOperand, OpNum);
382
1.49k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
383
1.49k
    int64_t Value =
384
1.49k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
385
386
1.49k
    switch (Value) {
387
55
    case -1:
388
182
    case 1:
389
201
    case 2:
390
269
    case 3:
391
390
    case 4:
392
471
    case 5:
393
761
    case 6:
394
972
    case 7:
395
1.28k
    case 8:
396
1.29k
    case 10:
397
1.37k
    case 12:
398
1.43k
    case 16:
399
1.44k
    case 32:
400
1.44k
    case 64:
401
1.45k
    case 128:
402
1.49k
    case 256:
403
1.49k
      break;
404
0
    default:
405
0
      CS_ASSERT_RET((0) && "Invalid B4const argument");
406
1.49k
    }
407
1.49k
    printInt64(O, Value);
408
1.49k
  } else
409
0
    printOperand(MI, OpNum, O);
410
1.49k
}
411
412
static inline void printB4constu_AsmOperand(MCInst *MI, int OpNum, SStream *O)
413
2.04k
{
414
2.04k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4constu_AsmOperand, OpNum);
415
2.04k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
416
2.04k
    int64_t Value =
417
2.04k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
418
419
2.04k
    switch (Value) {
420
118
    case 32768:
421
177
    case 65536:
422
423
    case 2:
423
441
    case 3:
424
480
    case 4:
425
482
    case 5:
426
488
    case 6:
427
496
    case 7:
428
526
    case 8:
429
536
    case 10:
430
566
    case 12:
431
1.84k
    case 16:
432
1.84k
    case 32:
433
1.94k
    case 64:
434
1.95k
    case 128:
435
2.04k
    case 256:
436
2.04k
      break;
437
0
    default:
438
0
      CS_ASSERT_RET((0) && "Invalid B4constu argument");
439
2.04k
    }
440
2.04k
    printInt64(O, Value);
441
2.04k
  } else
442
0
    printOperand(MI, OpNum, O);
443
2.04k
}
444
445
static inline void printImm7_22_AsmOperand(MCInst *MI, int OpNum, SStream *O)
446
7
{
447
7
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm7_22_AsmOperand, OpNum);
448
7
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
449
7
    int64_t Value =
450
7
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
451
7
    CS_ASSERT_RET(
452
7
      (Value >= 7 && Value <= 22) &&
453
7
      "Invalid argument, value must be in range <7,22>");
454
7
    printInt64(O, Value);
455
7
  } else
456
0
    printOperand(MI, OpNum, O);
457
7
}
458
459
static inline void printSelect_2_AsmOperand(MCInst *MI, int OpNum, SStream *O)
460
182
{
461
182
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_2_AsmOperand, OpNum);
462
182
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
463
182
    int64_t Value =
464
182
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
465
182
    CS_ASSERT_RET((Value >= 0 && Value <= 1) &&
466
182
            "Invalid argument, value must be in range [0,1]");
467
182
    printInt64(O, Value);
468
182
  } else
469
0
    printOperand(MI, OpNum, O);
470
182
}
471
472
static inline void printSelect_4_AsmOperand(MCInst *MI, int OpNum, SStream *O)
473
806
{
474
806
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_4_AsmOperand, OpNum);
475
806
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
476
806
    int64_t Value =
477
806
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
478
806
    CS_ASSERT_RET((Value >= 0 && Value <= 3) &&
479
806
            "Invalid argument, value must be in range [0,3]");
480
806
    printInt64(O, Value);
481
806
  } else
482
0
    printOperand(MI, OpNum, O);
483
806
}
484
485
static inline void printSelect_8_AsmOperand(MCInst *MI, int OpNum, SStream *O)
486
436
{
487
436
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_8_AsmOperand, OpNum);
488
436
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
489
436
    int64_t Value =
490
436
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
491
436
    CS_ASSERT_RET((Value >= 0 && Value <= 7) &&
492
436
            "Invalid argument, value must be in range [0,7]");
493
436
    printInt64(O, Value);
494
436
  } else
495
0
    printOperand(MI, OpNum, O);
496
436
}
497
498
static inline void printSelect_16_AsmOperand(MCInst *MI, int OpNum, SStream *O)
499
66
{
500
66
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_16_AsmOperand, OpNum);
501
66
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
502
66
    int64_t Value =
503
66
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
504
66
    CS_ASSERT_RET(
505
66
      (Value >= 0 && Value <= 15) &&
506
66
      "Invalid argument, value must be in range [0,15]");
507
66
    printInt64(O, Value);
508
66
  } else
509
0
    printOperand(MI, OpNum, O);
510
66
}
511
512
static inline void printSelect_256_AsmOperand(MCInst *MI, int OpNum, SStream *O)
513
1
{
514
1
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_256_AsmOperand,
515
1
             OpNum);
516
1
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
517
1
    int64_t Value =
518
1
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
519
1
    CS_ASSERT_RET(
520
1
      (Value >= 0 && Value <= 255) &&
521
1
      "Invalid argument, value must be in range [0,255]");
522
1
    printInt64(O, Value);
523
1
  } else
524
0
    printOperand(MI, OpNum, O);
525
1
}
526
527
static inline void printOffset_16_16_AsmOperand(MCInst *MI, int OpNum,
528
            SStream *O)
529
145
{
530
145
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_16_16_AsmOperand,
531
145
             OpNum);
532
145
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
533
145
    int64_t Value =
534
145
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
535
145
    CS_ASSERT_RET(
536
145
      (Value >= -128 && Value <= 112 && (Value & 0xf) == 0) &&
537
145
      "Invalid argument, value must be in range [-128,112], first 4 bits "
538
145
      "should be zero");
539
61
    printInt64(O, Value);
540
61
  } else {
541
0
    printOperand(MI, OpNum, O);
542
0
  }
543
145
}
544
545
static inline void printOffset_256_8_AsmOperand(MCInst *MI, int OpNum,
546
            SStream *O)
547
300
{
548
300
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_8_AsmOperand,
549
300
             OpNum);
550
300
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
551
300
    int64_t Value =
552
300
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
553
300
    CS_ASSERT_RET(
554
300
      (Value >= -1024 && Value <= 1016 &&
555
300
       (Value & 0x7) == 0) &&
556
300
      "Invalid argument, value must be in range [-1024,1016], first 3 "
557
300
      "bits should be zero");
558
272
    printInt64(O, Value);
559
272
  } else
560
0
    printOperand(MI, OpNum, O);
561
300
}
562
563
static inline void printOffset_256_16_AsmOperand(MCInst *MI, int OpNum,
564
             SStream *O)
565
432
{
566
432
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_16_AsmOperand,
567
432
             OpNum);
568
432
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
569
432
    int64_t Value =
570
432
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
571
432
    CS_ASSERT_RET(
572
432
      (Value >= -2048 && Value <= 2032 &&
573
432
       (Value & 0xf) == 0) &&
574
432
      "Invalid argument, value must be in range [-2048,2032], first 4 "
575
432
      "bits should be zero");
576
326
    printInt64(O, Value);
577
326
  } else {
578
0
    printOperand(MI, OpNum, O);
579
0
  }
580
432
}
581
582
static inline void printOffset_256_4_AsmOperand(MCInst *MI, int OpNum,
583
            SStream *O)
584
246
{
585
246
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_4_AsmOperand,
586
246
             OpNum);
587
246
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
588
246
    int64_t Value =
589
246
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
590
246
    CS_ASSERT_RET(
591
246
      (Value >= -512 && Value <= 508 && (Value & 0x3) == 0) &&
592
246
      "Invalid argument, value must be in range [-512,508], first 2 bits "
593
246
      "should be zero");
594
78
    printInt64(O, Value);
595
78
  } else
596
0
    printOperand(MI, OpNum, O);
597
246
}
598
599
static inline void printOffset_128_2_AsmOperand(MCInst *MI, int OpNum,
600
            SStream *O)
601
602
{
602
602
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_2_AsmOperand,
603
602
             OpNum);
604
602
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
605
602
    int64_t Value =
606
602
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
607
602
    CS_ASSERT_RET(
608
602
      (Value >= 0 && Value <= 254 && (Value & 0x1) == 0) &&
609
602
      "Invalid argument, value must be in range [0,254], first bit should "
610
602
      "be zero");
611
602
    printInt64(O, Value);
612
602
  } else
613
0
    printOperand(MI, OpNum, O);
614
602
}
615
616
static inline void printOffset_128_1_AsmOperand(MCInst *MI, int OpNum,
617
            SStream *O)
618
394
{
619
394
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_1_AsmOperand,
620
394
             OpNum);
621
394
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
622
394
    int64_t Value =
623
394
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
624
394
    CS_ASSERT_RET(
625
394
      (Value >= 0 && Value <= 127) &&
626
394
      "Invalid argument, value must be in range [0,127]");
627
394
    printInt64(O, Value);
628
394
  } else
629
0
    printOperand(MI, OpNum, O);
630
394
}
631
632
static inline void printOffset_64_16_AsmOperand(MCInst *MI, int OpNum,
633
            SStream *O)
634
1.02k
{
635
1.02k
  Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_64_16_AsmOperand,
636
1.02k
             OpNum);
637
1.02k
  if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) {
638
1.02k
    int64_t Value =
639
1.02k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
640
1.02k
    CS_ASSERT_RET(
641
1.02k
      (Value >= -512 && Value <= 496 && (Value & 0xf) == 0) &&
642
1.02k
      "Invalid argument, value must be in range [-512,496], first 4 bits "
643
1.02k
      "should be zero");
644
650
    printInt64(O, Value);
645
650
  } else
646
0
    printOperand(MI, OpNum, O);
647
1.02k
}
648
649
#define IMPL_printImmOperand(N, L, H, S) \
650
  static void printImmOperand_##N(MCInst *MI, int OpNum, SStream *O) \
651
43
  { \
652
43
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
653
43
               OpNum); \
654
43
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
655
43
    if (MCOperand_isImm(MC)) { \
656
43
      int64_t Value = MCOperand_getImm(MC); \
657
43
      CS_ASSERT_RET((Value >= L && Value <= H && \
658
43
               ((Value % S) == 0)) && \
659
43
              "Invalid argument"); \
660
43
      printInt64(O, Value); \
661
17
    } else { \
662
0
      printOperand(MI, OpNum, O); \
663
0
    } \
664
43
  }
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus16_47_1
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus16_14_2
XtensaInstPrinter.c:printImmOperand_minus32_28_4
Line
Count
Source
651
25
  { \
652
25
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
653
25
               OpNum); \
654
25
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
655
25
    if (MCOperand_isImm(MC)) { \
656
25
      int64_t Value = MCOperand_getImm(MC); \
657
25
      CS_ASSERT_RET((Value >= L && Value <= H && \
658
25
               ((Value % S) == 0)) && \
659
25
              "Invalid argument"); \
660
25
      printInt64(O, Value); \
661
17
    } else { \
662
0
      printOperand(MI, OpNum, O); \
663
0
    } \
664
25
  }
XtensaInstPrinter.c:printImmOperand_minus64_56_8
Line
Count
Source
651
18
  { \
652
18
    Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
653
18
               OpNum); \
654
18
    MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
655
18
    if (MCOperand_isImm(MC)) { \
656
18
      int64_t Value = MCOperand_getImm(MC); \
657
18
      CS_ASSERT_RET((Value >= L && Value <= H && \
658
18
               ((Value % S) == 0)) && \
659
18
              "Invalid argument"); \
660
18
      printInt64(O, Value); \
661
0
    } else { \
662
0
      printOperand(MI, OpNum, O); \
663
0
    } \
664
18
  }
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_56_8
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_3_1
Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_63_1
665
666
IMPL_printImmOperand(minus64_56_8, -64, 56, 8);
667
IMPL_printImmOperand(minus32_28_4, -32, 28, 4);
668
IMPL_printImmOperand(minus16_47_1, -16, 47, 1);
669
IMPL_printImmOperand(minus16_14_2, -16, 14, 2);
670
IMPL_printImmOperand(0_56_8, 0, 56, 8);
671
IMPL_printImmOperand(0_3_1, 0, 3, 1);
672
IMPL_printImmOperand(0_63_1, 0, 63, 1);
673
674
#include "XtensaGenAsmWriter.inc"
675
676
static void printInst(MCInst *MI, uint64_t Address, const char *Annot,
677
          SStream *O)
678
26.3k
{
679
26.3k
  unsigned Opcode = MCInst_getOpcode(MI);
680
681
26.3k
  switch (Opcode) {
682
11
  case Xtensa_WSR: {
683
    // INTERRUPT mnemonic is read-only, so use INTSET mnemonic instead
684
11
    Register SR = MCOperand_getReg(MCInst_getOperand(MI, (0)));
685
11
    if (SR == Xtensa_INTERRUPT) {
686
0
      Register Reg =
687
0
        MCOperand_getReg(MCInst_getOperand(MI, (1)));
688
0
      SStream_concat1(O, '\t');
689
0
      SStream_concat(O, "%s", "wsr");
690
0
      SStream_concat0(O, "\t");
691
692
0
      printRegName(O, Reg);
693
0
      SStream_concat(O, "%s", ", ");
694
0
      SStream_concat0(O, "intset");
695
0
      ;
696
0
      return;
697
0
    }
698
11
  }
699
26.3k
  }
700
26.3k
  printInstruction(MI, Address, O);
701
26.3k
}
702
703
void Xtensa_LLVM_printInstruction(MCInst *MI, uint64_t Address, SStream *O)
704
26.3k
{
705
26.3k
  printInst(MI, Address, NULL, O);
706
26.3k
}
707
708
const char *Xtensa_LLVM_getRegisterName(unsigned RegNo)
709
3.45k
{
710
3.45k
  return getRegisterName(RegNo);
711
3.45k
}