stage4/generate_c/generate_c.cc
changeset 1062 814acf353c69
parent 1061 f762b43c8fad
child 1064 1ac77681946f
equal deleted inserted replaced
1061:f762b43c8fad 1062:814acf353c69
  2196 
  2196 
  2197 /* generate the backup/restore function for a CONFIGURATION */
  2197 /* generate the backup/restore function for a CONFIGURATION */
  2198 /* the generated function will backup/restore the global variables declared in the
  2198 /* the generated function will backup/restore the global variables declared in the
  2199  * configuration, and call the backup/restore functions of each embedded resource to do
  2199  * configuration, and call the backup/restore functions of each embedded resource to do
  2200  * the same for the global variables declared inside each resource.
  2200  * the same for the global variables declared inside each resource.
       
  2201  *
       
  2202  *   The matiec compiler will now generate two additional functions which 
       
  2203  *   will backup and restore the PLC internal state to a void *buffer.
       
  2204  *       config_backup__(void **buffer, int *maxsize)
       
  2205  *       config_restore__(void **buffer, int *maxsize)
       
  2206  *
       
  2207  *   Both functions will backup/restore the internal state from the memory 
       
  2208  *   pointed to by *buffer, up to a maximum of *maxsize bytes.
       
  2209  *   Both functions will return with buffer pointing to the first unused 
       
  2210  *   byte in the buffer, and maxsize with the number of remaining bytes. If 
       
  2211  *   the buffer is not sufficient to store all the internal state, maxsize 
       
  2212  *   will return with a negative number, equal to the number of missing 
       
  2213  *   bytes.
       
  2214  *
       
  2215  *   In other words, to know the exact size of the buffer required to store 
       
  2216  *   the PLC internal state, malloc() that memory, and do the backup:
       
  2217  *          int maxsize = 0;
       
  2218  *          config_backup__(NULL, &maxsize);
       
  2219  *          void *buffer = malloc(-1 * maxsize);
       
  2220  *          // and now to really back the internal state...
       
  2221  *          config_backup__(&buffer, &maxsize);
  2201  */
  2222  */
  2202 class generate_c_backup_config_c: public generate_c_base_and_typeid_c {
  2223 class generate_c_backup_config_c: public generate_c_base_and_typeid_c {
  2203   private:
  2224   private:
  2204     const char *func_to_call; // parameter to pass data from: void *visit(configuration_declaration_c *)
  2225     const char *func_to_call; // parameter to pass data from: void *visit(configuration_declaration_c *)
  2205                               //                          to: void *visit(resource_declaration_c *)
  2226                               //                          to: void *visit(resource_declaration_c *)