Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further simplification of the popping in simix
[simgrid.git] / src / simix / simcalls.py
index ccaa840..4e8963f 100755 (executable)
@@ -105,36 +105,32 @@ class Simcall(object):
 
   def string(self):
     return '[SIMCALL_%s] = "SIMCALL_%s",'%(self.name.upper(), self.name.upper())       
-  
-  def result_getter_setter(self):
-    return '%s\n%s'%(self.result_getter(), self.result_setter())
-  
-  def result_getter(self):
-    return '' if self.res.type == 'void' else '''static inline %s simcall_%s__get__result(smx_simcall_t simcall){
-  return %s simcall->result.%s;
-}'''%(self.res.ret(), self.name, self.res.cast(), self.res.field())
-
-  def result_setter(self):
-    return '' if self.res.type == 'void' else '''static inline void simcall_%s__set__result(smx_simcall_t simcall, %s result){
-    simcall->result.%s = result;
-}'''%(self.name, self.res.type, self.res.field())
 
-  def args_getter_setter(self):
+  def accessors(self):
     res = []
     for i in range(len(self.args)):
       res.append(self.arg_getter(i))
       res.append(self.arg_setter(i))
+    if self.res.type != 'void':
+        res.append('static inline %s simcall_%s__get__result(smx_simcall_t simcall){'%(self.res.ret(), self.name))
+        res.append('    return %s simcall->result.%s;'%(self.res.cast(), self.res.field()))
+        res.append('}')
+        res.append('static inline void simcall_%s__set__result(smx_simcall_t simcall, %s result){'%(self.name, self.res.type,))
+        res.append('    simcall->result.%s = result;'%(self.res.field()))
+        res.append('}')
     return '\n'.join(res)
 
   def arg_getter(self, i):
     arg = self.args[i]
-    return '''static inline %s simcall_%s__get__%s(smx_simcall_t simcall){
+    return '''
+static inline %s simcall_%s__get__%s(smx_simcall_t simcall){
   return %s simcall->args[%i].%s;
 }'''%(arg.ret(), self.name, arg.name, arg.cast(), i, arg.field())
 
   def arg_setter(self, i):
     arg = self.args[i]
-    return '''static inline void simcall_%s__set__%s(smx_simcall_t simcall, %s arg){
+    return '''
+static inline void simcall_%s__set__%s(smx_simcall_t simcall, %s arg){
     simcall->args[%i].%s = arg;
 }'''%(self.name, arg.name, arg.type, i, arg.field())
 
@@ -206,7 +202,7 @@ def parse(fn):
 
 def header(fd):
     fd.write('/**********************************************************************/\n')
-    fd.write('/* File Generated by src/simix/simcalls.py from src/simix/simcalls.in */\n')
+    fd.write('/* File generated by src/simix/simcalls.py from src/simix/simcalls.in */\n')
     fd.write('/*                                                                    */\n')
     fd.write('/*                    DO NOT EVER CHANGE THIS FILE                    */\n')
     fd.write('/*                                                                    */\n')
@@ -241,22 +237,36 @@ if __name__=='__main__':
   #  print ("Some checks fail!")
   #  sys.exit(1)
 
-  write('simcalls_generated_enum.h', Simcall.enum, simcalls, simcalls_dict,"""
+  write('smx_popping_accessors.h', Simcall.accessors, simcalls, simcalls_dict)
+  
+  
+  fd = open("smx_popping_enum.h", 'w')
+  header(fd)
+  fd.write("""
+/*
+ * Note that the name comes from http://en.wikipedia.org/wiki/Popping 
+ * Indeed, the control flow is doing a strange dance in there.
+ *
+ * That\'s not about http://en.wikipedia.org/wiki/Poop, despite the odor :)
+ */
+
 /**
  * @brief All possible simcalls.
  */
 typedef enum {
 SIMCALL_NONE,
-  ""","""
-SIMCALL_NEW_API_INIT,
-NUM_SIMCALLS
-} e_smx_simcall_t;
   """)
   
-  write('simcalls_generated_res_getter_setter.h', Simcall.result_getter_setter, simcalls, simcalls_dict)
-  write('simcalls_generated_args_getter_setter.h', Simcall.args_getter_setter, simcalls, simcalls_dict)
+  handle(fd, Simcall.enum, simcalls, simcalls_dict)
   
+  fd.write("""
+NUM_SIMCALLS
+} e_smx_simcall_t;
+  """)
+
   
+  fd.close()
+
   
   fd = open("smx_popping_generated.c", 'w')
   header(fd)
@@ -306,15 +316,9 @@ NUM_SIMCALLS
   fd.write('          );\n');
   fd.write('      break;\n');
   fd.write('\n');
-  fd.write('    /* ****************************************************************************************** */\n');
-  fd.write('    /* TUTORIAL: New API                                                                        */\n');
-  fd.write('    /* ****************************************************************************************** */\n');
-  fd.write('    case SIMCALL_NEW_API_INIT:\n');
-  fd.write('      SIMIX_pre_new_api_fct(simcall);\n');
-  fd.write('      break;\n');
   fd.write('  }\n');
   fd.write('}\n');
   
   fd.close()
   
-  write('simcalls_generated_body.c', Simcall.body, simcalls, simcalls_dict)
+  write('smx_popping_bodies.c', Simcall.body, simcalls, simcalls_dict)