X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=blobdiff_plain;f=src%2Fir.c;h=10c053efd498bfe25aff8c6f195a42867dcf33dd;hp=ac47a8584b796c7f3b4bb350955c585610a276e0;hb=2adb4f588fa1a6a16876af1bfaeebebc8bbbc748;hpb=81be40c7e131efbb3300d948ee17d05a9910205e diff --git a/src/ir.c b/src/ir.c index ac47a85..10c053e 100644 --- a/src/ir.c +++ b/src/ir.c @@ -17,12 +17,11 @@ #include //u32_cpy #include //ulc_fprintf /* Local */ +#define eprintf_callback(...) exit(EXIT_FAILURE) #include "print.h" #include "apc.h" #include "ir.h" #include "pagenode.h" -#undef do_error -#define do_error(...) exit(-1) #define XXH_PRIVATE_API #include "../xxHash/xxhash.h" /* Public */ @@ -44,13 +43,14 @@ struct ir_classld_t }; struct ir_setld_t { struct ir_classld_t* classld; - long long ref; + uint32_t ref; struct ir_namelist_t* namelist, * namelist_head; }; struct ir_setdata_header_t { enum dtype type; uint8_t* src_filename, * data_name; union ir_setdata_t* nextsib; + long filepos; }; struct ir_framedata_t { struct ir_setdata_header_t header; @@ -66,6 +66,7 @@ struct ir_link_t { struct ir_setdata_header_t header; struct ir_classld_t* classld; struct ir_setld_t* setld; + struct ir_set_t* trg_set; enum ltype type; }; union ir_setdata_t @@ -80,6 +81,7 @@ struct ir_class_t { struct ir_class_t* nextchild, * nextsib; struct ir_set_t* root_set; uint8_t* name; + long filepos; }; struct ir_set_t { struct ir_set_t* nextchild, * nextsib; @@ -88,7 +90,7 @@ struct ir_set_t struct ir_framebox_t* frameboxes; struct ir_simplex_t* audio; struct ir_link_t* links; - long filepos; + long filepos; }; /* Functions */ static inline @@ -96,6 +98,8 @@ struct ir_framebox_t* ir_set_add_framebox(struct ir_set_t*,uint8_t*); static inline union ir_setdata_t* ir_framedata (enum dtype,const uint8_t*,apc_facing,int,int); static inline +void ir_linkdata_resolve_set(union ir_setdata_t*); +static inline int bytes_identical(const uint8_t*,const uint8_t*); static inline int classnames_identical(const uint8_t*,const uint8_t*); @@ -108,10 +112,12 @@ uint8_t* classname_alloc(const uint8_t*); #define struct_alloc(_T) ((struct _T*) stack_alloc(&datapages, sizeof(struct _T))) extern //apc.c long sys_pagesize; +extern //apc.c +char* apc_package_name; static struct pagelist_t datapages, namepages, refhashpages; static -struct ir_class_t root_class = { .name = (uint8_t*)"." }; +struct ir_class_t root_class; /* Init */ int ir_init @@ -119,7 +125,7 @@ int ir_init { pagelist_init(datapages, (size_t)SYS_PAGESIZE); pagelist_init(namepages, (size_t)NAME_PAGESIZE); pagelist_init(refhashpages, (size_t)SYS_PAGESIZE); - + root_class.name = (uint8_t*) apc_package_name; return 0; } @@ -220,6 +226,11 @@ struct ir_set_t* ir_class_addset return iter->nextsib; } +/* Get the root set of the class */ +struct ir_set_t* ir_class_rootset +( struct ir_class_t* class ) +{ return class->root_set; } + struct ir_set_t* ir_set_from_ref ( uint32_t ref ) { uint16_t hash; @@ -328,6 +339,55 @@ int classnames_identical return (ca == cb); } +/* Return the name of the set */ +uint8_t* ir_set_name +( struct ir_set_t* set) +{ return set->name; } + +/* Return the next sib of the class */ +struct ir_class_t* ir_class_nextsib +( struct ir_class_t* class ) +{ return class->nextsib; } + +/* Return the next sib of the class */ +struct ir_class_t* ir_class_nextchild +( struct ir_class_t* class ) +{ return class->nextchild; } + +/* Get the file position of the class */ +long ir_class_fpos +( struct ir_class_t* class ) +{ return class->filepos; } + +/* Set the file position of the class */ +void ir_class_assign_fpos +( struct ir_class_t* class, + long newpos +) +{ class->filepos = newpos; } + +/* Get the next sibling of the provided set */ +struct ir_set_t* ir_set_nextsib +( struct ir_set_t* set ) +{ return set->nextsib; } + +/* Get the next child of the provided set */ +struct ir_set_t* ir_set_nextchild +( struct ir_set_t* set ) +{ return set->nextchild; } + +/* Get the file position of the class */ +long ir_set_fpos +( struct ir_set_t* set ) +{ return set->filepos; } + +/* Set the file position of the class */ +void ir_set_assign_fpos +( struct ir_set_t* set, + long newpos +) +{ set->filepos = newpos; } + /* Assign Setdata to Set */ void ir_set_assign_data ( struct ir_set_t* set, @@ -544,7 +604,196 @@ union ir_setdata_t* ir_link return (union ir_setdata_t*) link; } +/* Return a set's root framebox */ +union ir_setdata_t* ir_set_framebox +( struct ir_set_t* set ) +{ return (union ir_setdata_t*) set->frameboxes; } + +/* Return a set's root audio data */ +union ir_setdata_t* ir_set_audio +( struct ir_set_t* set ) +{ return (union ir_setdata_t*) set->audio; } + +/* Return a set's root link data */ +union ir_setdata_t* ir_set_link +( struct ir_set_t* set ) +{ return (union ir_setdata_t*) set->links; } + +#define assert_link(linkdata) do { \ + if (linkdata->header.type != LDAT) \ + eprintf("Data %s is not a link\n", linkdata->header.data_name); \ + } while (0) + +/* Return the link type */ +enum ltype ir_linkdata_type +( union ir_setdata_t* linkdata ) +{ assert_link(linkdata); + return linkdata->link.type; +} + +/* Return the link type */ +uint32_t ir_linkdata_ref +( union ir_setdata_t* linkdata ) +{ assert_link(linkdata); + return linkdata->link.setld->ref; +} + +/* Return the current target set, resolving it first if not present */ +struct ir_set_t* ir_linkdata_set +( union ir_setdata_t* linkdata ) +{ assert_link(linkdata); + if (linkdata->link.trg_set == NULL) + ir_linkdata_resolve_set(linkdata); + return linkdata->link.trg_set; +} + +/* Resolve and assign the link's target set */ +static inline +void ir_linkdata_resolve_set +( union ir_setdata_t* linkdata ) +{ struct ir_class_t* class_iter; + struct ir_namelist_t* namelist_iter,* namelist_iter_last; + struct ir_setld_t* setld; + struct ir_classld_t* classld; + struct ir_set_t* set; + set = NULL; + class_iter = NULL; + assert_link(linkdata); + setld = linkdata->link.setld; + if (linkdata->link.setld == NULL) + eprintf("Link data is invalid\n"); + classld = linkdata->link.classld; + if (classld != NULL) + { namelist_iter = classld->namelist; + if (classld->root_class == NULL) + eprintf("No root class for classld\n"); + class_iter = classld->root_class->nextchild; + namelist_iter_last = NULL; + while (class_iter != NULL) + { if (classnames_identical(class_iter->name, namelist_iter->name)) + { if (namelist_iter == classld->namelist_head) + break; + class_iter = class_iter->nextchild; + namelist_iter_last = namelist_iter; + namelist_iter = namelist_iter->nextsib; + } + else + class_iter = class_iter->nextsib; + } + if (class_iter == NULL) + { if (namelist_iter_last) + eprintf("No such subclass \"%s\" of class \"%s\"\n", + namelist_iter->name, + namelist_iter_last->name); + else + eprintf("No such class \"%s\"\n", namelist_iter->name); + } + set = class_iter->root_set; + } + else + set = ir_set_from_ref(setld->ref); + if (set == NULL) + eprintf("Initial set resolution failed\n"); + namelist_iter = setld->namelist; + namelist_iter_last = NULL; + if (setld->namelist != NULL) + { while (set != NULL) + { if (bytes_identical(set->name, namelist_iter->name)) + { if (namelist_iter == setld->namelist_head) + break; + set = set->nextchild; + namelist_iter_last = namelist_iter; + namelist_iter = namelist_iter->nextsib; + } + else + set = set->nextsib; + } + if (set == NULL) + { if (namelist_iter_last) + eprintf("No such subset \"%s\" of set \"%s\"\n", + namelist_iter->name, + namelist_iter_last->name); + else + eprintf("No such set \"%s\" in class \"%s\"\n", + namelist_iter->name, + class_iter->name); + } + } + linkdata->link.trg_set = set; +} + +/* Assign a linkdatas trg_set */ +void ir_linkdata_assign_set +( struct ir_link_t* link, struct ir_set_t* set ) +{ link->trg_set = set; } + +/* Assign a linkdatas type */ +void ir_linkdata_assign_type +( struct ir_link_t* link, ltype type; ) +{ link->type = type; } + +/* Get a setdata's next sibling */ +union ir_setdata_t* ir_setdata_nextsib +( union ir_setdata_t* setdata ) +{ return setdata->header.nextsib; } + +/* Get a setdata's name */ +uint8_t* ir_setdata_name +( union ir_setdata_t* setdata ) +{ return setdata->header.data_name; } + +/* Get a setdata's filename */ +uint8_t* ir_setdata_filename +( union ir_setdata_t* setdata ) +{ return setdata->header.src_filename; } + +/* Get a setdata's file position */ +long ir_setdata_fpos +( union ir_setdata_t* setdata ) +{ return setdata->header.filepos; } + +/* Set a setdata's file position */ +void ir_setdata_assign_fpos +( union ir_setdata_t* setdata, + long newpos +) +{ setdata->header.filepos = newpos; } + +/* Assign a setdatas name */ +void ir_setdata_assign_name +( union ir_setdata_t* setdata, uint8_t* name ) +{ setdata->header.data_name = name;} + +/* Return a framebox's specified framesheet */ +union ir_setdata_t* ir_framebox_framesheet +( union ir_setdata_t* fbox, + apc_facing facing +) +{ if (fbox->header.type != FBDAT) + eprintf("Data %s is not a framebox\n", fbox->header.data_name); + return (union ir_setdata_t*) &fbox->framebox.framesheets[facing]; +} + +/* Return a framebox's specified mapsheet */ +union ir_setdata_t* ir_framebox_mapsheet +( union ir_setdata_t* fbox, + apc_facing facing +) +{ if (fbox->header.type != FBDAT) + eprintf("Data %s is not a framebox\n", fbox->header.data_name); + return (union ir_setdata_t*) &fbox->framebox.mapsheets[facing]; +} + +/* Return a framedata's frame info */ +struct ir_frameinfo_t* ir_framedata_frameinfo +( union ir_setdata_t* framedata ) +{ if (framedata->header.type != MSDAT && framedata->header.type != FSDAT) + eprintf("Data %s is not a framedata\n", framedata->header.data_name); + return &framedata->mapsheet.frameinfo; +} + +/** Allocators **/ static uint8_t* name_alloc ( const uint8_t* name_src ) @@ -586,13 +835,15 @@ uint8_t* classname_alloc static void crawl_class(struct ir_class_t*); static void crawl_set(struct ir_set_t*,int); +extern +int binout_init(ir_class); void ir_test(void) { uprintf("IR From Directory: %s\n",getcwd(NULL,255)); crawl_class(&root_class); if (root_class.root_set != NULL) crawl_set(root_class.root_set, 0); uprintf("starting binaryout \n"); - ir_binout_init(&root_class); + binout_init(&root_class); }