Skip to content

Commit

Permalink
Merge pull request #18 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
1.5.0: Rust bindings
  • Loading branch information
AngheloAlf authored Dec 18, 2022
2 parents 44b847f + b75637e commit 6e7b95d
Show file tree
Hide file tree
Showing 91 changed files with 8,312 additions and 495 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/publish_crate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and upload Rust crate

# Build on every branch push, tag push, and pull request change:
on: [push, pull_request]

jobs:
build_rust:
name: Build rust stuff
runs-on: ubuntu-latest

steps:
- name: Checkout reposistory
uses: actions/checkout@v3

- name: Build C library
run: make -j $(nproc) WERROR=1

- name: Run logic checks
run: ./tests/c/logic_checks/run_logic_checks.sh

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Build Rust bindings
run: cd rust && cargo build --release

- name: Upload crate
uses: katyo/publish-crates@v1
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
with:
path: './rust'
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ WARNINGS += -Werror=vla -Werror=switch -Werror=implicit-fallthrough -Werr
WARNINGS_C := -Werror=implicit-function-declaration -Werror=incompatible-pointer-types
WARNINGS_CXX :=

TABLE_GEN := tools/table_gen.sh

ifeq ($(CC),gcc)
WARNINGS += -Wno-cast-function-type
endif
Expand Down Expand Up @@ -66,6 +68,12 @@ OXX_FILES := $(foreach f,$(CXX_FILES:.cpp=.o),build/$f)

DEP_FILES := $(O_FILES:%.o=%.d) $(OXX_FILES:%.o=%.d)

TABLE_DIRS := $(shell find include src cplusplus rabbitizer -type d)
TABLE_TEMPLATES := $(foreach dir,$(TABLE_DIRS),$(wildcard $(dir)/*.table.template))
TABLE_GENERATED := $(TABLE_TEMPLATES:%.table.template=%.table.h)

TABLE_DEP_FILES := $(TABLE_GENERATED:%.table.h=%.table.d)

TESTS_DIRS := $(shell find tests -type d)
TESTS_C := $(foreach dir,$(TESTS_DIRS),$(wildcard $(dir)/*.c))
TESTS_CXX := $(foreach dir,$(TESTS_DIRS),$(wildcard $(dir)/*.cpp))
Expand Down Expand Up @@ -102,6 +110,7 @@ clean:

distclean: clean
$(RM) -rf dist *.egg-info .mypy_cache
$(RM) -rf $(TABLE_GENERATED)

format:
clang-format-11 -i -style=file $(C_FILES)
Expand Down Expand Up @@ -131,16 +140,22 @@ build/%.a:
build/%.so:
$(CC) -shared -o $@ $^

build/%.o: %.c
build/%.o: %.c | $(TABLE_GENERATED)
# The -MMD flags additionaly creates a .d file with the same name as the .o file.
$(CC) -MMD -MP -c $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(WARNINGS_C) $(CFLAGS) -o $@ $<

build/%.o: %.cpp
build/%.o: %.cpp | $(TABLE_GENERATED)
# The -MMD flags additionaly creates a .d file with the same name as the .o file.
$(CXX) -MMD -MP -c $(CXXSTD) $(OPTFLAGS) $(IINC_XX) $(WARNINGS) $(WARNINGS_CXX) $(CXXFLAGS) -o $@ $<


%.table.h: %.table.template
cpp -P $(IINC) -M -MM -MMD -MP -MF $(@:.table.h=.table.d) $<
$(TABLE_GEN) $< $@ $(@F)


-include $(DEP_FILES)
-include $(TABLE_DEP_FILES)

# Print target for debugging
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ NOTE: Installing the development version is not recommended. Proceed at your own
- Fully written in C for fast decoding.
- Python bindings.
- The minimal Python version is 3.7, older versions are not guaranteed to work.
- C++ bindings
- Rust bindings
- Includes some minor tools to build your own pointer/symbol detection.
- Configurable, many features can be turned on and off.
- MIPS instructions features:
Expand Down
10 changes: 1 addition & 9 deletions cplusplus/include/instructions/AccessType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@


namespace rabbitizer {
#define RAB_DEF_ACCESSTYPE(name) name,

enum class AccessType {
#include "instructions/AccessType.inc"

RAB_DEF_ACCESSTYPE(MAX)
};

#undef RAB_DEF_ACCESSTYPE
#include "AccessType_enum_class.table.h"
};


Expand Down
20 changes: 20 additions & 0 deletions cplusplus/include/instructions/AccessType_enum_class.table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */

/* Automatically generated. DO NOT MODIFY */

#ifndef AccessType_enum_class_table_h_automatic
#define AccessType_enum_class_table_h_automatic

enum class AccessType {
INVALID,
BYTE,
SHORT,
WORD,
DOUBLEWORD,
FLOAT,
DOUBLEFLOAT,
MAX,
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */

#define RAB_DEF_ACCESSTYPE(name) name,

enum class AccessType {
#include "instructions/AccessType.inc"

RAB_DEF_ACCESSTYPE(MAX)
};

#undef RAB_DEF_ACCESSTYPE
20 changes: 1 addition & 19 deletions cplusplus/include/instructions/InstrId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,7 @@

namespace rabbitizer {
namespace InstrId {
#define RABBITIZER_DEF_INSTR_ID(prefix, caseBits, name, ...) \
prefix##_##name,

#define RABBITIZER_DEF_INSTR_ID_ALTNAME(prefix, caseBits, name, altname, ...) \
RABBITIZER_DEF_INSTR_ID(prefix, caseBits, name, __VA_ARGS__)

enum class UniqueId {
#include "instructions/instr_id/RabbitizerInstrId_cpu.inc"

#include "instructions/instr_id/RabbitizerInstrId_rsp.inc"

#include "instructions/instr_id/RabbitizerInstrId_r5900.inc"

ALL_MAX = RABBITIZER_DEF_INSTR_ID(r5900, , MAX, )
};

#undef RABBITIZER_DEF_INSTR_ID
#undef RABBITIZER_DEF_INSTR_ID_ALTNAME

#include "UniqueId_enum_class.table.h"

std::string getOpcodeName(UniqueId uniqueId);
};
Expand Down
15 changes: 1 addition & 14 deletions cplusplus/include/instructions/OperandType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@


namespace rabbitizer {
#define RAB_DEF_OPERAND(prefix, operand) \
prefix##_##operand,

enum class OperandType {
RAB_DEF_OPERAND(ALL, INVALID)

#include "instructions/operands/RabbitizerOperandType_cpu.inc"
#include "instructions/operands/RabbitizerOperandType_rsp.inc"
#include "instructions/operands/RabbitizerOperandType_r5900.inc"

RAB_DEF_OPERAND(ALL, MAX)
};

#undef RAB_DEF_OPERAND
#include "OperandType_enum_class.table.h"
};


Expand Down
78 changes: 78 additions & 0 deletions cplusplus/include/instructions/OperandType_enum_class.table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */

/* Automatically generated. DO NOT MODIFY */

#ifndef OperandType_enum_class_table_h_automatic
#define OperandType_enum_class_table_h_automatic

enum class OperandType {
ALL_INVALID,
cpu_rs,
cpu_rt,
cpu_rd,
cpu_sa,
cpu_zero,
cpu_cop0d,
cpu_fs,
cpu_ft,
cpu_fd,
cpu_cop1cs,
cpu_cop2t,
cpu_op,
cpu_code,
cpu_code_lower,
cpu_copraw,
cpu_label,
cpu_immediate,
cpu_branch_target_label,
cpu_immediate_base,
rsp_rs,
rsp_rt,
rsp_rd,
rsp_cop0d,
rsp_cop2t,
rsp_cop2cd,
rsp_vs,
rsp_vt,
rsp_vd,
rsp_vt_elementhigh,
rsp_vt_elementlow,
rsp_vd_de,
rsp_vs_index,
rsp_offset_rs,
rsp_immediate_base,
r5900_I,
r5900_Q,
r5900_R,
r5900_ACC,
r5900_ACCxyzw,
r5900_vfs,
r5900_vft,
r5900_vfd,
r5900_vfsxyzw,
r5900_vftxyzw,
r5900_vfdxyzw,
r5900_vfsn,
r5900_vftn,
r5900_vfdn,
r5900_vfsl,
r5900_vftl,
r5900_vfdl,
r5900_vfsm,
r5900_vftm,
r5900_vfdm,
r5900_vis,
r5900_vit,
r5900_vid,
r5900_vis_predecr,
r5900_vit_predecr,
r5900_vid_predecr,
r5900_vis_postincr,
r5900_vit_postincr,
r5900_vid_postincr,
r5900_immediate5,
ALL_MAX,
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* SPDX-FileCopyrightText: © 2022 Decompollaborate */
/* SPDX-License-Identifier: MIT */

#define RAB_DEF_OPERAND(prefix, operand) \
prefix##_##operand,

enum class OperandType {
RAB_DEF_OPERAND(ALL, INVALID)

#include "instructions/operands/RabbitizerOperandType_cpu.inc"
#include "instructions/operands/RabbitizerOperandType_rsp.inc"
#include "instructions/operands/RabbitizerOperandType_r5900.inc"

RAB_DEF_OPERAND(ALL, MAX)
};

#undef RAB_DEF_OPERAND
80 changes: 1 addition & 79 deletions cplusplus/include/instructions/Registers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,8 @@


namespace rabbitizer {

namespace Registers {
#define RABBITIZER_DEF_REG(prefix, name, numeric) \
prefix##_##name

#define RABBITIZER_DEF_REG_NODOLLAR(prefix, name, numeric) \
prefix##_##name

namespace Cpu {
enum class GprO32 {
#include "instructions/registers/RabbitizerRegister_GprO32.inc"
};

enum class GprN32 {
#include "instructions/registers/RabbitizerRegister_GprN32.inc"
};


enum class Cop0 {
#include "instructions/registers/RabbitizerRegister_Cop0.inc"
};

// Float registers
enum class Cop1O32 {
#include "instructions/registers/RabbitizerRegister_Cop1O32.inc"
};

enum class Cop1N32 {
#include "instructions/registers/RabbitizerRegister_Cop1N32.inc"
};

enum class Cop1N64 {
#include "instructions/registers/RabbitizerRegister_Cop1N64.inc"
};

enum class Cop1Control {
#include "instructions/registers/RabbitizerRegister_Cop1Control.inc"
};

enum class Cop2 {
#include "instructions/registers/RabbitizerRegister_Cop2.inc"
};
};


namespace Rsp {
enum class Gpr {
#include "instructions/registers/RabbitizerRegister_RspGpr.inc"
};

enum class Cop0 {
#include "instructions/registers/RabbitizerRegister_RspCop0.inc"
};

enum class Cop2 {
#include "instructions/registers/RabbitizerRegister_RspCop2.inc"
};

enum class Cop2Control {
#include "instructions/registers/RabbitizerRegister_RspCop2Control.inc"
};

enum class Vector {
#include "instructions/registers/RabbitizerRegister_RspVector.inc"
};
};


namespace R5900 {
enum class VF {
#include "instructions/registers/RabbitizerRegister_R5900VF.inc"
};

enum class VI {
#include "instructions/registers/RabbitizerRegister_R5900VI.inc"
};
};

#undef RABBITIZER_DEF_REG
#undef RABBITIZER_DEF_REG_NODOLLAR
#include "Registers_enum_classes.table.h"
};
};

Expand Down
Loading

0 comments on commit 6e7b95d

Please sign in to comment.