AccessType enum

This commit is contained in:
angie 2022-10-13 19:41:46 -03:00
parent 7dc241a036
commit 7cec779b85
18 changed files with 201 additions and 27 deletions

View File

@ -0,0 +1,22 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */
#ifndef RABBITIZER_ACCESS_TYPE_HPP
#define RABBITIZER_ACCESS_TYPE_HPP
#pragma once
namespace rabbitizer {
#define RAB_DEF_ACCESSTYPE(name) name,
enum class AccessType {
#include "instructions/AccessType.inc"
RAB_DEF_ACCESSTYPE(MAX)
};
#undef RAB_DEF_ACCESSTYPE
};
#endif

View File

@ -13,6 +13,7 @@
#include "instructions/Registers.hpp"
#include "instructions/OperandType.hpp"
#include "instructions/InstrId.hpp"
#include "instructions/AccessType.hpp"
namespace rabbitizer {
@ -181,6 +182,7 @@ namespace rabbitizer {
bool isJrNotRa() const;
bool hasDelaySlot() const;
//! @deprecated
std::string mapInstrToType() const;
bool sameOpcode(const InstructionBase &other) const;
@ -232,6 +234,8 @@ namespace rabbitizer {
bool isPseudo() const;
AccessType getAccessType() const;
/* Instruction descriptor */

View File

@ -872,6 +872,10 @@ bool InstructionBase::isPseudo() const {
return RabbitizerInstrDescriptor_isPseudo(this->instr.descriptor);
}
AccessType InstructionBase::getAccessType() const {
return static_cast<AccessType>(RabbitizerInstrDescriptor_getAccessType(this->instr.descriptor));
}
/* Instruction descriptor */
/* Disassembly */

View File

@ -0,0 +1,15 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */
RAB_DEF_ACCESSTYPE(INVALID)
RAB_DEF_ACCESSTYPE(BYTE_SIGNED)
RAB_DEF_ACCESSTYPE(BYTE_UNSIGNED)
RAB_DEF_ACCESSTYPE(SHORT_SIGNED)
RAB_DEF_ACCESSTYPE(SHORT_UNSIGNED)
RAB_DEF_ACCESSTYPE(WORD_SIGNED)
RAB_DEF_ACCESSTYPE(WORD_UNSIGNED)
RAB_DEF_ACCESSTYPE(DOUBLEWORD_SIGNED)
RAB_DEF_ACCESSTYPE(DOUBLEWORD_UNSIGNED)
RAB_DEF_ACCESSTYPE(FLOAT_SIGNED)
RAB_DEF_ACCESSTYPE(DOUBLEFLOAT_SIGNED)

View File

@ -0,0 +1,28 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */
#ifndef RABBITIZER_ACCESS_TYPE_H
#define RABBITIZER_ACCESS_TYPE_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define RAB_DEF_ACCESSTYPE(name) RAB_ACCESSTYPE_##name,
typedef enum RabbitizerAccessType {
#include "instructions/AccessType.inc"
RAB_DEF_ACCESSTYPE(MAX)
} RabbitizerAccessType;
#undef RAB_DEF_ACCESSTYPE
#ifdef __cplusplus
}
#endif
#endif

View File

@ -11,6 +11,7 @@
#include "RabbitizerOperandType.h"
#include "RabbitizerInstrId.h"
#include "RabbitizerInstrSuffix.h"
#include "RabbitizerAccessType.h"
#ifdef __cplusplus
extern "C" {
@ -116,6 +117,8 @@ typedef struct RabbitizerInstrDescriptor {
* This instruction is a pseudo-instruction
*/
bool isPseudo;
RabbitizerAccessType accessType;
} RabbitizerInstrDescriptor;
// TODO: less redundant name
@ -181,6 +184,9 @@ bool RabbitizerInstrDescriptor_maybeIsMove(const RabbitizerInstrDescriptor *self
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isPseudo(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
RabbitizerAccessType RabbitizerInstrDescriptor_getAccessType(const RabbitizerInstrDescriptor *self);
#ifdef __cplusplus
}

View File

@ -207,6 +207,7 @@ bool RabbitizerInstruction_isJrNotRa(const RabbitizerInstruction *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstruction_hasDelaySlot(const RabbitizerInstruction *self);
//! @deprecated
NODISCARD NON_NULL(1) PURE
const char *RabbitizerInstruction_mapInstrToType(const RabbitizerInstruction *self);

View File

@ -175,7 +175,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_BYTE_SIGNED
) // Load Byte
RABBITIZER_DEF_INSTR_ID(
cpu, 0x21, lh,
@ -184,7 +185,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_SHORT_SIGNED
) // Load Halfword
RABBITIZER_DEF_INSTR_ID(
cpu, 0x22, lwl,
@ -202,7 +204,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_WORD_SIGNED
) // Load Word
RABBITIZER_DEF_INSTR_ID(
cpu, 0x24, lbu,
@ -211,7 +214,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_BYTE_UNSIGNED
) // Load Byte Insigned
RABBITIZER_DEF_INSTR_ID(
cpu, 0x25, lhu,
@ -220,7 +224,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_SHORT_UNSIGNED
) // Load Halfword Unsigned
RABBITIZER_DEF_INSTR_ID(
cpu, 0x26, lwr,
@ -238,7 +243,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_WORD_UNSIGNED
) // Load Word Unsigned
RABBITIZER_DEF_INSTR_ID(
cpu, 0x28, sb,
@ -246,7 +252,8 @@ RABBITIZER_DEF_INSTR_ID(
.instrType=RABBITIZER_INSTR_TYPE_I,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_BYTE_SIGNED
) // Store Byte
RABBITIZER_DEF_INSTR_ID(
cpu, 0x29, sh,
@ -254,7 +261,8 @@ RABBITIZER_DEF_INSTR_ID(
.instrType=RABBITIZER_INSTR_TYPE_I,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_SHORT_SIGNED
) // Store Halfword
RABBITIZER_DEF_INSTR_ID(
cpu, 0x2A, swl,
@ -270,7 +278,8 @@ RABBITIZER_DEF_INSTR_ID(
.instrType=RABBITIZER_INSTR_TYPE_I,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_WORD_SIGNED
) // Store Word
RABBITIZER_DEF_INSTR_ID(
cpu, 0x2C, sdl,
@ -329,7 +338,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_DOUBLEWORD_SIGNED
) // Load Doubleword
RABBITIZER_DEF_INSTR_ID(
cpu, 0x38, sc,
@ -353,7 +363,8 @@ RABBITIZER_DEF_INSTR_ID(
.instrType=RABBITIZER_INSTR_TYPE_I,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_DOUBLEWORD_SIGNED
) // Store Doubleword
// OP op, IMM(base)
@ -372,7 +383,8 @@ RABBITIZER_DEF_INSTR_ID(
.isFloat=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_FLOAT_SIGNED
) // Load Word to Coprocessor z
RABBITIZER_DEF_INSTR_ID(
cpu, 0x35, ldc1,
@ -382,7 +394,8 @@ RABBITIZER_DEF_INSTR_ID(
.isDouble=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_DOUBLEFLOAT_SIGNED
) // Load Doubleword to Coprocessor z
RABBITIZER_DEF_INSTR_ID(
cpu, 0x39, swc1,
@ -391,7 +404,8 @@ RABBITIZER_DEF_INSTR_ID(
.isFloat=true,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_FLOAT_SIGNED
) // Store Word from Coprocessor z
RABBITIZER_DEF_INSTR_ID(
cpu, 0x3D, sdc1,
@ -401,7 +415,8 @@ RABBITIZER_DEF_INSTR_ID(
.isDouble=true,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_DOUBLEFLOAT_SIGNED
) // Store Doubleword from Coprocessor z
// OP cop2t, IMM(base)

View File

@ -115,7 +115,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_BYTE_SIGNED
) // Load Byte
RABBITIZER_DEF_INSTR_ID(
rsp, 0x21, lh,
@ -124,7 +125,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_SHORT_SIGNED
) // Load Halfword
RABBITIZER_DEF_INSTR_ID(
rsp, 0x23, lw,
@ -133,7 +135,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_WORD_SIGNED
) // Load Word
RABBITIZER_DEF_INSTR_ID(
rsp, 0x24, lbu,
@ -142,7 +145,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_BYTE_UNSIGNED
) // Load Byte Insigned
RABBITIZER_DEF_INSTR_ID(
rsp, 0x25, lhu,
@ -151,7 +155,8 @@ RABBITIZER_DEF_INSTR_ID(
.modifiesRt=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_SHORT_UNSIGNED
) // Load Halfword Unsigned
RABBITIZER_DEF_INSTR_ID(
rsp, 0x28, sb,
@ -159,7 +164,8 @@ RABBITIZER_DEF_INSTR_ID(
.instrType=RABBITIZER_INSTR_TYPE_I,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_BYTE_SIGNED
) // Store Byte
RABBITIZER_DEF_INSTR_ID(
rsp, 0x29, sh,
@ -167,7 +173,8 @@ RABBITIZER_DEF_INSTR_ID(
.instrType=RABBITIZER_INSTR_TYPE_I,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_SHORT_SIGNED
) // Store Halfword
RABBITIZER_DEF_INSTR_ID(
rsp, 0x2B, sw,
@ -175,7 +182,8 @@ RABBITIZER_DEF_INSTR_ID(
.instrType=RABBITIZER_INSTR_TYPE_I,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_WORD_SIGNED
) // Store Word
RABBITIZER_DEF_INSTR_ID(
rsp, 0x33, pref,
@ -201,7 +209,8 @@ RABBITIZER_DEF_INSTR_ID(
.isFloat=true,
.canBeLo=true,
.doesDereference=true,
.doesLoad=true
.doesLoad=true,
.accessType=RAB_ACCESSTYPE_FLOAT_SIGNED
) // Load Word to Coprocessor z
RABBITIZER_DEF_INSTR_ID(
rsp, 0x39, swc1,
@ -210,7 +219,8 @@ RABBITIZER_DEF_INSTR_ID(
.isFloat=true,
.canBeLo=true,
.doesDereference=true,
.doesStore=true
.doesStore=true,
.accessType=RAB_ACCESSTYPE_FLOAT_SIGNED
) // Store Word from Coprocessor z

25
rabbitizer/AccessType.pyi Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-License-Identifier: MIT
from __future__ import annotations
from .Enum import Enum
class AccessType:
INVALID: Enum
BYTE_SIGNED: Enum
BYTE_UNSIGNED: Enum
SHORT_SIGNED: Enum
SHORT_UNSIGNED: Enum
WORD_SIGNED: Enum
WORD_UNSIGNED: Enum
DOUBLEWORD_SIGNED: Enum
DOUBLEWORD_UNSIGNED: Enum
FLOAT_SIGNED: Enum
DOUBLEFLOAT_SIGNED: Enum
MAX: Enum

View File

@ -11,6 +11,7 @@ from .Enum import *
from .InstrCategory import *
from .InstrId import *
from .OperandType import *
from .AccessType import *
from .RegGprO32 import *
from .RegGprN32 import *

View File

@ -0,0 +1,25 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */
#include "enums_utils.h"
#include "instructions/RabbitizerAccessType.h"
#define RAB_DEF_ACCESSTYPE(name) { "AccessType", #name , RAB_ACCESSTYPE_##name, false, NULL },
RabbitizerEnumMetadata rabbitizer_enum_AccessType_enumvalues[] = {
#include "instructions/AccessType.inc"
RAB_DEF_ACCESSTYPE(MAX)
{ 0 },
};
#undef RAB_DEF_ACCESSTYPE
static PyMethodDef rabbitizer_enum_AccessType_methods[] = {
{ 0 },
};
DEF_ENUM(AccessType, "")

View File

@ -62,7 +62,7 @@ class Instruction:
def isJrRa(self) -> bool: ...
def isJrNotRa(self) -> bool: ...
def hasDelaySlot(self) -> bool: ...
def mapInstrToType(self) -> str|None: ...
def mapInstrToType(self) -> str|None: ... #! deprecated
def sameOpcode(self, other: Instruction) -> bool: ...
def sameOpcodeButDifferentArguments(self, other: Instruction) -> bool: ...
@ -102,6 +102,7 @@ class Instruction:
def doesStore(self) -> bool: ...
def maybeIsMove(self) -> bool: ...
def isPseudo(self) -> bool: ...
def getAccessType(self) -> Enum: ...
def disassemble(self, immOverride: str|None=None, extraLJust: int=0) -> str: ...

View File

@ -42,6 +42,7 @@ static ModuleAttributes rabbitizer_module_attributes[] = {
MODULE_ATTRIBUTE_ENUM(InstrCategory),
MODULE_ATTRIBUTE_ENUM(InstrId),
MODULE_ATTRIBUTE_ENUM(OperandType),
MODULE_ATTRIBUTE_ENUM(AccessType),
MODULE_ATTRIBUTE_ENUM(RegGprO32),
MODULE_ATTRIBUTE_ENUM(RegGprN32),

View File

@ -48,6 +48,7 @@ DECL_ENUM(Abi)
DECL_ENUM(InstrCategory)
DECL_ENUM(InstrId)
DECL_ENUM(OperandType)
DECL_ENUM(AccessType)
DECL_ENUM(RegGprO32)
DECL_ENUM(RegGprN32)

View File

@ -329,6 +329,16 @@ DEF_DESCRIPTOR_METHOD_BOOL(doesStore)
DEF_DESCRIPTOR_METHOD_BOOL(maybeIsMove)
DEF_DESCRIPTOR_METHOD_BOOL(isPseudo)
static PyObject *rabbitizer_type_Instruction_getAccessType(PyRabbitizerInstruction *self, UNUSED PyObject *closure) {
RabbitizerAccessType accessType = RabbitizerInstrDescriptor_getAccessType(self->instr.descriptor);
PyObject *enumInstance;
enumInstance = rabbitizer_enum_AccessType_enumvalues[accessType].instance;
Py_INCREF(enumInstance);
return enumInstance;
}
static PyObject *rabbitizer_type_Instruction_disassemble(PyRabbitizerInstruction *self, PyObject *args, PyObject *kwds) {
static char *kwlist[] = {"immOverride", "extraLJust", NULL};
@ -438,6 +448,7 @@ static PyMethodDef rabbitizer_type_Instruction_methods[] = {
METHOD_NO_ARGS(doesStore, ""),
METHOD_NO_ARGS(maybeIsMove, ""),
METHOD_NO_ARGS(isPseudo, ""),
METHOD_NO_ARGS(getAccessType, ""),
METHOD_ARGS(disassemble, "description"),

View File

@ -9,7 +9,7 @@ setup(
Extension(
name="rabbitizer",
sources=["rabbitizer/rabbitizer_module.c", "rabbitizer/rabbitizer_submodule_Utils.c", "rabbitizer/rabbitizer_type_Instruction.c", "rabbitizer/rabbitizer_global_config.c", "rabbitizer/rabbitizer_type_TrackedRegisterState.c", "rabbitizer/rabbitizer_type_RegistersTracker.c", "rabbitizer/rabbitizer_type_LoPairingInfo.c",
"rabbitizer/enums/rabbitizer_type_Enum.c", "rabbitizer/enums/enums_utils.c", "rabbitizer/enums/rabbitizer_enum_InstrCategory.c", "rabbitizer/enums/rabbitizer_enum_InstrId.c", "rabbitizer/enums/rabbitizer_enum_Abi.c", "rabbitizer/enums/rabbitizer_enum_OperandType.c",
"rabbitizer/enums/rabbitizer_type_Enum.c", "rabbitizer/enums/enums_utils.c", "rabbitizer/enums/rabbitizer_enum_InstrCategory.c", "rabbitizer/enums/rabbitizer_enum_InstrId.c", "rabbitizer/enums/rabbitizer_enum_Abi.c", "rabbitizer/enums/rabbitizer_enum_OperandType.c", "rabbitizer/enums/rabbitizer_enum_AccessType.c",
"rabbitizer/enums/registers/rabbitizer_enum_GprO32.c", "rabbitizer/enums/registers/rabbitizer_enum_GprN32.c",
"src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c", "src/instructions/RabbitizerInstruction/RabbitizerInstruction_ProcessUniqueId.c", "src/instructions/RabbitizerInstruction/RabbitizerInstruction.c", "src/instructions/RabbitizerInstruction/RabbitizerInstruction_Examination.c",
"src/instructions/RabbitizerInstructionCpu/RabbitizerInstructionCpu_OperandType.c",

View File

@ -101,3 +101,7 @@ bool RabbitizerInstrDescriptor_maybeIsMove(const RabbitizerInstrDescriptor *self
bool RabbitizerInstrDescriptor_isPseudo(const RabbitizerInstrDescriptor *self) {
return self->isPseudo;
}
RabbitizerAccessType RabbitizerInstrDescriptor_getAccessType(const RabbitizerInstrDescriptor *self) {
return self->accessType;
}