0xMiden/compiler

Implement support for indirect calls via dynexec/procref

Open

#32 ouverte le 16 oct. 2023

Voir sur GitHub
 (3 commentaires) (0 réactions) (0 assignés)Rust (70 forks)github user discovery
codegengood first issue

Métriques du dépôt

Stars
 (110 stars)
Métriques de merge PR
 (Métriques PR en attente)

Description

Now that 0xPolygonMiden/miden-vm#1078 is merged (which introduces dynexec), the groundwork for supporting indirect calls in Miden Assembly is there. Before we can make use of it though, we need the proposed procref instruction, which would push the hash of a specified function name on the stack. This is done prior to dynexec, which requires that hash in order to execute the indirect call. We need procref because we don't know the hash of the function until after compilation, which procref solves by relying on the Miden assembler to expand it into push.HASH as it knows the hashes of all the functions.

Once that is implemented, we can make use of it to implement indirect calls in the IR:

### Tasks
- [ ] Add a new `call.indirect` opcode, to be paired with the `PrimOp` instruction type
- [ ] Add a new `Type` variant, `Type::Function(Box<FunctionType>)` which will be used in conjunction with `Type::Ptr` to represent function pointers
- [ ] Add a new data segment to `Program` which represents every function in the compiled program as a table of hashes. Initialize this table at runtime using `procref`
- [ ] https://github.com/0xPolygonMiden/compiler/issues/133
- [ ] Lower indirect calls to MASM by treating the function pointer operand as an index into the function table, load the callee hash, and then dispatch via `dynexec`. Indexing beyond the bounds of the table should trap.

Guide contributeur