rabbitizer/include/instructions/RabbitizerInstrDescriptor.h

269 lines
8.7 KiB
C
Raw Normal View History

2022-06-03 17:46:51 +00:00
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */
#ifndef RABBITIZER_INSTRDESCRIPTOR_H
#define RABBITIZER_INSTRDESCRIPTOR_H
#pragma once
#include <stdbool.h>
2022-07-09 23:19:53 +00:00
#include "common/Utils.h"
#include "RabbitizerOperandType.h"
2022-06-03 17:46:51 +00:00
#include "RabbitizerInstrId.h"
#include "RabbitizerInstrSuffix.h"
2022-10-13 22:41:46 +00:00
#include "RabbitizerAccessType.h"
2022-06-03 17:46:51 +00:00
2022-10-04 11:31:02 +00:00
#ifdef __cplusplus
extern "C" {
#endif
//! @deprecated
2022-06-03 17:46:51 +00:00
typedef enum RabbitizerInstrType {
RABBITIZER_INSTR_TYPE_UNKNOWN,
RABBITIZER_INSTR_TYPE_J,
RABBITIZER_INSTR_TYPE_I,
RABBITIZER_INSTR_TYPE_R,
RABBITIZER_INSTR_TYPE_REGIMM,
RABBITIZER_INSTR_TYPE_MAX,
} RabbitizerInstrType;
2022-12-19 20:07:32 +00:00
// Please note the members of this struct may be renamed or removed without further notice.
// For consistent usage please use the functions instead
2022-06-03 17:46:51 +00:00
typedef struct RabbitizerInstrDescriptor {
RabbitizerOperandType operands[4];
2022-06-03 17:46:51 +00:00
RabbitizerInstrType instrType;
RabbitizerInstrSuffix instrSuffix;
/**
* Local branch with "restricted" range, usually it doesn't jump outside the current function
*/
2022-06-03 17:46:51 +00:00
bool isBranch;
bool isBranchLikely;
/**
* The instruction can jump inside or outside its current function
*/
2022-06-03 17:46:51 +00:00
bool isJump;
2022-10-13 17:32:36 +00:00
/**
* The target address of this jump is encoded in the instruction (MIPS: J and JAL)
*/
bool isJumpWithAddress;
/**
* Triggers a trap on the processor
*/
2022-06-03 17:46:51 +00:00
bool isTrap;
/**
* The instruction performs float (any kind of float, including double precision) operations
*/
2022-06-03 17:46:51 +00:00
bool isFloat;
/**
* The instruction performs double precision float operations
*/
2022-06-03 17:46:51 +00:00
bool isDouble;
/**
* The instruction holds an immediate which is treated as an unsigned value,
* otherwise the immediate it may hold should be treated as a Two's complement value
*/
2022-06-03 17:46:51 +00:00
bool isUnsigned;
2022-12-20 03:42:27 +00:00
/**
* The instruction modifies the state of the MIPS `rs` register
*/
bool modifiesRs;
/**
* The instruction modifies the state of the MIPS `rt` register
*/
2022-06-03 17:46:51 +00:00
bool modifiesRt;
/**
* The instruction modifies the state of the MIPS `rd` register
*/
2022-06-03 17:46:51 +00:00
bool modifiesRd;
2022-12-14 21:03:13 +00:00
/**
* The instruction reads the value which the MIPS `rs` register holds
*/
bool readsRs;
/**
* The instruction reads the value which the MIPS `rt` register holds
*/
bool readsRt;
/**
* The instruction reads the value which the MIPS `rd` register holds
*/
bool readsRd;
2022-10-14 17:58:14 +00:00
bool readsHI;
bool readsLO;
bool modifiesHI;
bool modifiesLO;
2022-12-20 03:42:27 +00:00
bool modifiesFs;
bool modifiesFt;
bool modifiesFd;
bool readsFs;
bool readsFt;
bool readsFd;
/**
* This instruction is not emited by a C compiler
*/
2022-12-26 23:24:41 +00:00
bool notEmittedByCompilers;
2022-06-08 06:17:35 +00:00
/**
* The instruction can hold the "hi" value of a %hi/%lo pair
*/
bool canBeHi;
/**
* The instruction can hold the "lo" value of a %hi/%lo pair
*/
bool canBeLo;
/**
* "and link" family of instructions
* The instruction stores the return address link in the MIPS $ra (GPR 31) register
*/
bool doesLink;
/**
* This instruction performs a pointer dereference, either by loading from RAM or storing into RAM
*/
2022-06-08 06:17:35 +00:00
bool doesDereference;
/**
* Dereferences a pointer and loads data from RAM
*/
bool doesLoad;
/**
* Dereferences a pointer and stores data to RAM
*/
bool doesStore;
/**
* This instruction may be the result of expanding the `move` pseudo-instruction
*/
2022-06-11 21:49:33 +00:00
bool maybeIsMove;
2022-06-08 06:17:35 +00:00
/**
* This instruction is a pseudo-instruction
*/
bool isPseudo;
2022-10-13 22:41:46 +00:00
RabbitizerAccessType accessType;
bool doesUnsignedMemoryAccess;
2022-06-03 17:46:51 +00:00
} RabbitizerInstrDescriptor;
2022-06-04 00:19:58 +00:00
extern const RabbitizerInstrDescriptor RabbitizerInstrDescriptor_Descriptors[];
2022-06-03 17:46:51 +00:00
2022-06-04 06:17:25 +00:00
2022-12-15 19:06:48 +00:00
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_hasSpecificOperand(const RabbitizerInstrDescriptor *self, RabbitizerOperandType operand);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_hasOperandAlias(const RabbitizerInstrDescriptor *self, RabbitizerOperandType operand);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-09 02:44:43 +00:00
bool RabbitizerInstrDescriptor_isUnknownType(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isJType(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isIType(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isRType(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-09 02:44:43 +00:00
bool RabbitizerInstrDescriptor_isRegimmType(const RabbitizerInstrDescriptor *self);
2022-06-04 06:17:25 +00:00
NODISCARD NON_NULL(1) PURE
RabbitizerInstrSuffix RabbitizerInstrDescriptor_instrSuffix(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isBranch(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isBranchLikely(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isJump(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-10-13 17:32:36 +00:00
bool RabbitizerInstrDescriptor_isJumpWithAddress(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isTrap(const RabbitizerInstrDescriptor *self);
2022-06-04 06:17:25 +00:00
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isFloat(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isDouble(const RabbitizerInstrDescriptor *self);
2022-06-04 06:17:25 +00:00
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_isUnsigned(const RabbitizerInstrDescriptor *self);
2022-06-04 06:17:25 +00:00
2022-12-20 03:42:27 +00:00
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_modifiesRs(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_modifiesRt(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-05 17:19:45 +00:00
bool RabbitizerInstrDescriptor_modifiesRd(const RabbitizerInstrDescriptor *self);
2022-06-04 06:17:25 +00:00
2022-12-14 21:03:13 +00:00
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_readsRs(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_readsRt(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_readsRd(const RabbitizerInstrDescriptor *self);
2022-10-14 17:58:14 +00:00
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_readsHI(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_readsLO(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_modifiesHI(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_modifiesLO(const RabbitizerInstrDescriptor *self);
2022-12-20 03:42:27 +00:00
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_modifiesFs(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_modifiesFt(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_modifiesFd(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_readsFs(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_readsFt(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_readsFd(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-12-26 23:24:41 +00:00
bool RabbitizerInstrDescriptor_notEmittedByCompilers(const RabbitizerInstrDescriptor *self);
//! @deprecated
#define RabbitizerInstrDescriptor_notEmitedByCompilers RabbitizerInstrDescriptor_notEmittedByCompilers
2022-06-08 06:17:35 +00:00
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_canBeHi(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_canBeLo(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-08 06:17:35 +00:00
bool RabbitizerInstrDescriptor_doesLink(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-08 06:17:35 +00:00
bool RabbitizerInstrDescriptor_doesDereference(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-07-05 17:32:24 +00:00
bool RabbitizerInstrDescriptor_doesLoad(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-07-05 17:32:24 +00:00
bool RabbitizerInstrDescriptor_doesStore(const RabbitizerInstrDescriptor *self);
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
2022-06-11 21:49:33 +00:00
bool RabbitizerInstrDescriptor_maybeIsMove(const RabbitizerInstrDescriptor *self);
2022-06-08 06:17:35 +00:00
2022-07-09 23:19:53 +00:00
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_isPseudo(const RabbitizerInstrDescriptor *self);
2022-10-13 22:41:46 +00:00
NODISCARD NON_NULL(1) PURE
RabbitizerAccessType RabbitizerInstrDescriptor_getAccessType(const RabbitizerInstrDescriptor *self);
NODISCARD NON_NULL(1) PURE
bool RabbitizerInstrDescriptor_doesUnsignedMemoryAccess(const RabbitizerInstrDescriptor *self);
2022-10-13 22:41:46 +00:00
2022-10-04 11:31:02 +00:00
#ifdef __cplusplus
}
#endif
2022-06-03 17:46:51 +00:00
#endif