Add markdown linter to CI

This commit is contained in:
angie 2023-09-22 15:54:19 -03:00
parent f63d4cdd8c
commit 802f953b59
8 changed files with 91 additions and 63 deletions

17
.github/workflows/md_lint.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: Lint markdown files
# Build on every branch push, tag push, and pull request change:
on: [push, pull_request]
jobs:
checks:
runs-on: ubuntu-latest
name: Lint md files
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Lint markdown files
uses: articulate/actions-markdownlint@v1.1.0
with:
config: .markdownlint.jsonc

3
.gitignore vendored
View File

@ -211,7 +211,8 @@ dmypy.json
cython_debug/ cython_debug/
.vscode/ .vscode/*
!.vscode/extensions.json
# Generated by Cargo # Generated by Cargo
# will have compiled files and executables # will have compiled files and executables

7
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"davidanson.vscode-markdownlint"
]
}

View File

@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added
- Add `CHANGELOG.md` - Add `CHANGELOG.md`
- Add markdown linter to CI
## [1.7.9] - 2023-09-18 ## [1.7.9] - 2023-09-18

View File

@ -4,7 +4,7 @@
[package] [package]
name = "rabbitizer" name = "rabbitizer"
# Version should be synced with include/common/RabbitizerVersion.h # Version should be synced with include/common/RabbitizerVersion.h
version = "1.7.9" version = "1.7.10"
edition = "2021" edition = "2021"
authors = ["Anghelo Carvajal <angheloalf95@gmail.com>"] authors = ["Anghelo Carvajal <angheloalf95@gmail.com>"]
description = "MIPS instruction decoder" description = "MIPS instruction decoder"

View File

@ -48,89 +48,89 @@ Let's break up the example and explain each part:
1. The stack 1. The stack
The `RabbitizerInstruction` type is the type `rabbitizer` uses to represent an The `RabbitizerInstruction` type is the type `rabbitizer` uses to represent an
instruction. It is a simple struct which doesn't need dynamic memory instruction. It is a simple struct which doesn't need dynamic memory
allocation of any kind, so it can be declared as an automatic variable and live allocation of any kind, so it can be declared as an automatic variable and live
in the stack, without worrying about pointers and such. in the stack, without worrying about pointers and such.
The other stack variables should be self-explanatory. `word` is a 32-bit word The other stack variables should be self-explanatory. `word` is a 32-bit word
representing a raw MIPS instruction (spoiler, it is an `lw`). `rabbitizer` representing a raw MIPS instruction (spoiler, it is an `lw`). `rabbitizer`
needs to know the `vram` address of the instruction it is decoding, so we needs to know the `vram` address of the instruction it is decoding, so we
initialize with a place-holder one. `buffer` and `bufferSize` will be used for initialize with a place-holder one. `buffer` and `bufferSize` will be used for
storing the disassembled string. storing the disassembled string.
```c ```c
int main() { int main() {
RabbitizerInstruction instr; RabbitizerInstruction instr;
uint32_t word = 0x8D4A7E18; uint32_t word = 0x8D4A7E18;
uint32_t vram = 0x80000000; uint32_t vram = 0x80000000;
char *buffer; char *buffer;
size_t bufferSize; size_t bufferSize;
``` ```
2. Initializing 2. Initializing
To initialize our `instr` we need to call the pair `RabbitizerInstruction_init` To initialize our `instr` we need to call the pair `RabbitizerInstruction_init`
and `RabbitizerInstruction_processUniqueId`. `RabbitizerInstruction_init` and `RabbitizerInstruction_processUniqueId`. `RabbitizerInstruction_init`
initialises all the members of the struct so it doesn't contain garbage data initialises all the members of the struct so it doesn't contain garbage data
anymore, while `RabbitizerInstruction_processUniqueId` does the heavy lifting of anymore, while `RabbitizerInstruction_processUniqueId` does the heavy lifting of
identifying the actual instruction id out of the `word` we passed. identifying the actual instruction id out of the `word` we passed.
A `RabbitizerInstruction` variable is not considered fully initialized until it A `RabbitizerInstruction` variable is not considered fully initialized until it
has been passed to this pair of functions. has been passed to this pair of functions.
```c ```c
RabbitizerInstruction_init(&instr, word, vram); RabbitizerInstruction_init(&instr, word, vram);
RabbitizerInstruction_processUniqueId(&instr); RabbitizerInstruction_processUniqueId(&instr);
``` ```
3. Disassembling into a string 3. Disassembling into a string
To disassemble the passed word as a string we can call To disassemble the passed word as a string we can call
`RabbitizerInstruction_disassemble`. This function expects a `char` buffer to `RabbitizerInstruction_disassemble`. This function expects a `char` buffer to
fill, which should have enough space to hold the resulting string. To know how fill, which should have enough space to hold the resulting string. To know how
big this buffer needs to be we should use the big this buffer needs to be we should use the
`RabbitizerInstruction_getSizeForBuffer` function which calculates a size big `RabbitizerInstruction_getSizeForBuffer` function which calculates a size big
enough to hold the disassembled string for the passed instruction (without enough to hold the disassembled string for the passed instruction (without
taking into account the finalizing NUL character, similar to how `strlen` taking into account the finalizing NUL character, similar to how `strlen`
behaves). behaves).
With this information we can just `malloc` our buffer and call With this information we can just `malloc` our buffer and call
`RabbitizerInstruction_disassemble` to get our disassembled instruction. `RabbitizerInstruction_disassemble` to get our disassembled instruction.
(Ignore the extra `0` and `NULL` arguments for now, they will be discussed later) (Ignore the extra `0` and `NULL` arguments for now, they will be discussed later)
```c ```c
bufferSize = RabbitizerInstruction_getSizeForBuffer(&instr, 0, 0); bufferSize = RabbitizerInstruction_getSizeForBuffer(&instr, 0, 0);
buffer = malloc(bufferSize + 1); buffer = malloc(bufferSize + 1);
RabbitizerInstruction_disassemble(&instr, buffer, NULL, 0, 0); RabbitizerInstruction_disassemble(&instr, buffer, NULL, 0, 0);
``` ```
4. Printing 4. Printing
Not much to say here, just print the disassembled instruction to `stdout`. Not much to say here, just print the disassembled instruction to `stdout`.
```c ```c
printf("%s\n", buffer); printf("%s\n", buffer);
``` ```
5. Clean-up 5. Clean-up
Finally since we know we won't be using the produced string or the instruction Finally since we know we won't be using the produced string or the instruction
we just `free` and `RabbitizerInstruction_destroy` them. we just `free` and `RabbitizerInstruction_destroy` them.
As a curiosity, `RabbitizerInstruction_destroy` currently does nothing, but As a curiosity, `RabbitizerInstruction_destroy` currently does nothing, but
exists in case some destruction is needed in the future, so it recommended to exists in case some destruction is needed in the future, so it recommended to
call this function as a future-proof method. call this function as a future-proof method.
```c ```c
free(buffer); free(buffer);
RabbitizerInstruction_destroy(&instr); RabbitizerInstruction_destroy(&instr);
return 0; return 0;
} }
``` ```
## Overriding the immediate ## Overriding the immediate

View File

@ -14,7 +14,7 @@ extern "C" {
// Header version // Header version
#define RAB_VERSION_MAJOR 1 #define RAB_VERSION_MAJOR 1
#define RAB_VERSION_MINOR 7 #define RAB_VERSION_MINOR 7
#define RAB_VERSION_PATCH 9 #define RAB_VERSION_PATCH 10
#define RAB_VERSION_STR RAB_STRINGIFY(RAB_VERSION_MAJOR) "." RAB_STRINGIFY(RAB_VERSION_MINOR) "." RAB_STRINGIFY(RAB_VERSION_PATCH) #define RAB_VERSION_STR RAB_STRINGIFY(RAB_VERSION_MAJOR) "." RAB_STRINGIFY(RAB_VERSION_MINOR) "." RAB_STRINGIFY(RAB_VERSION_PATCH)

View File

@ -4,7 +4,7 @@
[project] [project]
name = "rabbitizer" name = "rabbitizer"
# Version should be synced with include/common/RabbitizerVersion.h # Version should be synced with include/common/RabbitizerVersion.h
version = "1.7.9" version = "1.7.10"
description = "MIPS instruction decoder" description = "MIPS instruction decoder"
# license = "MIT" # license = "MIT"
readme = "README.md" readme = "README.md"