Commit Graph

153 Commits

Author SHA1 Message Date
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
1a1ce44c87 engine: add incomplete translator loop
Everything has been setup except for the main translation loop which
have to be done another day. Its after midnight for me right now :(

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-14 00:06:15 -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
f910745a55 docs: add read only data handling to programming rules
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-13 21:18:50 -04:00
Ronald Caesar
99f4afb9fc docs: add handling arrays in programming rules
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-13 20:57:16 -04:00
Ronald Caesar
6e4c1edfda docs: add programming rules
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-13 20:32:41 -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
f89973d49d ir: move translation context to source file
There is no need to expose this struct in the header since it be used in
this module only.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-13 17:34:15 -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
896012c7fc ir: move bounds checking to debug builds
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-12 00:06:26 -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
a214d8fcdb build: bump to v0.3.0
Signed-off-by: Ronald Caesar <github43132@proton.me>
v0.3.0
2026-01-11 01:59:45 -04:00
Ronald Caesar
909d491535 build: add compiler variable length array warning
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-11 01:58:58 -04:00
Ronald Caesar
77d3e7f5cc tools: add coverage cli program
A simple program that prints to stdout the top 20 most common
instructions in an ARM64 binary file.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-11 01:51:53 -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
fbd61680e3 ir: add instruction emitter function
This function only responsibility is writing opcodes and operands to a
bal_instruction_t and adding it to the instruction stream.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-10 17:50:05 -04:00
Ronald Caesar
d663f5faa3 engine: remove poison freed definition
Setting a poison pattern to freed memory isnt a good idea.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-10 14:01:13 -04:00
Ronald Caesar
6cd4440436 engine: add destroy() function
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-10 13:57:38 -04:00
Ronald Caesar
6160510de7 engine: add reset() function
Also added the size of each array to bal_engine_t to make finding the
end of the array in memory simple and easy.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-10 13:33:42 -04:00
Ronald Caesar
a4dde266f0 engine: api add documentation
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-10 10:17:26 -04:00
Ronald Caesar
46c19425cf engine: add engine init function
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-10 02:58:45 -04:00
Ronald Caesar
bc7803569c engine: add ballistic engine struct
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-09 23:54:02 -04:00
Ronald Caesar
50bdb6ba8d memory: Add memory management interface
I want users of Ballistic to design their own memory allocators. Their memory
allocation requirements will most likely be different from ours, so providing
users the API to write their own allocators gives them a lot of freedom
to do whatever they feel is best. This idea was inspired in part by the Zig
programming language.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-09 20:19:44 -04:00
Ronald Caesar
763962567e ir: create initial ballistic types
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-09 19:22:38 -04:00
Ronald Caesar
e9ec38bcfd docs: add template files
These template files come from the Barr C style guide.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-09 18:23:35 -04:00
Ronald Caesar
6cf4df24bf docs: add table of contents
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-09 17:26:45 -04:00
Ronald Caesar
74aa9be671 docs: Update outdated instruction operand width
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-09 17:17:13 -04:00
Ronald Caesar
bf146b681a docs: Add initial static assumption implementation
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 19:53:52 -04:00
Ronald Caesar
2778c94a15 docs: Split ssa_versions[]
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 19:25:26 -04:00
Ronald Caesar
f97fcf7df9 docs: Add scenario to extension instruction
This accidentally got removed in previous commits

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 18:58:01 -04:00
Ronald Caesar
317c33b557 docs: Fix incorrect block limit statement
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 18:54:05 -04:00
Ronald Caesar
8b642a1e9f docs: Add limitations to extention instruction
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 18:50:52 -04:00
Ronald Caesar
624505af17 docs: Switch instruction and instruction encoding sections
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 18:25:05 -04:00
Ronald Caesar
4115204ab9 docs: Shrink instruction_t operands by one
Having 18-bit opcodes means a block has at most 131,072 instructions
which is simply too big. All of these instructions cannot fit into the
L1 cache, which results in cache thrashing.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 18:18:32 -04:00
Ronald Caesar
e7a8a873e6 docs: Replace ssa_version_t type attribute
We have enough bits in the opcode bitfield in instruction_t
to encode register classes (ADD_INT, ADD_FLOAT, ADD_VECTOR). However,
encoding the bit width (ADD_INT8, ADD_INT32) will massively increase the
amount of opcodes needed. So we replace `type` in ssa_version_t with
`bit_width`.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 18:09:07 -04:00
Ronald Caesar
fde3d195bd docs: Replace def extensions with block args
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-08 17:52:25 -04:00
Ronald Caesar
e002fbcc6a docs: Add block size limit rule
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-06 18:37:36 -04:00
Ronald Caesar
020aa8dca8 docs: Fix Hot-Cold Splitting contradiction
Rule 4.2 states: "If a basic block is deemed cold, it should move to a
separate buffer." This violates Rule 3.1 Implicit Indexing. If v100 is
located at instructions[100] and we move it to a cold buffer, it id no
longer at index 100. If we keep the index 100 but store the data
elsewhere, you break the linear memory array performance benefits.

Hot-cols splitting will be done during code generation.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-06 18:18:53 -04:00
Ronald Caesar
cf805cdd86 docs: Fix incorrect block scope comments
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-05 21:45:43 -04:00
Ronald Caesar
ee594332c9 docs: Refactor IR to merge-at-bottom SSA model
- Replace value-returning IFs with Void IFs and explicit OPCODE_MERGE.
- Move SSA definitions to block exits to eliminate backpatching.
- Formalize Control Scope Stack for tracking yields and arity.
- Update loop peeling logic to respect new merge semantics.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-05 21:26:14 -04:00
Ronald Caesar
f314836808 docs: Add IF-to-SELECT optimization pass
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-01-02 20:04:30 -04:00