Open elix22 opened 1 year ago
Thank you for reporting this. m2c
is not a part of the last binary release installation but it should have worked.
I'll fix it on this week.
I've just fixed it.
Great , thanks .
I think MIR is a great piece of software and has a lot of potential
I noticed that the generated c (from MIR) contains
extern char printf[];
I am removing it in order to pass compilation
Commented
// fprintf (f, "extern char %s[];\n", item->u.import_id);
I also modified below to pass compilation fprintf (f, "#include <stdio.h>\n");
void MIR_module2c (MIR_context_t ctx, FILE *f, MIR_module_t m) {
fprintf (f, "#include <stdint.h>\n");
fprintf (f, "#include <stdio.h>\n");
for (MIR_item_t item = DLIST_HEAD (MIR_item_t, m->items); item != NULL;
item = DLIST_NEXT (MIR_item_t, item))
out_item (ctx, f, item);
}
Great , thanks . I think MIR is a great piece of software and has a lot of potential I noticed that the generated c (from MIR) contains
extern char printf[];
Thank you for the kind words.
MIR has no information about external symbols (is it function or global variable?). It has only an import symbol
(import printf
in this case). So I use this trick. It should work at least with GCC although a warning might be generated.
On my Mac it is considered an error , but personally I am ok with my workaround.
gcc fib_mir_genereated.c -o fib_mir_genereated
fib_mir_genereated.c:5:13: error: redefinition of 'printf' as different kind of symbol
extern char printf[];
I tried the same procedure on c-benchmarks/sieve.c
Getting an error
./m2c sieve.mir > sieve_mir_genereated.c wrong length for MIR_var_tAssertion failed: (0), function mir_varr_assert_fail, file mir-varr.h, line 26. Abort trap: 6
I fixed this. Unfortunately mir-2-c compiler is in a bad shape. A lot of new MIR constructions is not implemented and some features are not easy to implement, including multiple results funcs and BLK types used to pass args according some target specific ABIs. For example, on x86-64 struct of int and double is passed in regs and for this a MIR BLK type is used.
So translation to MIR should be target specific. I should think what to do with m2c
. I am inclining to remove this because I don't see where it could be useful.
Thanks for your fixes . I am not an expert in JIT/AOT compilers but was always fascinated by this subject My Idea was to use it for a small .NET runtime DotNetAnywhere I have played with it in the past and also did some P.O.C running it on top of SDL , working on mobiles SDL-DNA The idea is to implement the following : Translate CIL -> MIR -> JIT (PC) Translate CIL -> MIR -> C (on Mobile devices)
Basically to follow the same functionality that is done for HAXE , with the Hashlink runtime On PC it is a JIT compiler For Mobiles it is compiled to C (HL/C) Also Played with it in the past made some working P.O.C , using it in a Game engine
These are all side pet projects , I like to play and experiment with this stuff. I didn't dig too deep into MIR , so I don't know if MIR is suitable for that task So I might be wrong in my assumptions . You thoughts would be appreciated
Thanks
I have compiled mir2c.c as a standalone executable (m2c , defined(MIR2C) )
trying to convert a simple Fibonacci (mir <-> c),
Getting an error
fib.c
fib.mir
fib_mir_genereated.c