PMunch/futhark

Add opirOutputHook

PMunch opened this issue · 4 comments

PMunch commented

Since #54 is mostly resolved/duplicate I figured it would be better to have this as a separate issue. Basically add a way to hook into the Øpir -> Futhark handover such that the JSON output can be modified before generating Nim code. This would allow full control over what gets generated, and allows modification.

This would be great!

for example I have in place this pipeline before and after Futhark to convert a C++ header file into a C header file, then nim.
Using this hook, I could turn this into a compile time thing instead of nimscript in nimble file

Pre Futhark:

check with: gcc -fsyntax-only myfile.h

0) add bools (check bool ABI!)
#include <stdbool.h>

1) remove extern "C" function prefix

2) remove default arguments
([a-zA-Z0-9_*]+\s[a-zA-Z0-9_*]+)(\s?=\s?[a-zA-Z0-9_]+) -> $1

3) typedef enums/structs

Post Futhark

4) fix procs starting with capital letter
proc ([A-Z]) -> proc \L$1

5) fix deprecated cuchar -> pick char or uint8 or byte
cuchar -> uint8

PROFIT!

PMunch commented

It should help with 4 and 5, but not sure if it would be able to do anything about 0-3 as those happen before the Øpir tool reads the C header and turns it into the JSON specification. I do wish to make Futhark C++ compatible in the long run, but since it has a much more complicated set of features this is going to require quite a bit of work.

sure thing. I pasted the whole story as I wanted to display larger picture (and I had it in clipboard :P)

the intended usage of the hook is obviously post opir/futhark

PMunch commented

This is added in e63584a and documented here: https://github.com/PMunch/futhark#deeper-control