Coverage Report

Created: 2025-11-09 07:00

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