two pass encoding and resizing references #22

Merged
omicron merged 6 commits from encoding_start into main 2025-04-24 13:05:47 +00:00
Owner

Implements a two pass encoding

First pass:

  • Run through the AST and collect information:
    • Set register values
    • Parse/set number values
    • Mark all instructions that use label references
  • Encode all instructions that don't use label references
  • Update addresses of all labels and instructions. Use an estimated
    instruction size for those instructions that use label references.

Second pass:

  • Run through the AST for all instructions that use label references and
    collect size information using the estimated addresses from pass 1
  • Encode label references with the estimated addresses, this fixes their
    size.
  • Update all addresses

Iteration: Repeat the second pass until addresses converge

This fixes #14

Implements a two pass encoding First pass: - Run through the AST and collect information: - Set register values - Parse/set number values - Mark all instructions that use label references - Encode all instructions that don't use label references - Update addresses of all labels and instructions. Use an estimated instruction size for those instructions that use label references. Second pass: - Run through the AST for all instructions that use label references and collect size information using the estimated addresses from pass 1 - Encode label references with the estimated addresses, this fixes their size. - Update all addresses Iteration: Repeat the second pass until addresses converge This fixes #14
omicron added 6 commits 2025-04-24 13:04:24 +00:00
Fix parse_memory_expression to use parse_label_reference
All checks were successful
Validate the build / validate-build (push) Successful in 37s
530e3fb423
Before it kept track of a more specific node that referenced the symbol
in some way. Now it will only keep track of the actual label defining
statements. This is done to facilitate encoding. The encoder can now go
from a symbol name to the statement that defines the symbol.

Restructure the encoder to deal with this and pass the correct statement
to the symbol update function.
- Add a instruction value that contains the encoding, the address and a
  flag to indicate if this instruction contains label references
- Add label value that contains an address
- Add reference value that contains offset, an absolute address and an
  operand size
- define types for all value options in the union
- define accessor functions for all the values in the union
First pass:
 - collect information for numbers, registers and which instructions
   contain label references
 - encode all instructions that don't contain label references
 - Set (temporary) addresses for each instruction

Second pass:
 - Collect information about label references (address, offset, size)
 - encode all instructions that contain label references
 - Update (if necessary) addresses for each instruction

 The second pass is iterated 10 times or until no instructions change
 size, whichever comes first.
Implement one immediate label reference operand
All checks were successful
Validate the build / validate-build (push) Successful in 43s
7cefc3564d
Also adds opcode data for jmp and call
omicron merged commit 7cefc3564d into main 2025-04-24 13:05:47 +00:00
omicron deleted branch encoding_start 2025-04-24 13:05:47 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: omicron/oas#22
No description provided.