Coverage Report

Created: 2025-10-12 06:32

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