33 Commits

Author SHA1 Message Date
Ronald Caesar
ad0f881e1b engine: udpate clang-format rules
Makes Ballistic more inlime with BARR-C's style guide.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-24 20:48:49 -04:00
Ronald Caesar
5dada6c7a4 engine: add translation loop switch statement
Also made the decoder function name shorter.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-24 00:34:41 -04:00
Ronald Caesar
2cc7f297c9 engine: intern constants
This does two things so I'll split them.

(1) Add function intern_constant() which adds a constant to the
constants array and returns the index.

The assembly for this function is beautiful. Only one load and store on
a successfull path.

Dump of assembler code for function intern_constant:
   0x0000000000010ee0 <+0>:     ldr     w8, [x4]
   0x0000000000010ee4 <+4>:     cbnz    w8, 0x10f08 <intern_constant+40>
   0x0000000000010ee8 <+8>:     ldrh    w8, [x2]
   0x0000000000010eec <+12>:    cmp     x3, x8
   0x0000000000010ef0 <+16>:    b.ls    0x10f10 <intern_constant+48>  // b.plast
   0x0000000000010ef4 <+20>:    str     w0, [x1, x8, lsl #2]
   0x0000000000010ef8 <+24>:    add     w9, w8, #0x1
   0x0000000000010efc <+28>:    orr     w0, w8, #0x10000
   0x0000000000010f00 <+32>:    strh    w9, [x2]
   0x0000000000010f04 <+36>:    ret
   0x0000000000010f08 <+40>:    mov     w0, #0x10000                    // #65536
   0x0000000000010f0c <+44>:    ret
   0x0000000000010f10 <+48>:    mov     w8, #0xffffff9c                 // #-100
   0x0000000000010f14 <+52>:    mov     w0, #0x10000                    // #65536
   0x0000000000010f18 <+56>:    str     w8, [x4]
   0x0000000000010f1c <+60>:    ret
End of assembler dump.

(2) I've decided that the entire translation code will fit in
bal_engine.c so the bal_ir_immiter and bal_translator files are not
needed anymore. I moved their preprocessor definitions into bal_engine.c

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-23 20:45:07 -04:00
Ronald Caesar
6a7db3db18 engine: add operand bit extraction
Also tracks the current position in the constants array.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-23 19:19:22 -04:00
Ronald Caesar
fd080b323c decoder: static assert bitfield width
This guarantees the bitfield is 5 bits, so if someone in the future
decides to shift bits around in the struct it wont break Ballistic.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-23 18:57:09 -04:00
Ronald Caesar
24891bf97f engine: update bal_attributes.h docs formatting
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-23 18:19:58 -04:00
Ronald Caesar
d4a1d395ec engine: add arm64 and x86 environment detection
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-23 17:43:09 -04:00
Ronald Caesar
3b9703f316 decoder: include operands in metadata
Stores operand bit positions and types in the decoder metadata. This
makes it way easier to emit IR instructions.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-18 02:44:40 -04:00
Ronald Caesar
2596a20f31 decoder: rewrite docs for cdoc
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-17 18:25:43 -04:00
Ronald Caesar
a507a5d53e engine: convert array sizes to element count.
The array sizes, such as instructions_size, contains the size of the
array in bytes. This is wrong and should the max element count of the
array.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-17 03:26:47 -04:00
Ronald Caesar
3cf17ac088 tools: fix CDoc ordering of types
Fixes CDoc ordering the sidebar and main page types in alphabetical
order. Only the sidebar should be sorted and the main page should
be rendered the way its header file was parsed, top to bottom.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-17 02:06:36 -04:00
Ronald Caesar
0de6d5fc07 ir: fix clang-tidy warnings
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-16 22:56:03 -04:00
Ronald Caesar
3f78168ce5 tools: create a rustdoc like documentation generator
While I do not like the Rust Language as a whole, their documentation
generator is the best I've ever seen. in any language. I want to
implement something like it for Ballistic.

Like I said in the README, I have absolutely zero motivation to create
a documentation generator so `cdoc.c` is made completely with AI. The
code is messy but the generated HTML files look beautiful.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-16 20:23:12 -04:00
Ronald Caesar
7f792157f5 engine: add constants array
This was tricky one to add to bal_engine_t because the struct was
already pretty packed. The struct only had 12 bytes to spare but to add
the constants array and its size required 16 bytes. I determined that
ssa_bit_widths_size was not required since ssa_bit_widths[] and
instructions[] will be parallel to each other, so one variable can keep
track of both arrays.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-15 16:25:42 -04:00
Ronald Caesar
4e4e48e495 engine: change bal_instruction_t to 32-bits
I do not know what I was thinking when I made it 64-bits.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-15 10:03:07 -04:00
Ronald Caesar
f0a8ff857c engine: fix incorrect function doc
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-14 23:30:36 -04:00
Ronald Caesar
d74290e5fc engine: rename engine_run() to engine_translate()
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-14 23:27:52 -04:00
Ronald Caesar
00c2866fb4 memory: add flat translation interface
Defines the API for memory translation.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-14 22:39:06 -04:00
Ronald Caesar
3d02fab4b7 memory: add default allocator
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-14 19:45:44 -04:00
Ronald Caesar
37cb629909 engine: add platform detection header
I do not want compiler attributes like __clang__ or __linux__ scattered
everywhere to detect the platform Ballistic is running on, so I added
preprocessor directives to make things a lot cleaner.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-14 18:58:53 -04:00
Ronald Caesar
02501ae7a4 engine: add main jit compilation loop
Also remove bal_translate_block() body. It will need to be redesigned
to be used by bal_engine_run().

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-14 18:15:35 -04:00
Ronald Caesar
f72da3e121 decoder: add ir opcode to metadata struct
Instead of using strcmp() on each decoded intruction's mnemonic to
translate it, we embedd an IR opcode into the struct. This is a very
barebones implementation and does not cover the entire ARM instruction
set. ARM instructions that does not have an IR opcode equivalent will be
marked with `OPCODE_TRAP` and should be implemented in the future.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-13 23:31:06 -04:00
Ronald Caesar
0b0f4bab98 engine: add __restrict__ compiler attribute
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-13 18:28:39 -04:00
Ronald Caesar
35c88dd939 ir: add initial ir translation module
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-12 19:08:14 -04:00
Ronald Caesar
a15ed49f25 ir: move ir emitter header to src/
I see no reason to make this header public. This is used by Ballistic
only.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-12 17:30:04 -04:00
Ronald Caesar
4818664671 engine: add alignment compiler attribute
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-12 14:00:19 -04:00
Ronald Caesar
3ae7e33cd7 engine: add hints for cpu branch predictor
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-12 12:15:09 -04:00
Ronald Caesar
d54ade0c9f engine: reorganize compiler attribute docs
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-12 10:18:25 -04:00
Ronald Caesar
e671b6a4f1 ir: add compiler hints for cold functions
Also marked more functions as hot.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-12 09:19:27 -04:00
Ronald Caesar
0ca446238d ir: Add compiler hints to hot functions
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-12 00:13:19 -04:00
Ronald Caesar
126323943b ir: add bit width parameter to emit_instructions()
At first I wondered how will we know the bitfield of the ssa variable
we're creating? Should we hardcode the bit width in the opcode and
create a large switch statement or hash table? To keep things simple
I just added a new bit width parameter to emit_instruction() and it
will be the frontend's responsibility to find the correct bitwidth.
This should better for x86 lowering.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-11 23:41:47 -04:00
Ronald Caesar
07aa3173de engine: move public headers to include folder
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-10 18:30:45 -04:00
Ronald Caesar
4aa8335612 decoder: Make decoder API public
The decoder API is now suitable to be made public. decoder.h is the sole
entry point for the decoder and it has been moved to `include/`

Signed-off-by: Ronald Caesar <github43132@proton.me>
2025-12-12 18:11:43 -04:00