Move the sbrk profiling code into the mercury_main() function.

The mercury_main() function is used in both standalone and library builds of
Mercury code.  However the main function where the code was was only used in
standalone programs.  The Mercury compiler is built as a library and
usually liked with main.c in the root directory, this is done so that it can
be used with GCC for the GCC backend.  I have moved the sbrk profiling code
into mercury_main so that it will be executed by the compiler.  I used this
to generate memory usage information in my thesis.

util/mkinit.c:
    As above.
This commit is contained in:
Paul Bone
2012-11-11 01:42:00 +00:00
parent 28c66f3358
commit 428d5a1cc2

View File

@@ -527,6 +527,14 @@ static const char mercury_main_func[] =
"int\n"
"mercury_main(int argc, char **argv)\n"
"{\n"
"#ifdef MR_PROFILE_SBRK\n"
" void* old_break;\n"
" void* new_break;\n"
"#endif\n"
" int result;\n"
"#ifdef MR_PROFILE_SBRK\n"
" old_break = sbrk(0);\n"
"#endif\n"
/*
** Note that the address we use for the stack base
** needs to be word-aligned (the MPS GC requires this).
@@ -536,7 +544,13 @@ static const char mercury_main_func[] =
" void *dummy;\n"
" mercury_init(argc, argv, &dummy);\n"
" mercury_call_main();\n"
" return mercury_terminate();\n"
" result = mercury_terminate();\n"
"#ifdef MR_PROFILE_SBRK\n"
" new_break = sbrk(0);\n"
" printf(\"sbrk delta: %d\\n\",\n"
" (MR_Integer)new_break - (MR_Integer)old_break);\n"
"#endif\n"
" return result;\n"
"}\n"
"\n"
/*
@@ -617,24 +631,10 @@ static const char main_func[] =
"int\n"
"main(int argc, char **argv)\n"
"{\n"
"#ifdef MR_PROFILE_SBRK\n"
" void* old_break;\n"
" void* new_break;\n"
"#endif\n"
" int result;\n"
"#ifdef MR_PROFILE_SBRK\n"
" old_break = sbrk(0);\n"
"#endif\n"
"#ifdef MR_MINGW\n"
" mercury_win32_args(&argc, &argv);\n"
"#endif\n"
" result = mercury_main(argc, argv);\n"
"#ifdef MR_PROFILE_SBRK\n"
" new_break = sbrk(0);\n"
" printf(\"sbrk delta: %d\\n\",\n"
" (MR_Integer)new_break - (MR_Integer)old_break);\n"
"#endif\n"
" return result;\n"
" return mercury_main(argc, argv);\n"
"}\n"
"#endif\n"
;