Coverage Report

Created: 2025-10-10 06:20

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