Coverage Report

Created: 2025-11-24 06:12

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