Coverage Report

Created: 2025-07-01 07:03

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