buildtree.c

Builds a tree from an opcode map

Author

Marcel Sondaar

License

Public Domain

Summary
buildtree.cBuilds a tree from an opcode map
Functions
LibGFX_recursetreerecursive helper function for building a tree from an opcode map

Functions

LibGFX_recursetree

static int LibGFX_recursetree(int node,
AST_Node **tempmap,
AST_RawOpcodeMap *rawmap,
int maxnode)

recursive helper function for building a tree from an opcode map

This function takes the current root, and the list of pregenerated nodes, then fills in the node in question if it hasn’t been visited yet, silently return when the node is reachable from two sides, and complain if a cyclic dependency was detected or if the opcode map contains bogus data.

upon succesful return, the node requested is converted in a proper acyclic graph, with all properties set accordingly. upon failure, the states are undefined, except that node->children may have got a valid pointer assigned. it is required that node->children = NULL and node->refcount = 0 upon entry because cleanup becomes impossible otherwise.  (this function does not do it) also, node->operatorindex must be correctly set for each node in tempmap

in

nodethe current operator index
tempmapa list of pregenerated node pointers for each entry
rawmapthe original raw opcode map
maxnodethe amount of nodes preallocated, used in bounds checking

out

return0 on success, 1 on failure.
<libgfx_errormsg>altered on failure.
static int LibGFX_recursetree(int node,
AST_Node **tempmap,
AST_RawOpcodeMap *rawmap,
int maxnode)
recursive helper function for building a tree from an opcode map