Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ProgramBlobBuilder to accept instruction offsets in jump args #173

Open
koute opened this issue Sep 24, 2024 · 0 comments
Open
Labels
D-easy An easy issue that might be good for someone new P-low Low priority

Comments

@koute
Copy link
Collaborator

koute commented Sep 24, 2024

Background

Historically we've encoded jumps as having an index of the target basic block as its argument. Later we've redesigned it so that now jumps are encoded with a relative byte offset to where they're supposed to jump (so that we don't require an O(n) pass before execution). However, the ProgramBlobBuilder still works the same as it did, for example:

builder.set_code(&[
    // 0th basic block starts here.
    asm::add_imm(A0, A0, 100), 
    asm::trap(),
    // 1st basic block starts here.
    asm::add_imm(A0, A0, 200), 
    asm::jump(1)
], &[]);

Here the jump(1) means that it will jump to the add_imm(A0, A0, 200) instruction (yes, it will be an infinite loop).

The task

Refactor the builder so that it accepts an absolute instruction number instead of a basic block number (we can't have it accept byte offsets or relative byte offsets since our instructions are variable length, so if it accepted byte offsets it'd make it literally impossible to use).

So the example that I've given should now look like this (it should still produce exactly the same code, but now jump accepts the index of the target instruction instead of the index of the target basic block):

builder.set_code(&[
    asm::add_imm(A0, A0, 100), // 0th instruction
    asm::trap(), // 1th instruction
    asm::add_imm(A0, A0, 200), // 2th instruction
    asm::jump(2) 
], &[]);
@koute koute added P-low Low priority D-easy An easy issue that might be good for someone new labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-easy An easy issue that might be good for someone new P-low Low priority
Projects
None yet
Development

No branches or pull requests

1 participant