Skip to content

Refactor machine code fixups and pack code bytes#226

Open
laurenthuberdeau wants to merge 3 commits intomainfrom
refactor-fixups
Open

Refactor machine code fixups and pack code bytes#226
laurenthuberdeau wants to merge 3 commits intomainfrom
refactor-fixups

Conversation

@laurenthuberdeau
Copy link
Copy Markdown
Collaborator

Context

⚠️ This PR was almost entirely written using Gemini CLI. ⚠️

This PR refactors machine code generation to improve memory efficiency and compatibility with fixed-width ISAs.

Changes:

  1. Decoupled Fixups: Moves label and goto fixup metadata out of the machine code buffer into a dedicated, statically allocated fixups buffer.
  2. Code Buffer Packing: Packs 4 machine code bytes into each 32-bit row of the code array. This significantly reduces the number of shell variables required to store the code buffer when running as a shell script.

- Decouple fixup storage from the machine code buffer.
- Introduce a statically allocated 'fixups' buffer.
- Simplify 'push_fixup' by implicitly capturing 'cgc_fs'.
- Add generic accessors for fixup node data.
- Update label and goto resolution logic to use the new buffer.
- Modify 'emit_i8' to pack 4 bytes per 'int' using bitwise operations.
- Update 'generate_exe' in elf.c and mach-o.c to unpack bytes before writing to output.
- Reduce CODE_SIZE and adjust 'code' array declaration to significantly reduce BSS memory usage.
- Update 'emit_i8' bounds check to match the new byte capacity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant