powdr-labs / powdr

A modular stack for zkVMs, with a focus on productivity, security and performance.
Apache License 2.0
408 stars 81 forks source link

Allow specifying the entry point outside the main machine #579

Open Schaeff opened 1 year ago

Schaeff commented 1 year ago

This was requested by users, the monolithic way in which we generate the RiscV machine is a bit odd.

Our riscv implementation looks like

machine RiscV {
   // implementation of riscv architecture
   instr ...
   instr ...
   constraints ...

   // entry point
   fn main {
      // transpiled assembly
   }
}

This is awkward because we want to be able to define the hardware once and use it many times. For this, let's allow:

machine RiscV {
   // only the implementation
}

#[entry_point(RiscV)]
function main {

}

When compiling:

This could also just be treated as some kind of macro, so that the rest of the system doesn't need to change at all.

Along with the import system, it enables:

#[entry_point(std::architectures::RiscV)]
function main {

}

Alternatives:

The general rationale for this change is that the entry point is a special case, and this kind of main injection would not be used anywhere else, so implementing it as a special case makes more sense than introducing concepts which would affect the whole system.

cc @georgwiese

leonardoalt commented 8 months ago

This would be cool.