From 4b05e3072919cfc1bbb1cf0540b5718cd649a30b Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 23 Jun 2016 22:09:59 -0400 Subject: [PATCH] compiler: add hooks for before and at the begin of the C `main` Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index e9eacef..cddc8d3 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -779,6 +779,20 @@ extern void nitni_global_ref_decr( struct nitni_ref *ref ); v.add "\}" end + # Hook to add specif piece of code before the the main C function. + # + # Is called by `compile_main_function` + fun compile_before_main(v: VISITOR) + do + end + + # Hook to add specif piece of code at the begin on the main C function. + # + # Is called by `compile_main_function` + fun compile_begin_main(v: VISITOR) + do + end + # Generate the main C function. # # This function: @@ -876,12 +890,16 @@ extern void nitni_global_ref_decr( struct nitni_ref *ref ); v.add_decl("exit(status);") v.add_decl("\}") + compile_before_main(v) + if no_main then v.add_decl("int nit_main(int argc, char** argv) \{") else v.add_decl("int main(int argc, char** argv) \{") end + compile_begin_main(v) + v.add "#if !defined(__ANDROID__) && !defined(TARGET_OS_IPHONE)" v.add("signal(SIGABRT, sig_handler);") v.add("signal(SIGFPE, sig_handler);") -- 1.7.9.5