#include <unistd.h> //u8_* functions\r
#include <unitypes.h> //uint8_t as a char\r
#include <unistr.h> //u32_cpy\r
+#include <unistdio.h> //ulc_fprintf\r
/* Local */\r
+#include "print.h"\r
#include "apc.h"\r
#include "ir.h"\r
+#undef do_error\r
+#define do_error(...) exit(-1)\r
/* Public */\r
int ir_init(void);\r
void ir_quit(void);\r
int ir_linker(void);\r
int ir_condenser(void);\r
/* Memory allocation structures */\r
-enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT };\r
struct pagenode_t;\r
struct pagenode_header_t {\r
struct pagenode_t* next;\r
struct pagenode_t* root, * head;\r
size_t pagesize;\r
};\r
+#define DATA_PAGESIZE (sys_pagesize)\r
+#define NAME_PAGESIZE (APC_NAME_MAX * 1024)\r
+#define PL_HEADERSIZE (sizeof(struct pagenode_header_t))\r
+#define PL_HEADSIZE(_PL) (_PL.head->header.head - _PL.head->root)\r
+#define PL_HEADMEM(_PL) (_PL.pagesize - PL_HEADERSIZE - PL_HEADSIZE(_PL))\r
+/* Set data mem */\r
+enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT };\r
struct ir_namelist_t;\r
struct ir_namelist_t\r
{ struct ir_namelist_t* nextsib;\r
long long ref;\r
struct ir_namelist_t* namelist, * namelist_head;\r
};\r
-/* Set data mem */\r
struct ir_setdata_header_t\r
{ enum dtype type;\r
uint8_t* src_filename, * data_name;\r
};\r
/* Functions */\r
static inline\r
-int init_pagelist(struct pagelist_t*,size_t);\r
-static inline\r
struct ir_framebox_t* ir_set_add_framebox(struct ir_set_t*,const uint8_t*);\r
+static inline\r
+union ir_setdata_t* ir_framedata (enum dtype,const uint8_t*,apc_facing,int,int);\r
+static inline\r
+int init_pagelist(struct pagelist_t*,size_t);\r
static\r
-void ir_free_pagenodes(struct pagenode_t*);\r
+void ir_free_pagenodes(struct pagenode_t*);\r
static inline\r
-int bytes_identical(const uint8_t*,const uint8_t*);\r
+int bytes_identical(const uint8_t*,const uint8_t*);\r
static\r
-void* stack_alloc(size_t);\r
+void* stack_alloc(size_t);\r
+#define struct_alloc(_T) ((struct _T*) stack_alloc(sizeof(struct _T)))\r
static\r
-uint8_t* name_alloc(const uint8_t*);\r
-static inline\r
-union ir_setdata_t* ir_framedata (enum dtype,const uint8_t*,apc_facing,int,int);\r
-/* Function-Like Macros */\r
-#define do_warn() do { \\r
- } while (0)\r
-#define wprint(str) do { \\r
- fprintf(stderr, str); \\r
- do_warn(); \\r
- } while (0)\r
-#define wprintf(fmt,...) do { \\r
- fprintf(stderr, fmt, __VA_ARGS__); \\r
- do_warn(); \\r
- } while (0)\r
-#define do_error() do { \\r
- exit(-1); \\r
- } while (0)\r
-#define eprint(str) do { \\r
- fprintf(stderr, str); \\r
- do_error(); \\r
- } while (0)\r
-#define eprintf(fmt,...) do { \\r
- fprintf(stderr, fmt, __VA_ARGS__); \\r
- do_error(); \\r
- } while (0)\r
-#define struct_alloc(_T) ((struct _T*) stack_alloc(sizeof(struct _T)))\r
-#define DATA_PAGESIZE (sys_pagesize)\r
-#define NAME_PAGESIZE (APC_NAME_MAX * 1024)\r
-#define PL_HEADERSIZE (sizeof(struct pagenode_header_t))\r
-#define PL_HEADSIZE(_PL) (_PL.head->header.head - _PL.head->root)\r
-#define PL_HEADMEM(_PL) (_PL.pagesize - PL_HEADERSIZE - PL_HEADSIZE(_PL))\r
-/* Memory */\r
+uint8_t* name_alloc(const uint8_t*);\r
extern //apc.c\r
-long sys_pagesize;\r
+long sys_pagesize;\r
static\r
struct pagelist_t datapages, namepages;\r
static\r
int ir_init\r
( void )\r
{ if (init_pagelist(&datapages, (size_t)DATA_PAGESIZE))\r
- eprint("Memory allocation error\n");\r
+ eprintf("Memory allocation error\n");\r
if (init_pagelist(&namepages, (size_t)NAME_PAGESIZE))\r
- eprint("Memory allocation error\n");\r
+ eprintf("Memory allocation error\n");\r
return 0;\r
}\r
\r
( void )\r
{ return 0; }\r
\r
+/* Return the class's name string */\r
+uint8_t* ir_class_name\r
+( struct ir_class_t* class )\r
+{ return class->name; }\r
+\r
/* Return a pointer to the root class */\r
struct ir_class_t* ir_class_root\r
( void )\r
)\r
{ struct ir_class_t* iter;\r
if (class->nextchild == NULL)\r
- return class->nextchild = struct_alloc(ir_class_t);\r
+ goto alloc;\r
iter = class->nextchild;\r
+ if (iter->name == NULL)\r
+ eprintf("Null name pointer in class %p\n", iter);\r
+ if (name == NULL)\r
+ eprintf("Null child added to class %s\n", iter->name);\r
check:\r
if (bytes_identical(iter->name, name))\r
return iter;\r
{ iter = iter->nextsib;\r
goto check;\r
}\r
+ alloc:\r
iter = struct_alloc(ir_class_t);\r
iter->nextsib = class->nextchild;\r
iter->name = name_alloc(name);\r
)\r
{ struct ir_set_t* iter;\r
if (class->root_set == NULL)\r
- return class->root_set = struct_alloc(ir_set_t);\r
+ goto alloc;\r
iter = class->root_set;\r
+ if (iter->name == NULL)\r
+ eprintf("Null name pointer in class %p\n", iter);\r
+ if (name == NULL)\r
+ eprintf("Null set added to class %U\n", iter->name);\r
check:\r
if (bytes_identical(iter->name, name))\r
return iter;\r
{ iter = iter->nextsib;\r
goto check;\r
}\r
+ alloc:\r
iter = struct_alloc(ir_set_t);\r
iter->nextsib = class->root_set;\r
iter->name = name_alloc(name);\r
)\r
{ struct ir_set_t* iter;\r
if (set->nextchild == NULL)\r
- return set->nextchild = struct_alloc(ir_set_t);\r
+ goto alloc;\r
iter = set->nextchild;\r
+ if (iter->name == NULL)\r
+ eprintf("Null name pointer in set %p\n", iter);\r
+ if (name == NULL)\r
+ eprintf("Null child added to set %s\n", iter->name);\r
check:\r
if (bytes_identical(iter->name, name))\r
return iter;\r
{ iter = iter->nextsib;\r
goto check;\r
}\r
+ alloc:\r
iter = struct_alloc(ir_set_t);\r
iter->nextsib = set->nextchild;\r
iter->name = name_alloc(name);\r
)\r
{ struct ir_framebox_t* iter;\r
if (set->frameboxes == NULL)\r
- return set->frameboxes = struct_alloc(ir_framebox_t);\r
+ goto alloc;\r
iter = set->frameboxes;\r
check:\r
if (bytes_identical(iter->header.data_name, name))\r
{ iter = (struct ir_framebox_t*) iter->header.nextsib;\r
goto check;\r
}\r
+ alloc:\r
iter = struct_alloc(ir_framebox_t);\r
iter->header.nextsib = (union ir_setdata_t*) set->frameboxes;\r
iter->header.data_name = name_alloc(name);\r
( union ir_setdata_t* setdata,\r
const uint8_t* path\r
)\r
-{ if (setdata->header.src_filename != NULL)\r
+{ if (path == NULL)\r
+ eprintf("Null path in data %s\n", setdata->header.data_name);\r
+ if (setdata->header.src_filename != NULL)\r
wprintf("Path override: %s -> %s for setdata %s\n",\r
setdata->header.src_filename, path, setdata->header.data_name);\r
setdata->header.src_filename = name_alloc(path);\r
int height\r
)\r
{ struct ir_framedata_t* framedata = struct_alloc(ir_framedata_t);\r
+ if (name == NULL)\r
+ eprintf("Null name in set allocation\n");\r
framedata->header.type = type;\r
framedata->header.data_name = name_alloc(name);\r
framedata->frameinfo.facing = d;\r
union ir_setdata_t* ir_audio\r
( const uint8_t* name )\r
{ struct ir_simplex_t* audio = struct_alloc(ir_simplex_t);\r
+ if (name == NULL)\r
+ eprintf("Null audio\n");\r
audio->header.type = ADAT;\r
audio->header.data_name = name_alloc(name);\r
return (union ir_setdata_t*) audio;\r
struct ir_classld_t* ir_classld_from_class\r
( struct ir_class_t* class )\r
{ struct ir_classld_t* classld;\r
+ if (class == NULL)\r
+ eprintf("Null class in classld\n");\r
classld = struct_alloc(ir_classld_t);\r
classld->root_class = class;\r
return classld;\r
if (PL_HEADMEM(datapages) < bytes) \r
{ datapages.head->header.next = (struct pagenode_t*) calloc(datapages.pagesize,1);\r
if (datapages.head->header.next == NULL)\r
- eprint("Memory allocation error \n");\r
+ eprintf("Memory allocation error \n");\r
datapages.head = datapages.head->header.next; \r
datapages.head->header.head = datapages.head->root;\r
}\r
if (head_mem == 0) //not enough room\r
{ namepages.head->header.next = (struct pagenode_t*) calloc(namepages.pagesize,1);\r
if (namepages.head->header.next == NULL)\r
- eprint("Memory allocation error\n");\r
+ eprintf("Memory allocation error\n");\r
namepages.head = namepages.head->header.next;\r
namepages.head->header.head = namepages.head->root;\r
goto copy;\r