Coverage Report

Created: 2024-09-08 06:22

/src/capstonenext/arch/LoongArch/LoongArchInstPrinter.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
//===- LoongArchInstPrinter.cpp - Convert LoongArch MCInst to asm syntax --===//
16
//
17
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
18
// See https://llvm.org/LICENSE.txt for license information.
19
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
20
//
21
//===----------------------------------------------------------------------===//
22
//
23
// This class prints an LoongArch MCInst to a .s file.
24
//
25
//===----------------------------------------------------------------------===//
26
27
#include <stdio.h>
28
#include <string.h>
29
#include <stdlib.h>
30
#include <capstone/platform.h>
31
32
#include "LoongArchMapping.h"
33
#include "LoongArchInstPrinter.h"
34
35
#define GET_SUBTARGETINFO_ENUM
36
#include "LoongArchGenSubtargetInfo.inc"
37
38
#define GET_INSTRINFO_ENUM
39
#include "LoongArchGenInstrInfo.inc"
40
41
#define GET_REGINFO_ENUM
42
#include "LoongArchGenRegisterInfo.inc"
43
44
#define CONCAT(a, b) CONCAT_(a, b)
45
#define CONCAT_(a, b) a##_##b
46
47
#define DEBUG_TYPE "loongarch-asm-printer"
48
49
// Include the auto-generated portion of the assembly writer.
50
#define PRINT_ALIAS_INSTR
51
#include "LoongArchGenAsmWriter.inc"
52
53
static void printInst(MCInst *MI, uint64_t Address, const char *Annot,
54
          SStream *O)
55
0
{
56
0
  if (!printAliasInstr(MI, Address, O))
57
0
    printInstruction(MI, Address, O);
58
0
  ;
59
0
}
60
61
void LoongArch_LLVM_printInst(MCInst *MI, uint64_t Address, const char *Annot,
62
            SStream *O)
63
0
{
64
0
  printInst(MI, Address, Annot, O);
65
0
}
66
67
const char *LoongArch_LLVM_getRegisterName(unsigned RegNo, unsigned AltIdx)
68
0
{
69
0
  return getRegisterName(RegNo, AltIdx);
70
0
}
71
72
static void printRegName(SStream *O, MCRegister Reg)
73
0
{
74
0
  SStream_concat1(O, '$');
75
0
  SStream_concat0(O, getRegisterName(Reg, LoongArch_RegAliasName));
76
0
}
77
78
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
79
0
{
80
0
  add_cs_detail(MI, LOONGARCH_OP_GROUP_OPERAND, OpNo);
81
0
  MCOperand *MO = MCInst_getOperand(MI, (OpNo));
82
83
0
  if (MCOperand_isReg(MO)) {
84
0
    printRegName(O, MCOperand_getReg(MO));
85
0
    return;
86
0
  }
87
88
0
  if (MCOperand_isImm(MO)) {
89
0
    printInt64(O, MCOperand_getImm(MO));
90
0
    return;
91
0
  }
92
93
0
  assert(0 && "Expressions are not supported.");
94
0
}
95
96
static void printAtomicMemOp(MCInst *MI, unsigned OpNo, SStream *O)
97
0
{
98
0
  add_cs_detail(MI, LOONGARCH_OP_GROUP_ATOMICMEMOP, OpNo);
99
0
  MCOperand *MO = MCInst_getOperand(MI, (OpNo));
100
101
0
  printRegName(O, MCOperand_getReg(MO));
102
0
}