Coverage Report

Created: 2025-08-29 06:29

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