fwsGonzo / libriscv

The fastest RISC-V sandbox
BSD 3-Clause "New" or "Revised" License
522 stars 46 forks source link

Allow translating RISC-V to embeddable source code #145

Closed fwsGonzo closed 5 days ago

fwsGonzo commented 4 weeks ago

The binary translator outputs a code file that is usually delivered to a compiler in order to produce a shared object. However, it can also be used directly in the codebase to accelerate the sandboxed program. The only change is that we need to run setup code to activate this.

Then, the file needs to be added to your project as a normal C or C++ code file, and the setup function needs to be invoked at the right time. So, Machine probably needs a constructor option in order for this to work. Or maybe not. Construct the Machine first and then call setup? It could work.

Why? Because many platforms don't let you change or modify executable segments at all. You can only load a vetted binary that is your shipped product. So, your choices are interpreted or fully embed the sandbox program as safe code. Having the option is nice, but since I doubt I will use this feature, I don't know if or when I will get to it. But it's a nice thought.

There are plenty of games out there that don't use any fancy scripting at all, just plain Lua, for example. One example recently had 60k lines of Lua script in his shipped game.

fwsGonzo commented 5 days ago

Implemented with https://github.com/fwsGonzo/libriscv/pull/174