libyasm
Macros | Typedefs | Enumerations | Functions
symrec.h File Reference

YASM symbol table interface. More...

Go to the source code of this file.

Typedefs

typedef enum yasm_sym_status yasm_sym_status
 Symbol status. More...
 
typedef enum yasm_sym_vis yasm_sym_vis
 Symbol record visibility. More...
 
typedef int(* yasm_symtab_traverse_callback )(yasm_symrec *sym, void *d)
 Callback function for yasm_symrec_traverse(). More...
 
typedef struct yasm_symtab_iter yasm_symtab_iter
 Symbol table iterator (opaque type). More...
 
typedef yasm_bytecodeyasm_symrec_get_label_bytecodep
 Dependent pointer to a bytecode. More...
 

Enumerations

enum  yasm_sym_status {
  YASM_SYM_NOSTATUS = 0, YASM_SYM_USED = 1 << 0, YASM_SYM_DEFINED = 1 << 1, YASM_SYM_VALUED = 1 << 2,
  YASM_SYM_NOTINTABLE = 1 << 3
}
 Symbol status. More...
 
enum  yasm_sym_vis {
  YASM_SYM_LOCAL = 0, YASM_SYM_GLOBAL = 1 << 0, YASM_SYM_COMMON = 1 << 1, YASM_SYM_EXTERN = 1 << 2,
  YASM_SYM_DLOCAL = 1 << 3
}
 Symbol record visibility. More...
 

Functions

YASM_LIB_DECL yasm_symtabyasm_symtab_create (void)
 Create a new symbol table. More...
 
YASM_LIB_DECL void yasm_symtab_destroy (yasm_symtab *symtab)
 Destroy a symbol table and all internal symbols. More...
 
YASM_LIB_DECL void yasm_symtab_set_case_sensitive (yasm_symtab *symtab, int sensitive)
 Set the symbol table to be case sensitive or not. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_abs_sym (yasm_symtab *symtab)
 Get a reference to the symbol table's "absolute" symbol. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_use (yasm_symtab *symtab, const char *name, unsigned long line)
 Get a reference to (use) a symbol. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_get (yasm_symtab *symtab, const char *name)
 Get a reference to a symbol, without "using" it. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_define_equ (yasm_symtab *symtab, const char *name, yasm_expr *e, unsigned long line)
 Define a symbol as an EQU value. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_define_label (yasm_symtab *symtab, const char *name, yasm_bytecode *precbc, int in_table, unsigned long line)
 Define a symbol as a label. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_define_curpos (yasm_symtab *symtab, const char *name, yasm_bytecode *precbc, unsigned long line)
 Define a symbol as a label representing the current assembly position. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_define_special (yasm_symtab *symtab, const char *name, yasm_sym_vis vis)
 Define a special symbol that will appear in the symbol table and have a defined name, but have no other data associated with it within the standard symrec. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_declare (yasm_symtab *symtab, const char *name, yasm_sym_vis vis, unsigned long line)
 Declare external visibility of a symbol. More...
 
YASM_LIB_DECL void yasm_symrec_declare (yasm_symrec *symrec, yasm_sym_vis vis, unsigned long line)
 Declare external visibility of a symbol. More...
 
YASM_LIB_DECL int yasm_symtab_traverse (yasm_symtab *symtab, void *d, yasm_symtab_traverse_callback func)
 Traverse all symbols in the symbol table. More...
 
YASM_LIB_DECL const
yasm_symtab_iter
yasm_symtab_first (const yasm_symtab *symtab)
 Get an iterator pointing to the first symbol in the symbol table. More...
 
YASM_LIB_DECL const
yasm_symtab_iter
yasm_symtab_next (const yasm_symtab_iter *prev)
 Move a symbol table iterator to the next symbol in the symbol table. More...
 
YASM_LIB_DECL yasm_symrecyasm_symtab_iter_value (const yasm_symtab_iter *cur)
 Get the symbol corresponding to the current symbol table iterator value. More...
 
YASM_LIB_DECL void yasm_symtab_parser_finalize (yasm_symtab *symtab, int undef_extern, yasm_errwarns *errwarns)
 Finalize symbol table after parsing stage. More...
 
YASM_LIB_DECL void yasm_symtab_print (yasm_symtab *symtab, FILE *f, int indent_level)
 Print the symbol table. More...
 
YASM_LIB_DECL const char * yasm_symrec_get_name (const yasm_symrec *sym)
 Get the name of a symbol. More...
 
YASM_LIB_DECL char * yasm_symrec_get_global_name (const yasm_symrec *sym, const yasm_object *object)
 Get the externally-visible (global) name of a symbol. More...
 
YASM_LIB_DECL yasm_sym_vis yasm_symrec_get_visibility (const yasm_symrec *sym)
 Get the visibility of a symbol. More...
 
YASM_LIB_DECL yasm_sym_status yasm_symrec_get_status (const yasm_symrec *sym)
 Get the status of a symbol. More...
 
YASM_LIB_DECL unsigned long yasm_symrec_get_def_line (const yasm_symrec *sym)
 Get the virtual line of where a symbol was first defined. More...
 
YASM_LIB_DECL unsigned long yasm_symrec_get_decl_line (const yasm_symrec *sym)
 Get the virtual line of where a symbol was first declared. More...
 
YASM_LIB_DECL unsigned long yasm_symrec_get_use_line (const yasm_symrec *sym)
 Get the virtual line of where a symbol was first used. More...
 
YASM_LIB_DECL const yasm_expryasm_symrec_get_equ (const yasm_symrec *sym)
 Get EQU value of a symbol. More...
 
YASM_LIB_DECL int yasm_symrec_get_label (const yasm_symrec *sym, yasm_symrec_get_label_bytecodep *precbc)
 Get the label location of a symbol. More...
 
YASM_LIB_DECL void yasm_symrec_set_size (yasm_symrec *sym, int size)
 Set the size of a symbol. More...
 
YASM_LIB_DECL int yasm_symrec_get_size (const yasm_symrec *sym)
 Get the size of a symbol. More...
 
YASM_LIB_DECL void yasm_symrec_set_segment (yasm_symrec *sym, const char *segment)
 Set the segment of a symbol. More...
 
YASM_LIB_DECL const char * yasm_symrec_get_segment (const yasm_symrec *sym)
 Get the segment of a symbol. More...
 
YASM_LIB_DECL int yasm_symrec_is_abs (const yasm_symrec *sym)
 Determine if symbol is the "absolute" symbol created by yasm_symtab_abs_sym(). More...
 
YASM_LIB_DECL int yasm_symrec_is_special (const yasm_symrec *sym)
 Determine if symbol is a special symbol. More...
 
YASM_LIB_DECL int yasm_symrec_is_curpos (const yasm_symrec *sym)
 Determine if symbol is a label representing the current assembly position. More...
 
YASM_LIB_DECL void yasm_symrec_set_objext_valparams (yasm_symrec *sym, yasm_valparamhead *objext_valparams)
 Set object-extended valparams. More...
 
YASM_LIB_DECL yasm_valparamheadyasm_symrec_get_objext_valparams (yasm_symrec *sym)
 Get object-extended valparams, if any, associated with symbol's declaration. More...
 
YASM_LIB_DECL void yasm_symrec_set_common_size (yasm_symrec *sym, yasm_expr *common_size)
 Set common size of symbol. More...
 
YASM_LIB_DECL yasm_expr ** yasm_symrec_get_common_size (yasm_symrec *sym)
 Get common size of symbol, if symbol is declared COMMON and a size was set for it. More...
 
YASM_LIB_DECL void * yasm_symrec_get_data (yasm_symrec *sym, const yasm_assoc_data_callback *callback)
 Get associated data for a symbol and data callback. More...
 
YASM_LIB_DECL void yasm_symrec_add_data (yasm_symrec *sym, const yasm_assoc_data_callback *callback, void *data)
 Add associated data to a symbol. More...
 
YASM_LIB_DECL void yasm_symrec_print (const yasm_symrec *sym, FILE *f, int indent_level)
 Print a symbol. More...
 

Detailed Description

YASM symbol table interface.

Definition in file symrec.h.

Typedef Documentation

Symbol status.

YASM_SYM_DEFINED is set by yasm_symtab_define_label(), yasm_symtab_define_equ(), or yasm_symtab_declare()/yasm_symrec_declare() with a visibility of YASM_SYM_EXTERN or YASM_SYM_COMMON.

typedef enum yasm_sym_vis yasm_sym_vis

Symbol record visibility.

Note
YASM_SYM_EXTERN and YASM_SYM_COMMON are mutually exclusive.

Dependent pointer to a bytecode.

Definition at line 313 of file symrec.h.

Symbol table iterator (opaque type).

Definition at line 210 of file symrec.h.

typedef int(* yasm_symtab_traverse_callback)(yasm_symrec *sym,void *d)

Callback function for yasm_symrec_traverse().

Parameters
symsymbol
ddata passed into yasm_symrec_traverse()
Returns
Nonzero to stop symbol traversal.

Definition at line 195 of file symrec.h.

Enumeration Type Documentation

Symbol status.

YASM_SYM_DEFINED is set by yasm_symtab_define_label(), yasm_symtab_define_equ(), or yasm_symtab_declare()/yasm_symrec_declare() with a visibility of YASM_SYM_EXTERN or YASM_SYM_COMMON.

Enumerator
YASM_SYM_NOSTATUS 

no status

YASM_SYM_USED 

for use before definition

YASM_SYM_DEFINED 

once it's been defined in the file

YASM_SYM_VALUED 

once its value has been determined

YASM_SYM_NOTINTABLE 

if it's not in sym_table (ex.

'$')

Definition at line 41 of file symrec.h.

Symbol record visibility.

Note
YASM_SYM_EXTERN and YASM_SYM_COMMON are mutually exclusive.
Enumerator
YASM_SYM_LOCAL 

Default, local only.

YASM_SYM_GLOBAL 

If symbol is declared GLOBAL.

YASM_SYM_COMMON 

If symbol is declared COMMON.

YASM_SYM_EXTERN 

If symbol is declared EXTERN.

YASM_SYM_DLOCAL 

If symbol is explicitly declared LOCAL.

Definition at line 52 of file symrec.h.

Function Documentation

YASM_LIB_DECL void yasm_symrec_add_data ( yasm_symrec sym,
const yasm_assoc_data_callback callback,
void *  data 
)

Add associated data to a symbol.

Attention
Deletes any existing associated data for that data callback.
Parameters
symsymbol
callbackcallback
datadata to associate
YASM_LIB_DECL void yasm_symrec_declare ( yasm_symrec symrec,
yasm_sym_vis  vis,
unsigned long  line 
)

Declare external visibility of a symbol.

Note
Not all visibility combinations are allowed.
Parameters
symrecsymbol
visvisibility
linevirtual line of visibility-setting
YASM_LIB_DECL yasm_expr** yasm_symrec_get_common_size ( yasm_symrec sym)

Get common size of symbol, if symbol is declared COMMON and a size was set for it.

Parameters
symsymbol
Returns
Common size (NULL if none).
YASM_LIB_DECL void* yasm_symrec_get_data ( yasm_symrec sym,
const yasm_assoc_data_callback callback 
)

Get associated data for a symbol and data callback.

Parameters
symsymbol
callbackcallback used when adding data
Returns
Associated data (NULL if none).
YASM_LIB_DECL unsigned long yasm_symrec_get_decl_line ( const yasm_symrec sym)

Get the virtual line of where a symbol was first declared.

Parameters
symsymbol
Returns
line virtual line
YASM_LIB_DECL unsigned long yasm_symrec_get_def_line ( const yasm_symrec sym)

Get the virtual line of where a symbol was first defined.

Parameters
symsymbol
Returns
line virtual line
YASM_LIB_DECL const yasm_expr* yasm_symrec_get_equ ( const yasm_symrec sym)

Get EQU value of a symbol.

Parameters
symsymbol
Returns
EQU value, or NULL if symbol is not an EQU or is not defined.
YASM_LIB_DECL char* yasm_symrec_get_global_name ( const yasm_symrec sym,
const yasm_object object 
)

Get the externally-visible (global) name of a symbol.

Parameters
symsymbol
objectobject
Returns
Externally-visible symbol name (allocated, caller must free).
YASM_LIB_DECL int yasm_symrec_get_label ( const yasm_symrec sym,
yasm_symrec_get_label_bytecodep precbc 
)

Get the label location of a symbol.

Parameters
symsymbol
precbcbytecode preceding label (output)
Returns
0 if not symbol is not a label or if the symbol's visibility is YASM_SYM_EXTERN or YASM_SYM_COMMON (not defined in the file).
YASM_LIB_DECL const char* yasm_symrec_get_name ( const yasm_symrec sym)

Get the name of a symbol.

Parameters
symsymbol
Returns
Symbol name.
YASM_LIB_DECL yasm_valparamhead* yasm_symrec_get_objext_valparams ( yasm_symrec sym)

Get object-extended valparams, if any, associated with symbol's declaration.

Parameters
symsymbol
Returns
Object-extended valparams (NULL if none).
YASM_LIB_DECL const char* yasm_symrec_get_segment ( const yasm_symrec sym)

Get the segment of a symbol.

Parameters
symsymbol
Returns
segment of the symbol, NULL if none specified by the user.
YASM_LIB_DECL int yasm_symrec_get_size ( const yasm_symrec sym)

Get the size of a symbol.

Parameters
symsymbol
Returns
size of the symbol, 0 if none specified by the user.
YASM_LIB_DECL yasm_sym_status yasm_symrec_get_status ( const yasm_symrec sym)

Get the status of a symbol.

Parameters
symsymbol
Returns
Symbol status.
YASM_LIB_DECL unsigned long yasm_symrec_get_use_line ( const yasm_symrec sym)

Get the virtual line of where a symbol was first used.

Parameters
symsymbol
Returns
line virtual line
YASM_LIB_DECL yasm_sym_vis yasm_symrec_get_visibility ( const yasm_symrec sym)

Get the visibility of a symbol.

Parameters
symsymbol
Returns
Symbol visibility.
YASM_LIB_DECL int yasm_symrec_is_abs ( const yasm_symrec sym)

Determine if symbol is the "absolute" symbol created by yasm_symtab_abs_sym().

Parameters
symsymbol
Returns
0 if symbol is not the "absolute" symbol, nonzero otherwise.
YASM_LIB_DECL int yasm_symrec_is_curpos ( const yasm_symrec sym)

Determine if symbol is a label representing the current assembly position.

Parameters
symsymbol
Returns
0 if symbol is not a current position label, nonzero otherwise.
YASM_LIB_DECL int yasm_symrec_is_special ( const yasm_symrec sym)

Determine if symbol is a special symbol.

Parameters
symsymbol
Returns
0 if symbol is not a special symbol, nonzero otherwise.
YASM_LIB_DECL void yasm_symrec_print ( const yasm_symrec sym,
FILE *  f,
int  indent_level 
)

Print a symbol.

For debugging purposes.

Parameters
ffile
indent_levelindentation level
symsymbol
YASM_LIB_DECL void yasm_symrec_set_common_size ( yasm_symrec sym,
yasm_expr common_size 
)

Set common size of symbol.

Parameters
symsymbol
common_sizecommon size expression
YASM_LIB_DECL void yasm_symrec_set_objext_valparams ( yasm_symrec sym,
yasm_valparamhead objext_valparams 
)

Set object-extended valparams.

Parameters
symsymbol
objext_valparamsobject-extended valparams
YASM_LIB_DECL void yasm_symrec_set_segment ( yasm_symrec sym,
const char *  segment 
)

Set the segment of a symbol.

Parameters
symsymbol
segmentsegment to be set
YASM_LIB_DECL void yasm_symrec_set_size ( yasm_symrec sym,
int  size 
)

Set the size of a symbol.

Parameters
symsymbol
sizesize to be set
YASM_LIB_DECL yasm_symrec* yasm_symtab_abs_sym ( yasm_symtab symtab)

Get a reference to the symbol table's "absolute" symbol.

This is essentially an EQU with no name and value 0, and is used for relocating absolute current-position-relative values.

See Also
yasm_value_set_curpos_rel().
Parameters
symtabsymbol table
Returns
Absolute symbol (dependent pointer, do not free).
YASM_LIB_DECL yasm_symtab* yasm_symtab_create ( void  )

Create a new symbol table.

YASM_LIB_DECL yasm_symrec* yasm_symtab_declare ( yasm_symtab symtab,
const char *  name,
yasm_sym_vis  vis,
unsigned long  line 
)

Declare external visibility of a symbol.

Note
Not all visibility combinations are allowed.
Parameters
symtabsymbol table
namesymbol name
visvisibility
linevirtual line of visibility-setting
Returns
Symbol (dependent pointer, do not free).
YASM_LIB_DECL yasm_symrec* yasm_symtab_define_curpos ( yasm_symtab symtab,
const char *  name,
yasm_bytecode precbc,
unsigned long  line 
)

Define a symbol as a label representing the current assembly position.

This should be used for this purpose instead of yasm_symtab_define_label() as value_finalize_scan() looks for usage of this symbol type for special handling. The symbol created is not inserted into the symbol table.

Parameters
symtabsymbol table
namesymbol (label) name
precbcbytecode preceding label
linevirtual line of label
Returns
Symbol (dependent pointer, do not free).
YASM_LIB_DECL yasm_symrec* yasm_symtab_define_equ ( yasm_symtab symtab,
const char *  name,
yasm_expr e,
unsigned long  line 
)

Define a symbol as an EQU value.

Parameters
symtabsymbol table
namesymbol (EQU) name
eEQU value (expression)
linevirtual line of EQU
Returns
Symbol (dependent pointer, do not free).
YASM_LIB_DECL yasm_symrec* yasm_symtab_define_label ( yasm_symtab symtab,
const char *  name,
yasm_bytecode precbc,
int  in_table,
unsigned long  line 
)

Define a symbol as a label.

Parameters
symtabsymbol table
namesymbol (label) name
precbcbytecode preceding label
in_tablenonzero if the label should be inserted into the symbol table (some specially-generated ones should not be)
linevirtual line of label
Returns
Symbol (dependent pointer, do not free).
YASM_LIB_DECL yasm_symrec* yasm_symtab_define_special ( yasm_symtab symtab,
const char *  name,
yasm_sym_vis  vis 
)

Define a special symbol that will appear in the symbol table and have a defined name, but have no other data associated with it within the standard symrec.

Parameters
symtabsymbol table
namesymbol name
vissymbol visibility
Returns
Symbol (dependent pointer, do not free).
YASM_LIB_DECL void yasm_symtab_destroy ( yasm_symtab symtab)

Destroy a symbol table and all internal symbols.

Parameters
symtabsymbol table
Warning
All yasm_symrec *'s into this symbol table become invalid after this is called!
YASM_LIB_DECL const yasm_symtab_iter* yasm_symtab_first ( const yasm_symtab symtab)

Get an iterator pointing to the first symbol in the symbol table.

Parameters
symtabsymbol table
Returns
Iterator for the symbol table.
YASM_LIB_DECL yasm_symrec* yasm_symtab_get ( yasm_symtab symtab,
const char *  name 
)

Get a reference to a symbol, without "using" it.

Should be used for cases when an internal assembler usage of a symbol shouldn't be treated like a normal user symbol usage.

Parameters
symtabsymbol table
namesymbol name
Returns
Symbol (dependent pointer, do not free). May be NULL if symbol doesn't exist.
YASM_LIB_DECL yasm_symrec* yasm_symtab_iter_value ( const yasm_symtab_iter cur)

Get the symbol corresponding to the current symbol table iterator value.

Parameters
curiterator value
Returns
Corresponding symbol.
YASM_LIB_DECL const yasm_symtab_iter* yasm_symtab_next ( const yasm_symtab_iter prev)

Move a symbol table iterator to the next symbol in the symbol table.

Parameters
prevPrevious iterator value
Returns
Next iterator value, or NULL if no more symbols in the table.
YASM_LIB_DECL void yasm_symtab_parser_finalize ( yasm_symtab symtab,
int  undef_extern,
yasm_errwarns errwarns 
)

Finalize symbol table after parsing stage.

Checks for symbols that are used but never defined or declared YASM_SYM_EXTERN or YASM_SYM_COMMON.

Parameters
symtabsymbol table
undef_externif nonzero, all undef syms should be declared extern
errwarnserror/warning set
Note
Errors/warnings are stored into errwarns.
YASM_LIB_DECL void yasm_symtab_print ( yasm_symtab symtab,
FILE *  f,
int  indent_level 
)

Print the symbol table.

For debugging purposes.

Parameters
symtabsymbol table
ffile
indent_levelindentation level
YASM_LIB_DECL void yasm_symtab_set_case_sensitive ( yasm_symtab symtab,
int  sensitive 
)

Set the symbol table to be case sensitive or not.

Should be called before adding any symbol.

Parameters
symtabsymbol table
sensitivewhether the symbol table should be case sensitive.
YASM_LIB_DECL int yasm_symtab_traverse ( yasm_symtab symtab,
void *  d,
yasm_symtab_traverse_callback  func 
)

Traverse all symbols in the symbol table.

Parameters
symtabsymbol table
ddata to pass to each call of callback function
funccallback function called on each symbol
Returns
Nonzero value returned by callback function if it ever returned nonzero.
YASM_LIB_DECL yasm_symrec* yasm_symtab_use ( yasm_symtab symtab,
const char *  name,
unsigned long  line 
)

Get a reference to (use) a symbol.

The symbol does not necessarily need to be defined before it is used.

Parameters
symtabsymbol table
namesymbol name
linevirtual line where referenced
Returns
Symbol (dependent pointer, do not free).