Coverage Report

Created: 2025-11-16 06:38

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