Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make smx_popping_bodies.c parsable by eclipse (kinda)
[simgrid.git] / src / simix / simcalls.py
index 7781eb3..7ebab19 100755 (executable)
@@ -101,40 +101,36 @@ class Simcall(object):
     return True
 
   def enum(self):
-    return 'SIMCALL_%s,'%(self.name.upper())
+    return '  SIMCALL_%s,'%(self.name.upper())
 
   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())
 
@@ -204,7 +200,8 @@ def parse(fn):
       resdi.append(sim)
   return simcalls, simcalls_guarded
 
-def header(fd):
+def header(name):
+    fd = open(name, 'w')
     fd.write('/**********************************************************************/\n')
     fd.write('/* File generated by src/simix/simcalls.py from src/simix/simcalls.in */\n')
     fd.write('/*                                                                    */\n')
@@ -212,6 +209,13 @@ def header(fd):
     fd.write('/*                                                                    */\n')
     fd.write('/* change simcalls specification in src/simix/simcalls.in             */\n')  
     fd.write('/**********************************************************************/\n\n')
+    fd.write('/*\n')
+    fd.write(' * Note that the name comes from http://en.wikipedia.org/wiki/Popping\n') 
+    fd.write(' * Indeed, the control flow is doing a strange dance in there.\n')
+    fd.write(' *\n')
+    fd.write(' * That\'s not about http://en.wikipedia.org/wiki/Poop, despite the odor :)\n')
+    fd.write(' */\n\n')
+    return fd
 
 def handle(fd,func, simcalls, guarded_simcalls):
     fd.write('\n'.join(func(simcall) for simcall in simcalls))
@@ -220,14 +224,6 @@ def handle(fd,func, simcalls, guarded_simcalls):
         fd.write('\n'.join(func(simcall) for simcall in list))
         fd.write('\n#endif\n')
 
-def write(fn, func, simcalls, scd,pre="",post=""):
-    fd = open(fn, 'w')
-    header(fd)
-    fd.write(pre)
-    handle(fd, func, simcalls, scd)
-    fd.write(post)
-    fd.close()
-
 if __name__=='__main__':
   import sys
   simcalls, simcalls_dict = parse('simcalls.in')
@@ -241,46 +237,34 @@ if __name__=='__main__':
   #  print ("Some checks fail!")
   #  sys.exit(1)
 
-  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)
-  
-  
-  fd = open("smx_popping_generated.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,
-  """)
+  ###
+  ### smx_popping_accessors.c
+  ###
+  fd = header('smx_popping_accessors.h')
+  handle(fd, Simcall.accessors, simcalls, simcalls_dict)
+  fd.close()
+
+  ###
+  ### smx_popping_enum.c
+  ###
+  fd = header("smx_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
-} e_smx_simcall_t;
-  """)
-
-  
+  fd.write('  NUM_SIMCALLS\n')
+  fd.write('} e_smx_simcall_t;\n')
   fd.close()
 
+  ###
+  ### smx_popping_generated.c
+  ###
   
-  fd = open("smx_popping_generated.c", 'w')
-  header(fd)
-  fd.write('/*\n')
-  fd.write(' * Note that the name comes from http://en.wikipedia.org/wiki/Popping \n')
-  fd.write(' * Indeed, the control flow is doing a strange dance in there.\n')
-  fd.write(' *\n')
-  fd.write(' * That\'s not about http://en.wikipedia.org/wiki/Poop, despite the odor :)\n')
-  fd.write(' */\n\n')
+  fd = header("smx_popping_generated.c")
   
   fd.write('#include "smx_private.h"\n');
   fd.write('#ifdef HAVE_MC\n');
@@ -326,4 +310,12 @@ NUM_SIMCALLS
   
   fd.close()
   
-  write('simcalls_generated_body.c', Simcall.body, simcalls, simcalls_dict)
+  ###
+  ### smx_popping_bodies.c
+  ###
+  fd = header('smx_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()