-if __name__=='__main__':
- import sys
- simcalls, simcalls_dict = parse('simcalls.in')
-
- ok = True
- ok &= all(map(Simcall.check, simcalls))
- for k,v in simcalls_dict.items():
- ok &= all(map(Simcall.check, v))
- # FIXME: we should not hide it
- #if not ok:
- # print ("Some checks fail!")
- # sys.exit(1)
-
- ###
- ### smx_popping_accessors.c
- ###
- fd = header('popping_accessors.h')
- handle(fd, Simcall.accessors, simcalls, simcalls_dict)
- fd.write("\n\n/* The prototype of all simcall handlers, automatically generated for you */\n\n")
- handle(fd, Simcall.handler_prototype, simcalls, simcalls_dict)
- fd.close()
-
- ###
- ### smx_popping_enum.c
- ###
- fd = header("popping_enum.h")
- fd.write('/**\n')
- fd.write(' * @brief All possible simcalls.\n')
- fd.write(' */\n')
- fd.write('typedef enum {\n')
- fd.write(' SIMCALL_NONE,\n')
-
- handle(fd, Simcall.enum, simcalls, simcalls_dict)
-
- fd.write(' NUM_SIMCALLS\n')
- fd.write('} e_smx_simcall_t;\n')
- fd.close()
-
- ###
- ### smx_popping_generated.c
- ###
-
- fd = header("popping_generated.c")
-
- fd.write('#include "smx_private.h"\n');
- fd.write('#ifdef HAVE_MC\n');
- fd.write('#include "mc/mc_private.h"\n');
- fd.write('#endif\n');
- fd.write('\n');
- fd.write('XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_popping);\n\n');
-
- fd.write('/** @brief Simcalls\' names (generated from src/simix/simcalls.in) */\n')
- fd.write('const char* simcall_names[] = {\n')
-
- handle(fd, Simcall.string, simcalls, simcalls_dict)
-
- fd.write('[SIMCALL_NONE] = "NONE"\n')
- fd.write('};\n\n')
-
-
- fd.write('/**\n');
- fd.write(' * @brief (in kernel mode) unpack the simcall and activate the handler\n');
- fd.write(' * \n')
- fd.write(' * This function is generated from src/simix/simcalls.in\n')
- fd.write(' */\n');
- fd.write('void SIMIX_simcall_handle(smx_simcall_t simcall, int value) {\n');
- fd.write(' XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));\n');
- fd.write(' SIMCALL_SET_MC_VALUE(simcall, value);\n');
- fd.write(' if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP)\n');
- fd.write(' return;\n');
- fd.write(' switch (simcall->call) {\n');
-
- handle(fd, Simcall.case, simcalls, simcalls_dict)
-
- fd.write(' case NUM_SIMCALLS:\n');
- fd.write(' break;\n');
- fd.write(' case SIMCALL_NONE:\n');
- fd.write(' THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",\n');
- fd.write(' SIMIX_process_get_name(simcall->issuer),\n');
- fd.write(' SIMIX_host_get_name(SIMIX_process_get_host(simcall->issuer))\n');
- fd.write(' );\n');
- fd.write(' break;\n');
- fd.write('\n');
- fd.write(' }\n');
- fd.write('}\n');
-
- fd.close()
-
- ###
- ### smx_popping_bodies.c
- ###
- fd = header('popping_bodies.c')
- fd.write('#include "smx_private.h"\n')
- fd.write('#include "mc/mc_interface.h"\n')
- fd.write('#include "xbt/ex.h"\n')
- handle(fd, Simcall.body, simcalls, simcalls_dict)
- fd.close()
+if __name__ == '__main__':
+ import sys
+ simcalls, simcalls_dict = parse('simcalls.in')
+
+ ok = True
+ ok &= all(map(Simcall.check, simcalls))
+ for k, v in simcalls_dict.items():
+ ok &= all(map(Simcall.check, v))
+ # FIXME: we should not hide it
+ # if not ok:
+ # print ("Some checks fail!")
+ # sys.exit(1)
+
+ #
+ # smx_popping_accessors.c
+ #
+ fd = header('popping_accessors.h')
+ fd.write('#include "src/simix/popping_private.h"');
+ handle(fd, Simcall.accessors, simcalls, simcalls_dict)
+ fd.write(
+ "\n\n/* The prototype of all simcall handlers, automatically generated for you */\n\n")
+ handle(fd, Simcall.handler_prototype, simcalls, simcalls_dict)
+ fd.close()
+
+ #
+ # smx_popping_enum.c
+ #
+ fd = header("popping_enum.h")
+ fd.write('/**\n')
+ fd.write(' * @brief All possible simcalls.\n')
+ fd.write(' */\n')
+ fd.write('typedef enum {\n')
+ fd.write(' SIMCALL_NONE,\n')
+
+ handle(fd, Simcall.enum, simcalls, simcalls_dict)
+
+ fd.write(' NUM_SIMCALLS\n')
+ fd.write('} e_smx_simcall_t;\n')
+ fd.close()
+
+ #
+ # smx_popping_generated.cpp
+ #
+
+ fd = header("popping_generated.cpp")
+
+ fd.write('#include <xbt/base.h>\n')
+ fd.write('#include "smx_private.h"\n')
+ fd.write('#if HAVE_MC\n')
+ fd.write('#include "src/mc/mc_forward.hpp"\n')
+ fd.write('#endif\n')
+ fd.write('\n')
+ fd.write('XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_popping);\n\n')
+
+ fd.write(
+ '/** @brief Simcalls\' names (generated from src/simix/simcalls.in) */\n')
+ fd.write('const char* simcall_names[] = {\n')
+
+ fd.write(' "SIMCALL_NONE",')
+ handle(fd, Simcall.string, simcalls, simcalls_dict)
+
+ fd.write('};\n\n')
+
+ fd.write('/** @private\n')
+ fd.write(
+ ' * @brief (in kernel mode) unpack the simcall and activate the handler\n')
+ fd.write(' * \n')
+ fd.write(' * This function is generated from src/simix/simcalls.in\n')
+ fd.write(' */\n')
+ fd.write(
+ 'void SIMIX_simcall_handle(smx_simcall_t simcall, int value) {\n')
+ fd.write(
+ ' XBT_DEBUG("Handling simcall %p: %s", simcall, SIMIX_simcall_name(simcall->call));\n')
+ fd.write(' SIMCALL_SET_MC_VALUE(simcall, value);\n')
+ fd.write(
+ ' if (simcall->issuer->context->iwannadie && simcall->call != SIMCALL_PROCESS_CLEANUP)\n')
+ fd.write(' return;\n')
+ fd.write(' switch (simcall->call) {\n')
+
+ handle(fd, Simcall.case, simcalls, simcalls_dict)
+
+ fd.write(' case NUM_SIMCALLS:\n')
+ fd.write(' break;\n')
+ fd.write(' case SIMCALL_NONE:\n')
+ fd.write(' THROWF(arg_error,0,"Asked to do the noop syscall on %s@%s",\n')
+ fd.write(' simcall->issuer->name.c_str(),\n')
+ fd.write(' sg_host_get_name(simcall->issuer->host)\n')
+ fd.write(' );\n')
+ fd.write(' break;\n')
+ fd.write('\n')
+ fd.write(' }\n')
+ fd.write('}\n')
+
+ fd.close()
+
+ #
+ # smx_popping_bodies.cpp
+ #
+ fd = header('popping_bodies.cpp')
+ fd.write('#include <functional>\n')
+ fd.write('#include "smx_private.h"\n')
+ fd.write('#include "src/mc/mc_forward.hpp"\n')
+ fd.write('#include "xbt/ex.h"\n')
+ fd.write('#include <simgrid/simix.hpp>\n')
+ fd.write("/** @cond */ // Please Doxygen, don't look at this\n")
+ fd.write('''
+template<class R, class... T>
+inline static R simcall(e_smx_simcall_t call, T const&... t)
+{
+ smx_actor_t self = SIMIX_process_self();
+ simgrid::simix::marshal(&self->simcall, call, t...);
+ if (self != simix_global->maestro_process) {
+ XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name.c_str(),
+ SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call);
+ SIMIX_process_yield(self);
+ } else {
+ SIMIX_simcall_handle(&self->simcall, 0);
+ }
+ return simgrid::simix::unmarshal<R>(self->simcall.result);
+}
+''')
+ handle(fd, Simcall.body, simcalls, simcalls_dict)
+ fd.write("/** @endcond */\n");
+ fd.close()