libyasm
Data Structures | Macros | Typedefs | Functions
valparam.h File Reference

YASM value/parameter interface. More...

Go to the source code of this file.

Data Structures

struct  yasm_valparam
 Value/parameter pair. More...
 
union  yasm_valparam::yasm_param
 Parameter value. More...
 
struct  yasm_directive
 Directive list entry structure. More...
 
struct  yasm_dir_help
 Directive valparam parse helper structure. More...
 

Typedefs

typedef struct yasm_dir_help yasm_dir_help
 Directive valparam parse helper structure. More...
 

Functions

 STAILQ_HEAD (yasm_valparamhead, yasm_valparam)
 Linked list of value/parameter pairs. More...
 
YASM_LIB_DECL void yasm_call_directive (const yasm_directive *directive, yasm_object *object, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams, unsigned long line)
 Call a directive. More...
 
YASM_LIB_DECL yasm_valparamyasm_vp_create_id (char *v, char *p, int id_prefix)
 Create a new valparam with identifier parameter. More...
 
YASM_LIB_DECL yasm_valparamyasm_vp_create_string (char *v, char *p)
 Create a new valparam with string parameter. More...
 
YASM_LIB_DECL yasm_valparamyasm_vp_create_expr (char *v, yasm_expr *p)
 Create a new valparam with expression parameter. More...
 
YASM_LIB_DECL yasm_expryasm_vp_expr (const yasm_valparam *vp, yasm_symtab *symtab, unsigned long line)
 Get a valparam parameter as an expr. More...
 
YASM_LIB_DECL const char * yasm_vp_string (const yasm_valparam *vp)
 Get a valparam parameter as a string. More...
 
YASM_LIB_DECL const char * yasm_vp_id (const yasm_valparam *vp)
 Get a valparam parameter as an identifier. More...
 
YASM_LIB_DECL yasm_valparamheadyasm_vps_create (void)
 Create a new linked list of valparams. More...
 
YASM_LIB_DECL void yasm_vps_destroy (yasm_valparamhead *headp)
 Destroy a list of valparams (created with yasm_vps_create). More...
 
void yasm_vps_initialize (yasm_valparamhead *headp)
 Initialize linked list of valparams. More...
 
YASM_LIB_DECL void yasm_vps_delete (yasm_valparamhead *headp)
 Destroy (free allocated memory for) linked list of valparams (created with yasm_vps_initialize). More...
 
void yasm_vps_append (yasm_valparamhead *headp, yasm_valparam *vp)
 Append valparam to tail of linked list. More...
 
yasm_valparamyasm_vps_first (yasm_valparamhead *headp)
 Get first valparam in linked list. More...
 
yasm_valparamyasm_vps_next (yasm_valparam *cur)
 Get next valparam in linked list. More...
 
YASM_LIB_DECL void yasm_vps_print (const yasm_valparamhead *headp, FILE *f)
 Iterate through linked list of valparams. More...
 
YASM_LIB_DECL int yasm_dir_helper (void *obj, yasm_valparam *vp_first, unsigned long line, const yasm_dir_help *help, size_t nhelp, void *data, int(*helper_valparam)(void *object, yasm_valparam *vp, unsigned long line, void *data))
 Help parse a list of directive value/parameters. More...
 
YASM_LIB_DECL int yasm_dir_helper_flag_set (void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg)
 Standard helper for yasm_dir_helper() that simply sets a flag when called. More...
 
YASM_LIB_DECL int yasm_dir_helper_flag_or (void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg)
 Standard helper for yasm_dir_helper() that simply ORs a flag when called. More...
 
YASM_LIB_DECL int yasm_dir_helper_flag_and (void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg)
 Standard helper for yasm_dir_helper() that simply ANDs a flag when called. More...
 
YASM_LIB_DECL int yasm_dir_helper_expr (void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg)
 Standard helper for yasm_dir_helper() that parses an expr parameter. More...
 
YASM_LIB_DECL int yasm_dir_helper_intn (void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg)
 Standard helper for yasm_dir_helper() that parses an intnum parameter. More...
 
YASM_LIB_DECL int yasm_dir_helper_string (void *obj, yasm_valparam *vp, unsigned long line, void *data, uintptr_t arg)
 Standard helper for yasm_dir_helper() that parses an string (or standalone identifier) parameter. More...
 
YASM_LIB_DECL int yasm_dir_helper_valparam_warn (void *obj, yasm_valparam *vp, unsigned long line, void *data)
 Standard catch-all callback fro yasm_dir_helper(). More...
 

Detailed Description

YASM value/parameter interface.

Definition in file valparam.h.

Typedef Documentation

typedef struct yasm_dir_help yasm_dir_help

Directive valparam parse helper structure.

Function Documentation

STAILQ_HEAD ( yasm_valparamhead  ,
yasm_valparam   
)

Linked list of value/parameter pairs.

YASM_LIB_DECL void yasm_call_directive ( const yasm_directive directive,
yasm_object object,
yasm_valparamhead valparams,
yasm_valparamhead objext_valparams,
unsigned long  line 
)

Call a directive.

Performs any valparam checks asked for by the directive prior to call. Note that for a variety of reasons, a directive can generate an error.

Parameters
directivedirective
objectobject
valparamsvalue/parameters
objext_valparamsobject format-specific value/parameters
linevirtual line (from yasm_linemap)
YASM_LIB_DECL int yasm_dir_helper ( void *  obj,
yasm_valparam vp_first,
unsigned long  line,
const yasm_dir_help help,
size_t  nhelp,
void *  data,
int(*)(void *object, yasm_valparam *vp, unsigned long line, void *data)  helper_valparam 
)

Help parse a list of directive value/parameters.

Takes an array of yasm_dir_help structures and tries to match val=param (or just val) against the passed value/parameters. When no match is found in the array of help structures, calls helper_valparam.

Parameters
objobject to be passed to yasm_dir_help.helper() or helper_valparam() callback
vp_firstfirst value/parameter to examine
linevirtual line number; passed down to helper callback
helparray of yasm_dir_help structures
nhelpnumber of array elements
database data pointer; if a match is found, the respective yasm_dir_help.off is added to this prior to it being passed to the helper callback
helper_valparamcatch-all callback; should return -1 on error, 0 if not matched, 1 if matched.
Returns
-1 on error, 1 if any arguments matched (including via catch-all callback), 0 if no match.
YASM_LIB_DECL int yasm_dir_helper_expr ( void *  obj,
yasm_valparam vp,
unsigned long  line,
void *  data,
uintptr_t  arg 
)

Standard helper for yasm_dir_helper() that parses an expr parameter.

The yasm_dir_help structure that uses this function should have needsparam=1. The obj parameter to yasm_dir_helper() when this helper is used MUST point to a yasm_object. In addition, the data parameter that is ultimately passed to this function (e.g. yasm_dir_helper() data parameter plus yasm_dir_help.off) must point to a yasm_expr * initialized to NULL.

Parameters
objobject; must be yasm_object
vpvalparam
linevirtual line number
datapointer to yasm_expr *
argunused argument
Returns
-1 on error, 0 otherwise.
YASM_LIB_DECL int yasm_dir_helper_flag_and ( void *  obj,
yasm_valparam vp,
unsigned long  line,
void *  data,
uintptr_t  arg 
)

Standard helper for yasm_dir_helper() that simply ANDs a flag when called.

It does not look at the vp; rather, it uses the value of the arg parameter, and ANDs its inverse (~) with the unsigned long value in data.

Parameters
objunused
vpunused
lineunused
datapointer to an unsigned long
argflag to AND
Returns
0
YASM_LIB_DECL int yasm_dir_helper_flag_or ( void *  obj,
yasm_valparam vp,
unsigned long  line,
void *  data,
uintptr_t  arg 
)

Standard helper for yasm_dir_helper() that simply ORs a flag when called.

It does not look at the vp; rather, it uses the value of the arg parameter, and ORs it with the unsigned long value in data.

Parameters
objunused
vpunused
lineunused
datapointer to an unsigned long
argflag to OR
Returns
0
YASM_LIB_DECL int yasm_dir_helper_flag_set ( void *  obj,
yasm_valparam vp,
unsigned long  line,
void *  data,
uintptr_t  arg 
)

Standard helper for yasm_dir_helper() that simply sets a flag when called.

It does not look at the vp; rather, it uses the value of the arg parameter, and stores an unsigned long value to data.

Parameters
objunused
vpunused
lineunused
datapointer to an unsigned long
argflag to set
Returns
0
YASM_LIB_DECL int yasm_dir_helper_intn ( void *  obj,
yasm_valparam vp,
unsigned long  line,
void *  data,
uintptr_t  arg 
)

Standard helper for yasm_dir_helper() that parses an intnum parameter.

The yasm_dir_help structure that uses this function should have needsparam=1. The obj parameter to yasm_dir_helper() when this helper is used MUST point to a yasm_object. In addition, the data parameter that is ultimately passed to this function (e.g. yasm_dir_helper() data parameter plus yasm_dir_help.off) must point to a yasm_intnum * initialized to NULL.

Parameters
objobject; must be yasm_object
vpvalparam
linevirtual line number
datapointer to yasm_intnum *
argunused argument
Returns
-1 on error, 0 otherwise.
YASM_LIB_DECL int yasm_dir_helper_string ( void *  obj,
yasm_valparam vp,
unsigned long  line,
void *  data,
uintptr_t  arg 
)

Standard helper for yasm_dir_helper() that parses an string (or standalone identifier) parameter.

The yasm_dir_help structure that uses this function should have needsparam=1. The data parameter that is ultimately passed to this function (e.g. yasm_dir_helper() data parameter plus yasm_dir_help.off) must point to a char * initialized to NULL.

Parameters
objunused
vpvalparam
lineunused
datapointer to char *
argunused
Returns
-1 on error, 0 otherwise.
YASM_LIB_DECL int yasm_dir_helper_valparam_warn ( void *  obj,
yasm_valparam vp,
unsigned long  line,
void *  data 
)

Standard catch-all callback fro yasm_dir_helper().

Generates standard warning for all valparams.

Parameters
objunused
vpvalparam
lineunused
dataunused
Returns
0
YASM_LIB_DECL yasm_valparam* yasm_vp_create_expr ( char *  v,
yasm_expr p 
)

Create a new valparam with expression parameter.

Parameters
vvalue
pparameter
Returns
Newly allocated valparam.
YASM_LIB_DECL yasm_valparam* yasm_vp_create_id ( char *  v,
char *  p,
int  id_prefix 
)

Create a new valparam with identifier parameter.

Parameters
vvalue
pparameter
id_prefixidentifier prefix for raw identifiers
Returns
Newly allocated valparam.
YASM_LIB_DECL yasm_valparam* yasm_vp_create_string ( char *  v,
char *  p 
)

Create a new valparam with string parameter.

Parameters
vvalue
pparameter
Returns
Newly allocated valparam.
YASM_LIB_DECL yasm_expr* yasm_vp_expr ( const yasm_valparam vp,
yasm_symtab symtab,
unsigned long  line 
)

Get a valparam parameter as an expr.

If the parameter is an identifier, it's treated as a symbol (yasm_symtab_use() is called to convert it).

Parameters
vpvalparam
symtabsymbol table
linevirtual line
Returns
Expression, or NULL if vp is NULL or the parameter cannot be converted to an expression.
YASM_LIB_DECL const char* yasm_vp_id ( const yasm_valparam vp)

Get a valparam parameter as an identifier.

Parameters
vpvalparam
Returns
Identifier (string), or NULL if vp is NULL or the parameter is not an identifier.
YASM_LIB_DECL const char* yasm_vp_string ( const yasm_valparam vp)

Get a valparam parameter as a string.

If the parameter is an identifier, it's treated as a string.

Parameters
vpvalparam
Returns
String, or NULL if vp is NULL or the parameter cannot be realized as a string.
void yasm_vps_append ( yasm_valparamhead headp,
yasm_valparam vp 
)

Append valparam to tail of linked list.

Parameters
headplinked list
vpvalparam
YASM_LIB_DECL yasm_valparamhead* yasm_vps_create ( void  )

Create a new linked list of valparams.

Returns
Newly allocated valparam list.
YASM_LIB_DECL void yasm_vps_delete ( yasm_valparamhead headp)

Destroy (free allocated memory for) linked list of valparams (created with yasm_vps_initialize).

Warning
Deletes val/params.
Parameters
headplinked list
YASM_LIB_DECL void yasm_vps_destroy ( yasm_valparamhead headp)

Destroy a list of valparams (created with yasm_vps_create).

Parameters
headplist of valparams
yasm_valparam* yasm_vps_first ( yasm_valparamhead headp)

Get first valparam in linked list.

Parameters
headplinked list
Returns
First valparam in linked list.
void yasm_vps_initialize ( yasm_valparamhead headp)

Initialize linked list of valparams.

Parameters
headplinked list
yasm_valparam* yasm_vps_next ( yasm_valparam cur)

Get next valparam in linked list.

Parameters
curprevious valparam in linked list
Returns
Next valparam in linked list.
YASM_LIB_DECL void yasm_vps_print ( const yasm_valparamhead headp,
FILE *  f 
)

Iterate through linked list of valparams.

Parameters
iteriterator variable
headplinked list Print linked list of valparams. For debugging purposes.
ffile
headplinked list