libyasm/section.h File Reference

YASM section interface. More...

Go to the source code of this file.

Data Structures

struct  yasm_reloc
struct  yasm_object
 An object. More...

Typedefs

typedef yasm_reloc yasm_reloc
 Basic YASM relocation.

Functions

YASM_LIB_DECL yasm_objectyasm_object_create (const char *src_filename, const char *obj_filename, yasm_arch *arch, const yasm_objfmt_module *objfmt_module, const yasm_dbgfmt_module *dbgfmt_module)
 Create a new object.
YASM_LIB_DECL yasm_sectionyasm_object_get_general (yasm_object *object, const char *name, unsigned long align, int code, int res_only, int *isnew, unsigned long line)
 Create a new, or continue an existing, general section.
YASM_LIB_DECL int yasm_object_directive (yasm_object *object, const char *name, const char *parser, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams, unsigned long line)
 Handle a directive.
YASM_LIB_DECL void yasm_object_destroy (yasm_object *object)
 Delete (free allocated memory for) an object.
YASM_LIB_DECL void yasm_object_print (const yasm_object *object, FILE *f, int indent_level)
 Print an object.
YASM_LIB_DECL void yasm_object_finalize (yasm_object *object, yasm_errwarns *errwarns)
 Finalize an object after parsing.
YASM_LIB_DECL int yasm_object_sections_traverse (yasm_object *object, void *d, int(*func)(yasm_section *sect, void *d))
 Traverses all sections in an object, calling a function on each section.
YASM_LIB_DECL yasm_sectionyasm_object_find_general (yasm_object *object, const char *name)
 Find a general section in an object, based on its name.
YASM_LIB_DECL void yasm_object_set_source_fn (yasm_object *object, const char *src_filename)
 Change the source filename for an object.
YASM_LIB_DECL void yasm_object_set_global_prefix (yasm_object *object, const char *prefix)
 Change the prefix used for externally-visible symbols.
YASM_LIB_DECL void yasm_object_set_global_suffix (yasm_object *object, const char *suffix)
 Change the suffix used for externally-visible symbols.
YASM_LIB_DECL void yasm_object_optimize (yasm_object *object, yasm_errwarns *errwarns)
 Optimize an object.
YASM_LIB_DECL int yasm_section_is_code (yasm_section *sect)
 Determine if a section is flagged to contain code.
YASM_LIB_DECL unsigned long yasm_section_get_opt_flags (const yasm_section *sect)
 Get yasm_optimizer-specific flags.
YASM_LIB_DECL void yasm_section_set_opt_flags (yasm_section *sect, unsigned long opt_flags)
 Set yasm_optimizer-specific flags.
YASM_LIB_DECL int yasm_section_is_default (const yasm_section *sect)
 Determine if a section was declared as the "default" section (e.g.
YASM_LIB_DECL void yasm_section_set_default (yasm_section *sect, int def)
 Set section "default" flag to a new value.
YASM_LIB_DECL yasm_objectyasm_section_get_object (const yasm_section *sect)
 Get object owner of a section.
YASM_LIB_DECL void * yasm_section_get_data (yasm_section *sect, const yasm_assoc_data_callback *callback)
 Get assocated data for a section and data callback.
YASM_LIB_DECL void yasm_section_add_data (yasm_section *sect, const yasm_assoc_data_callback *callback, void *data)
 Add associated data to a section.
YASM_LIB_DECL void yasm_section_add_reloc (yasm_section *sect, yasm_reloc *reloc, void(*destroy_func)(void *reloc))
 Add a relocation to a section.
YASM_LIB_DECL yasm_relocyasm_section_relocs_first (yasm_section *sect)
 Get the first relocation for a section.
yasm_relocyasm_section_reloc_next (yasm_reloc *reloc)
 Get the next relocation for a section.
YASM_LIB_DECL void yasm_reloc_get (yasm_reloc *reloc, yasm_intnum **addrp, yasm_symrec **symp)
 Get the basic relocation information for a relocation.
YASM_LIB_DECL yasm_bytecodeyasm_section_bcs_first (yasm_section *sect)
 Get the first bytecode in a section.
YASM_LIB_DECL yasm_bytecodeyasm_section_bcs_last (yasm_section *sect)
 Get the last bytecode in a section.
YASM_LIB_DECL yasm_bytecodeyasm_section_bcs_append (yasm_section *sect, yasm_bytecode *bc)
 Add bytecode to the end of a section.
YASM_LIB_DECL int yasm_section_bcs_traverse (yasm_section *sect, yasm_errwarns *errwarns, void *d, int(*func)(yasm_bytecode *bc, void *d))
 Traverses all bytecodes in a section, calling a function on each bytecode.
YASM_LIB_DECL const char * yasm_section_get_name (const yasm_section *sect)
 Get name of a section.
YASM_LIB_DECL void yasm_section_set_align (yasm_section *sect, unsigned long align, unsigned long line)
 Change alignment of a section.
YASM_LIB_DECL unsigned long yasm_section_get_align (const yasm_section *sect)
 Get alignment of a section.
YASM_LIB_DECL void yasm_section_print (const yasm_section *sect, FILE *f, int indent_level, int print_bcs)
 Print a section.


Detailed Description

YASM section interface.

Definition in file section.h.


Typedef Documentation

typedef struct yasm_reloc yasm_reloc

Basic YASM relocation.

Object formats will need to extend this structure with additional fields for relocation type, etc.

Definition at line 44 of file section.h.


Function Documentation

YASM_LIB_DECL yasm_object* yasm_object_create ( const char *  src_filename,
const char *  obj_filename,
yasm_arch arch,
const yasm_objfmt_module objfmt_module,
const yasm_dbgfmt_module dbgfmt_module 
)

Create a new object.

A default section is created as the first section. An empty symbol table (yasm_symtab) and line mapping (yasm_linemap) are automatically created.

Parameters:
src_filename source filename (e.g. "file.asm")
obj_filename object filename (e.g. "file.o")
arch architecture
objfmt_module object format module
dbgfmt_module debug format module
Returns:
Newly allocated object, or NULL on error.

YASM_LIB_DECL void yasm_object_destroy ( yasm_object object  ) 

Delete (free allocated memory for) an object.

All sections in the object and all bytecodes within those sections are also deleted.

Parameters:
object object

YASM_LIB_DECL int yasm_object_directive ( yasm_object object,
const char *  name,
const char *  parser,
yasm_valparamhead valparams,
yasm_valparamhead objext_valparams,
unsigned long  line 
)

Handle a directive.

Passed down to object format, debug format, or architecture as appropriate.

Parameters:
object object
name directive name
parser parser keyword
valparams value/parameters
objext_valparams "object format-specific" value/parameters
line virtual line (from yasm_linemap)
Returns:
0 if directive recognized, nonzero if unrecognized.

YASM_LIB_DECL void yasm_object_finalize ( yasm_object object,
yasm_errwarns errwarns 
)

Finalize an object after parsing.

Parameters:
object object
errwarns error/warning set
Note:
Errors/warnings are stored into errwarns.

YASM_LIB_DECL yasm_section* yasm_object_find_general ( yasm_object object,
const char *  name 
)

Find a general section in an object, based on its name.

Parameters:
object object
name section name
Returns:
Section matching name, or NULL if no match found.

YASM_LIB_DECL yasm_section* yasm_object_get_general ( yasm_object object,
const char *  name,
unsigned long  align,
int  code,
int  res_only,
int *  isnew,
unsigned long  line 
)

Create a new, or continue an existing, general section.

The section is added to the object if there's not already a section by that name.

Parameters:
object object
name section name
align alignment in bytes (0 if none)
code if nonzero, section is intended to contain code (e.g. alignment should be made with NOP instructions, not 0)
res_only if nonzero, only space-reserving bytecodes are allowed in the section (ignored if section already exists)
isnew output; set to nonzero if section did not already exist
line virtual line of section declaration (ignored if section already exists)
Returns:
New section.

YASM_LIB_DECL void yasm_object_optimize ( yasm_object object,
yasm_errwarns errwarns 
)

Optimize an object.

Takes the unoptimized object and optimizes it. If successful, the object is ready for output to an object file.

Parameters:
object object
errwarns error/warning set
Note:
Optimization failures are stored into errwarns.

YASM_LIB_DECL void yasm_object_print ( const yasm_object object,
FILE *  f,
int  indent_level 
)

Print an object.

For debugging purposes.

Parameters:
object object
f file
indent_level indentation level

YASM_LIB_DECL int yasm_object_sections_traverse ( yasm_object object,
void *  d,
int(*)(yasm_section *sect, void *d)  func 
)

Traverses all sections in an object, calling a function on each section.

Parameters:
object object
d data pointer passed to func on each call
func function
Returns:
Stops early (and returns func's return value) if func returns a nonzero value; otherwise 0.

YASM_LIB_DECL void yasm_object_set_global_prefix ( yasm_object object,
const char *  prefix 
)

Change the prefix used for externally-visible symbols.

Parameters:
object object
prefix new prefix

YASM_LIB_DECL void yasm_object_set_global_suffix ( yasm_object object,
const char *  suffix 
)

Change the suffix used for externally-visible symbols.

Parameters:
object object
suffix new suffix

YASM_LIB_DECL void yasm_object_set_source_fn ( yasm_object object,
const char *  src_filename 
)

Change the source filename for an object.

Parameters:
object object
src_filename new source filename (e.g. "file.asm")

YASM_LIB_DECL void yasm_reloc_get ( yasm_reloc reloc,
yasm_intnum **  addrp,
yasm_symrec **  symp 
)

Get the basic relocation information for a relocation.

Parameters:
reloc relocation
addrp address of relocation within section (returned)
symp relocated symbol (returned)

YASM_LIB_DECL void yasm_section_add_data ( yasm_section sect,
const yasm_assoc_data_callback callback,
void *  data 
)

Add associated data to a section.

Attention:
Deletes any existing associated data for that data callback.
Parameters:
sect section
callback callback
data data to associate

YASM_LIB_DECL void yasm_section_add_reloc ( yasm_section sect,
yasm_reloc reloc,
void(*)(void *reloc)  destroy_func 
)

Add a relocation to a section.

Parameters:
sect section
reloc relocation
destroy_func function that can destroy the relocation
Note:
Does not make a copy of reloc. The same destroy_func must be used for all relocations in a section or an internal error will occur. The section will destroy the relocation address; it is the caller's responsibility to destroy any other allocated data.

YASM_LIB_DECL yasm_bytecode* yasm_section_bcs_append ( yasm_section sect,
yasm_bytecode bc 
)

Add bytecode to the end of a section.

Note:
Does not make a copy of bc; so don't pass this function static or local variables, and discard the bc pointer after calling this function.
Parameters:
sect section
bc bytecode (may be NULL)
Returns:
If bytecode was actually appended (it wasn't NULL or empty), the bytecode; otherwise NULL.

YASM_LIB_DECL yasm_bytecode* yasm_section_bcs_first ( yasm_section sect  ) 

Get the first bytecode in a section.

Parameters:
sect section
Returns:
First bytecode in section (at least one empty bytecode is always present).

YASM_LIB_DECL yasm_bytecode* yasm_section_bcs_last ( yasm_section sect  ) 

Get the last bytecode in a section.

Parameters:
sect section
Returns:
Last bytecode in section (at least one empty bytecode is always present).

YASM_LIB_DECL int yasm_section_bcs_traverse ( yasm_section sect,
yasm_errwarns errwarns,
void *  d,
int(*)(yasm_bytecode *bc, void *d)  func 
)

Traverses all bytecodes in a section, calling a function on each bytecode.

Parameters:
sect section
errwarns error/warning set (may be NULL)
d data pointer passed to func on each call (may be NULL)
func function
Returns:
Stops early (and returns func's return value) if func returns a nonzero value; otherwise 0.
Note:
If errwarns is non-NULL, yasm_errwarn_propagate() is called after each call to func (with the bytecode's line number).

YASM_LIB_DECL unsigned long yasm_section_get_align ( const yasm_section sect  ) 

Get alignment of a section.

Parameters:
sect section
Returns:
Alignment in bytes (0 if none).

YASM_LIB_DECL void* yasm_section_get_data ( yasm_section sect,
const yasm_assoc_data_callback callback 
)

Get assocated data for a section and data callback.

Parameters:
sect section
callback callback used when adding data
Returns:
Associated data (NULL if none).

YASM_LIB_DECL const char* yasm_section_get_name ( const yasm_section sect  ) 

Get name of a section.

Parameters:
sect section
Returns:
Section name.

YASM_LIB_DECL yasm_object* yasm_section_get_object ( const yasm_section sect  ) 

Get object owner of a section.

Parameters:
sect section
Returns:
Object this section is a part of.

YASM_LIB_DECL unsigned long yasm_section_get_opt_flags ( const yasm_section sect  ) 

Get yasm_optimizer-specific flags.

For yasm_optimizer use only.

Parameters:
sect section
Returns:
Optimizer-specific flags.

YASM_LIB_DECL int yasm_section_is_code ( yasm_section sect  ) 

Determine if a section is flagged to contain code.

Parameters:
sect section
Returns:
Nonzero if section is flagged to contain code.

YASM_LIB_DECL int yasm_section_is_default ( const yasm_section sect  ) 

Determine if a section was declared as the "default" section (e.g.

not created through a section directive).

Parameters:
sect section
Returns:
Nonzero if section was declared as default.

YASM_LIB_DECL void yasm_section_print ( const yasm_section sect,
FILE *  f,
int  indent_level,
int  print_bcs 
)

Print a section.

For debugging purposes.

Parameters:
f file
indent_level indentation level
sect section
print_bcs if nonzero, print bytecodes within section

yasm_reloc* yasm_section_reloc_next ( yasm_reloc reloc  ) 

Get the next relocation for a section.

Parameters:
reloc previous relocation
Returns:
Next relocation for section. NULL if no more relocations.

YASM_LIB_DECL yasm_reloc* yasm_section_relocs_first ( yasm_section sect  ) 

Get the first relocation for a section.

Parameters:
sect section
Returns:
First relocation for section. NULL if no relocations.

YASM_LIB_DECL void yasm_section_set_align ( yasm_section sect,
unsigned long  align,
unsigned long  line 
)

Change alignment of a section.

Parameters:
sect section
align alignment in bytes
line virtual line

YASM_LIB_DECL void yasm_section_set_default ( yasm_section sect,
int  def 
)

Set section "default" flag to a new value.

Parameters:
sect section
def new value of default flag

YASM_LIB_DECL void yasm_section_set_opt_flags ( yasm_section sect,
unsigned long  opt_flags 
)

Set yasm_optimizer-specific flags.

For yasm_optimizer use only.

Parameters:
sect section
opt_flags optimizer-specific flags.


Generated on Fri Jul 25 01:23:33 2008 for libyasm by  doxygen 1.5.2