COD (C-On-Demand) Dynamic Code Generation
|
Go to the source code of this file.
Data Structures | |
struct | _FMField |
struct | _FMOptInfo |
struct | _FMformat_list |
struct | extern_entry |
struct | _cod_code_struct |
Defines | |
#define | FMOffset(p_type, field) ((int) (((char *) (&(((p_type)0)->field))) - ((char *) 0))) |
#define | FMstr(s) "s" |
#define | FMArrayDecl(type, size) FMstr(type[size]) |
#define | FMArrayDecl2(type, size, size2) FMstr(type[size][size2]) |
#define | FMDefaultDecl(name, val) FMstr(name(val)) |
Typedefs | |
typedef struct parse_struct * | cod_parse_context |
typedef struct cod_exec_struct * | cod_exec_context |
typedef struct sm_struct * | sm_ref |
typedef struct _FMField | FMField |
typedef struct _FMField * | FMFieldList |
typedef struct _FMOptInfo | FMOptInfo |
typedef struct _FMformat_list | FMStructDescRec |
typedef struct _FMformat_list * | FMStructDescList |
typedef struct extern_entry | cod_extern_entry |
typedef cod_extern_entry * | cod_extern_list |
typedef struct _cod_code_struct * | cod_code |
typedef void(* | err_out_func_t )(void *client_data, char *string) |
Functions | |
cod_parse_context | new_cod_parse_context (void) |
void | cod_free_parse_context (cod_parse_context context) |
void | cod_assoc_externs (cod_parse_context context, cod_extern_list externs) |
void | cod_subroutine_declaration (const char *decl, cod_parse_context context) |
This is used to establish the parameter profile and return type of the subroutine to be generated. | |
void | cod_add_simple_struct_type (const char *name, FMFieldList field_list, cod_parse_context context) |
Make a structured type, represented by a FFS-style FMFieldList, available in a particular context. | |
void | cod_add_struct_type (FMStructDescList format_list, cod_parse_context context) |
Make a set of structured types, represented by a FFS-style FMStructDescList, available in a particular context. | |
void | cod_add_param (const char *id, const char *typ, int param_num, cod_parse_context context) |
As an alternative to cod_subroutine_declaration(), add declaration for the Nth parameter. | |
void | cod_set_return_type (char *typ, cod_parse_context context) |
add a declaration for the Nth parameter as an FFS-encoded structure | |
cod_code | cod_code_gen (char *code, cod_parse_context context) |
int | cod_code_verify (char *code, cod_parse_context context) |
void | cod_code_free (cod_code code) |
cod_exec_context | cod_create_exec_context (cod_code code) |
void | cod_exec_context_free (cod_exec_context ec) |
void | cod_assoc_client_data (cod_exec_context ec, int key, long value) |
long | cod_get_client_data (cod_exec_context ec, int key) |
void * | cod_extract_state (cod_exec_context ec, int *length_p) |
int | cod_install_state (cod_exec_context ec, void *state, int length) |
int | cod_parse_for_context (char *code, cod_parse_context context) |
This parses a string to determine what external functions and variables are visible during code generation. | |
int | cod_parse_for_globals (char *code, cod_parse_context context) |
This parses a string to setup global variables that are visible during code generation. | |
cod_parse_context | cod_copy_context (cod_parse_context context) |
cod_parse_context | cod_copy_globals (cod_parse_context context) |
void | cod_set_error_func (cod_parse_context context, err_out_func_t err_func) |
void | cod_set_dont_coerce_return (cod_parse_context context, int value) |
void | cod_dump (cod_code code) |
cod_code | gen_rollback_code (FMStructDescList format1, FMStructDescList format2, char *xform_code) |
void | cod_add_int_constant_to_parse_context (const char *id, int value, cod_parse_context context) |
This is used to add an integer constant available in a particular context. | |
void | cod_set_closure (char *name, void *value, cod_parse_context context) |
Sets what value cod_closure_context will send to a subroutine. |
typedef struct parse_struct* cod_parse_context |
cod_parse_context is the basic handle controlling generation of subroutines and functions. It is used in nearly all calls to setup parameter profiles and other information and to generate the code. Using a separate handle rather than static variables to store this information over the multiple calls needed for code generation ensures thread safety.
typedef struct cod_exec_struct* cod_exec_context |
cod_exec_context is used to provide an execution context for COD-generated procedures. The full set of uses for this have not been determined, but it will support execution emulation on platforms where we do not have dynamic code generation, extraction of static state from functions, and the ability to pass information "through" a generated function from the calling context and make it available to a subroutine that might be called by the generated code.
typedef struct sm_struct* sm_ref |
sm_ref is a pointer to an internal COD data structure representing a semantic element of a program fragment (E.G. a parameter definition).
typedef struct _FMformat_list FMStructDescRec |
A structure to hold Format Name / Field List associations.
This is used to associate names with field lists. Together these define a structure that can be composed into larger structures.
typedef struct extern_entry cod_extern_entry |
A structure to hold external entries.
This is used to associate textual names with addresses.
typedef cod_extern_entry* cod_extern_list |
A list of cod_extern_entry structures. This is used to specify the addresses of external functions or variables that a function may access.
typedef struct _cod_code_struct * cod_code |
cod_code is a handle to the generated code. In addition to the generated code block, it holds external data pointers and supplemental information.
typedef void(* err_out_func_t)(void *client_data, char *string) |
err_out_func_t is a function pointer type. Functions matching this profile can be used as call-out handlers for COD errors.
client_data | an uninspected value passed in from cod_set_error_func() |
string | the textual representation of the error. |
cod_parse_context new_cod_parse_context | ( | void | ) |
Create a handle to a new cod_parse_context.
This is generally the first call in dynamically generating a subroutine/function. The cod_parse_context created here is used in all future calls, setting up the parameter profile and generating the code.
void cod_free_parse_context | ( | cod_parse_context | context | ) |
Free a handle to an cod_parse_context.
context | the cod_parse_context to be free'd. Calling this routine frees all memory associated with the parse context, but not that of code that has been generated from this context. |
void cod_assoc_externs | ( | cod_parse_context | context, |
cod_extern_list | externs | ||
) |
Associate a set of "name, external address" pairs with a parse context
These names and addresses are used to resolve (external references in generated code). In addition to associating the addresses, the full prototypes of the functions or variables must be added to the parse context, usually with cod_parse_for_context().
context | the cod_parse_context to which the externs are associated. |
externs | the list of "name, external address" pairs to be associated. This list should be terminated with a {NULL, 0} pair. |
void cod_subroutine_declaration | ( | const char * | decl, |
cod_parse_context | context | ||
) |
This is used to establish the parameter profile and return type of the subroutine to be generated.
decl | the textual declaration for the subroutine |
context | the context for subroutine generation |
The 'decl' parameter is a C-style declaration, without a terminating semicolon. I.E. something like: "int proc(double d, int *i)"
void cod_add_simple_struct_type | ( | const char * | name, |
FMFieldList | field_list, | ||
cod_parse_context | context | ||
) |
Make a structured type, represented by a FFS-style FMFieldList, available in a particular context.
name | the name to be associated with the new structured type. |
field_list | the FFS-style FMFieldList that describes the layout of the structure. |
context | the context in which the type is to be made available. |
void cod_add_struct_type | ( | FMStructDescList | format_list, |
cod_parse_context | context | ||
) |
Make a set of structured types, represented by a FFS-style FMStructDescList, available in a particular context.
format_list | the FFS-style FMStructDescList that describes the layout of the structures. |
context | the context in which the type is to be made available. |
void cod_add_param | ( | const char * | id, |
const char * | typ, | ||
int | param_num, | ||
cod_parse_context | context | ||
) |
As an alternative to cod_subroutine_declaration(), add declaration for the Nth parameter.
name | the name to be associated with the new parameter. |
typ | the data type of the new parameter. |
param_num | the numeral of the new parameter (0 is first) |
context | the context in which the subroutine is being declared. |
void cod_set_return_type | ( | char * | typ, |
cod_parse_context | context | ||
) |
add a declaration for the Nth parameter as an FFS-encoded structure
name | the name to be associated with the new parameter. |
data | an encoded data block |
param_num | the numeral of the new parameter (0 is first) |
c | an FMContext value in which to format information for the data is available |
context | the context in which the subroutine is being declared. |
As an alternative to cod_subroutine_declaration(), set the return type of a subroutine
typ | the data type of the return value. |
context | the context in which the subroutine is being declared. |
cod_code cod_code_gen | ( | char * | code, |
cod_parse_context | context | ||
) |
generate code for a function body in a given context
code | the string representing the function body. |
context | the context in which the function body is to be generated. |
int cod_code_verify | ( | char * | code, |
cod_parse_context | context | ||
) |
perform syntactical and semantic checking of a function body without actually generating code.
code | the string representing the function body. |
context | the context in which the function body is to be checked. |
void cod_code_free | ( | cod_code | code | ) |
Free all resources associated with the generated code associated with the cod_code handle.
code | the handle to the resources that will be free'd. |
create an execution context associated with a code block
code | the handle to the code bloc |
void cod_exec_context_free | ( | cod_exec_context | ec | ) |
Free all resources associated with the generated code associated with the cod_exec_context handle.
code | the handle to the resources that will be free'd. |
void cod_assoc_client_data | ( | cod_exec_context | ec, |
int | key, | ||
long | value | ||
) |
Associate application-level data with an execution context. This is typically done so that it can be retrieved by a called subprocess. The key value is any 32-bit value, presumably chosen to minimize the possibility of conflict. The value that can be associated is a long.
ec | the cod_exec_context value to which to associate the data |
key | the value that will serve as a key to retrieve the data |
value | the 'long' data that will be associated with the key |
long cod_get_client_data | ( | cod_exec_context | ec, |
int | key | ||
) |
Retrieve application-level data with an execution context. This is typically done by a called subprocess to retrieve data that was available to the broader application. The key value is any 32-bit value, presumably chosen to minimize the possibility of conflict. The value returned is one which had been associated via cod_assoc_client_data(). If no value had been associated, -1 is returned. *
ec | the cod_exec_context value to which to associate the data |
key | the value that will serve as a key to retrieve the data |
void* cod_extract_state | ( | cod_exec_context | ec, |
int * | length_p | ||
) |
Extract static state from an execution context.
ec | the cod_exec_context value from which to extract static state |
length_pointer | a pointer to an integer which will be set to the length of the returned state block |
int cod_install_state | ( | cod_exec_context | ec, |
void * | state, | ||
int | length | ||
) |
Install static state into an execution context.
ec | the cod_exec_context value into which to install static state |
state | the state block to install |
state_size | the size of the state block |
int cod_parse_for_context | ( | char * | code, |
cod_parse_context | context | ||
) |
This parses a string to determine what external functions and variables are visible during code generation.
The input string is of standard C syntax for external variable and function declarations. All previously registered types are available.
code | The input string containing declarations. |
context | The parse context in which the declarations should be visible. |
int cod_parse_for_globals | ( | char * | code, |
cod_parse_context | context | ||
) |
This parses a string to setup global variables that are visible during code generation.
The input string is of standard C syntax for external variable and function declarations. All previously registered types are available.
code | The input string containing declarations. |
context | The parse context in which the declarations should be visible. |
cod_parse_context cod_copy_context | ( | cod_parse_context | context | ) |
Duplicate a handle to an cod_parse_context.
context | the cod_parse_context to be duplicated. |
cod_parse_context cod_copy_globals | ( | cod_parse_context | context | ) |
Duplicate a handle to an cod_parse_context, specifically adapting the results to reuse the global declarations of the prior context. This is a specialized function that helps run external regression tests and may not be broadly useful.
context | the cod_parse_context to be duplicated. |
void cod_set_error_func | ( | cod_parse_context | context, |
err_out_func_t | err_func | ||
) |
cod_set_error_func establishes a new error output routine for COD.
By default, errors are sent to stdout. If the error output is set then errors can be captured for other disposition.
context | the context in which errors are to be captured |
err_func | the function to be called when errors occur |
void cod_set_dont_coerce_return | ( | cod_parse_context | context, |
int | value | ||
) |
cod_set_dont_coerce_return restricts COD to more strict type matching for expressions and return values
context | the context to restrict |
value | True if coercion is not to be applied to return values, false by default |
This will dump (to stdout) a disassembled version of the machine code that has been generated
code | the cod_code handle containing the code to be dumped. |
cod_code gen_rollback_code | ( | FMStructDescList | format1, |
FMStructDescList | format2, | ||
char * | xform_code | ||
) |
This will generate rollback code for message morphing
format1 | the new format. This is the format of the input message. |
format2 | the old format. This is the format of the output message. |
xform_code | The COD code string that transforms data from format1 to format2. |
void cod_add_int_constant_to_parse_context | ( | const char * | id, |
int | value, | ||
cod_parse_context | context | ||
) |
This is used to add an integer constant available in a particular context.
id | The name to be associated with the type. |
value | The value of the constant |
context | the context in which this is to be created |
void cod_set_closure | ( | char * | name, |
void * | value, | ||
cod_parse_context | context | ||
) |
Sets what value cod_closure_context will send to a subroutine.
name | The name of the (external) subroutine. |
value | The value to send |
context | The context in which the subroutine has been declared. |