Coverage Report

Created: 2026-03-11 06:06

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