| 1 | // |
| 2 | // ACME - a crossassembler for producing 6502/65c02/65816 code. |
| 3 | // Copyright (C) 1998-2006 Marco Baye |
| 4 | // Have a look at "acme.c" for further info |
| 5 | // |
| 6 | // Tree stuff |
| 7 | #ifndef tree_H |
| 8 | #define tree_H |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include "config.h" |
| 12 | |
| 13 | |
| 14 | // Macros for pre-defining tree node tables |
| 15 | #define PREDEFNODE(s, v) {NULL, NULL, 1, s, (void*) (v)} |
| 16 | #define PREDEFLAST(s, v) {NULL, NULL, 0, s, (void*) (v)} |
| 17 | |
| 18 | |
| 19 | // type definitions |
| 20 | |
| 21 | typedef unsigned int hash_t; |
| 22 | // Must be unsigned, otherwise the hash algorithm won't be very useful! |
| 23 | |
| 24 | // tree node structure type definition (for easy lookups) |
| 25 | struct node_t { |
| 26 | node_t* greater_than; // pointer to sub-tree |
| 27 | node_t* less_than_or_equal;// pointer to sub-tree |
| 28 | hash_t hash_value; |
| 29 | const char* id_string; // name, zero-terminated |
| 30 | void* body; // bytes, handles or handler function |
| 31 | }; |
| 32 | |
| 33 | // tree node structure type definition (for macros/labels) |
| 34 | struct node_ra_t { |
| 35 | node_ra_t* greater_than; // pointer to sub-tree |
| 36 | node_ra_t* less_than_or_equal;// pointer to sub-tree |
| 37 | hash_t hash_value; |
| 38 | char* id_string; // name, zero-terminated |
| 39 | void* body; // macro/label body |
| 40 | unsigned int id_number; // zone number |
| 41 | }; |
| 42 | |
| 43 | |
| 44 | // Prototypes |
| 45 | |
| 46 | // Add predefined tree items to given tree. |
| 47 | extern void Tree_add_table(node_t** tree, node_t* table_to_add); |
| 48 | // Search for a given ID string in a given tree. Store "Body" component in |
| 49 | // NodeBody and return TRUE. Return FALSE if no matching item found. |
| 50 | extern bool Tree_easy_scan(node_t* tree, void** node_body, struct dynabuf_t* dyna_buf); |
| 51 | // Search for a "RAM tree" item. Save pointer to found tree item in given |
| 52 | // location. If no matching item is found, check the "Create" flag: If set, |
| 53 | // create new tree item, link to tree, fill with data and store its pointer. |
| 54 | // If "Create" is clear, store NULL. Returns whether item was created. |
| 55 | extern bool Tree_hard_scan(node_ra_t**, node_ra_t**, int, bool); |
| 56 | // Calls given function for each node of each tree of given forest. |
| 57 | extern void Tree_dump_forest(node_ra_t**, int, void (*)(node_ra_t*, FILE*), FILE*); |
| 58 | |
| 59 | |
| 60 | #endif |