COD (C-On-Demand) Dynamic Code Generation
cod.h
Go to the documentation of this file.
00001 #ifndef __COD__H__
00002 #define __COD__H__
00003 
00005 #if defined(__cplusplus) || defined(c_plusplus)
00006 extern "C" {
00007 #endif
00008 
00009 #if defined(FUNCPROTO) || defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
00010 #ifndef ARGS
00011 #define ARGS(args) args
00012 #endif
00013 #else
00014 #ifndef ARGS
00015 #define ARGS(args) (/*args*/)
00016 #endif
00017 #endif
00018 
00019 
00028 typedef struct parse_struct *cod_parse_context;
00029 
00039 typedef struct cod_exec_struct *cod_exec_context;
00040 
00045 typedef struct sm_struct *sm_ref;
00046 
00047 #ifndef FMOffset
00048 #define FMOffset(p_type,field) \
00049         ((int) (((char *) (&(((p_type)0)->field))) - ((char *) 0)))
00050 #if defined(__STDC__) || defined(__ANSI_CPP__) || defined(_MSC_VER)
00051 #define FMstr(s) #s
00052 #else
00053 #define FMstr(s) "s"
00054 #endif
00055 #define FMArrayDecl(type, size) FMstr(type[size])
00056 #define FMArrayDecl2(type, size, size2) FMstr(type[size][size2])
00057 
00058 #define FMDefaultDecl(name, val) FMstr(name(val))
00059 
00060 typedef struct _FMField {
00061     const char *field_name;     /* Field name */
00062     const char *field_type;     /* Representation type desired */
00063     int field_size;             /* Size in bytes of representation */
00064     int field_offset;           /* Offset from base to put field value */
00065 } FMField, *FMFieldList;
00066 
00067 typedef struct _FMOptInfo {
00068     int info_type;
00069     int info_len;
00070     char *info_block;
00071 } FMOptInfo;
00072 
00080 typedef struct _FMformat_list {
00082     char *format_name;
00084     FMFieldList field_list;
00085     int struct_size;
00086     FMOptInfo *opt_info;
00087 }FMStructDescRec, *FMStructDescList;
00088 #endif
00089 
00095 typedef struct extern_entry {
00097     char *extern_name;
00099     void *extern_value;
00100 } cod_extern_entry;
00101 
00106 typedef cod_extern_entry *cod_extern_list;
00107 
00116 extern cod_parse_context new_cod_parse_context(void);
00117 
00125 extern void cod_free_parse_context ARGS((cod_parse_context context));
00126 
00139 extern void cod_assoc_externs ARGS((cod_parse_context context,
00140                                     cod_extern_list externs));
00141 
00155 extern void
00156 cod_subroutine_declaration(const char *decl, cod_parse_context context);
00157 
00167 extern void cod_add_simple_struct_type(const char *name, FMFieldList field_list, 
00168                                        cod_parse_context context);
00169 
00178 extern void cod_add_struct_type(FMStructDescList format_list, 
00179                                 cod_parse_context context);
00180 
00189 extern void
00190 cod_add_param(const char *id, const char *typ, int param_num, 
00191               cod_parse_context context);
00192 
00202 #ifdef __FM__
00203 extern void
00204 cod_add_encoded_param(const char *id, char *data, int param_num, 
00205                       FMContext c, cod_parse_context context);
00206 #endif
00207 
00214 extern void
00215 cod_set_return_type(char *typ, cod_parse_context context);
00216 
00221 typedef struct _cod_code_struct {
00223     void (*func)(void);
00225     int has_exec_ctx;
00227     void *code_memory_block;
00229     void *data;
00231     int static_size_required;
00233     int static_block_address_register;
00235     FMStructDescList static_formats;
00238     void *drisc_context;
00241     void *execution_handle;
00242 } *cod_code;
00243 
00250 cod_code cod_code_gen ARGS((char *code, cod_parse_context context));
00251 
00259 int cod_code_verify ARGS((char *code, cod_parse_context context));
00260 
00267 extern void cod_code_free ARGS((cod_code code));
00268 
00275 extern cod_exec_context cod_create_exec_context ARGS((cod_code code));
00276 
00283 extern void cod_exec_context_free ARGS((cod_exec_context ec));
00284 
00295 extern void cod_assoc_client_data(cod_exec_context ec, int key, long value);
00296 
00309 extern long cod_get_client_data(cod_exec_context ec, int key);
00310 
00319 extern void *cod_extract_state(cod_exec_context ec, int *length_p);
00320 
00329 extern int cod_install_state(cod_exec_context ec, void *state, int length);
00330 
00341 int cod_parse_for_context ARGS((char *code, cod_parse_context context));
00342 
00353 int cod_parse_for_globals ARGS((char *code, cod_parse_context context));
00354 
00360 extern cod_parse_context cod_copy_context ARGS((cod_parse_context context));
00361 
00369 extern cod_parse_context cod_copy_globals ARGS((cod_parse_context context));
00370 
00378 typedef void (*err_out_func_t) ARGS((void *client_data, char *string));
00379 
00388 void cod_set_error_func ARGS((cod_parse_context context, 
00389                               err_out_func_t err_func));
00390 
00397 void cod_set_dont_coerce_return ARGS((cod_parse_context context, int value));
00398 
00404 void cod_dump ARGS((cod_code code));
00405 
00412 extern cod_code
00413 gen_rollback_code ARGS((FMStructDescList format1, FMStructDescList format2, char *xform_code));
00414 
00421 extern void cod_add_int_constant_to_parse_context ARGS((const char *id, int value,
00422     cod_parse_context context)); 
00423 
00430 extern void cod_set_closure ARGS((char *name, void* value, cod_parse_context context));
00431 
00432 #if defined(__cplusplus) || defined(c_plusplus)
00433 }
00434 #endif
00435 
00436 #endif