# Driver sources
DRIVERS ?= apc testapc
+# Debug Level
+DEBUG ?= 1
+
# Yacc
YACC := bison
YFLAGS ?= -v -d -Wall
# Rules
.SECONDEXPANSION:
$(ldTRG): $$(call ldDEP,$$@) | $(hGEN) ; $(call LDCMD,$^,$@)
-%-d.o: CFLAGS+= -Og -ggdb
+%-d.o: CFLAGS+= -Og -ggdb -DDEBUG=$(DEBUG)
%.o %-d.o: %.c $$(call cGENDEP,$$(dir $$@)%.c) ; $(call CCMD,$<,$@)
%.tab.h: %.tab.c ;
%.tab.c: %.y $$(call S2S,YCMD,%.y,$$@) ;
#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
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 %s\n", iter->name);\r
+ eprintf("Null set added to class %U\n", iter->name);\r
check:\r
if (bytes_identical(iter->name, name))\r
return iter;\r
)\r
{ struct ir_framedata_t* framedata = struct_alloc(ir_framedata_t);\r
if (name == NULL)\r
- eprint("Null name in set allocation\n");\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
( const uint8_t* name )\r
{ struct ir_simplex_t* audio = struct_alloc(ir_simplex_t);\r
if (name == NULL)\r
- eprint("Null audio\n");\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_class_t* class )\r
{ struct ir_classld_t* classld;\r
if (class == NULL)\r
- eprint("Null class in classld\n");\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
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
+#include <unistr.h>
#include "parser.tab.h"
#include "apc.h"
-#include <unistdio.h>
-#include <unistr.h>
+#include "print.h"
/* Public */
int lexer_init(void);
void lexer_quit(void);
YYSTYPE lval_stack[0xFF + 1];
static
uint8_t lval_offs;
+#define $($)#$
#define PUSHTOK(T,L) yypush_parse(pstate, T, (L), cstate)
-#define LEXTOK(T,Y,L) do { \
- lval_stack[lval_offs].Y = L; \
- PUSHTOK(T,lval_stack + lval_offs); \
- lval_offs++; \
- ntok++; \
+#define LEXTOK(T,Y,L) do { \
+ if (DEBUG) { \
+ ulc_fprintf(stdout, "["$(T)); \
+ switch (T) { \
+ case NAME: case PATH: \
+ ulc_fprintf(stdout, "->%U", L); break; \
+ case REF: \
+ ulc_fprintf(stdout, "->%X", L); break; \
+ default: break; \
+ } \
+ ulc_fprintf(stdout, "]"); \
+ } \
+ lval_stack[lval_offs].Y = L; \
+ PUSHTOK(T,lval_stack + lval_offs); \
+ lval_offs++; \
+ ntok++; \
} while (0)
#define PUSHFACE(F) LEXTOK(FACING, face, F)
#define PUSHREF(R) LEXTOK(REF, ref, R)
#define PUSHOP(O) LEXTOK(O, val, 0)
#define PUSHPATH(P) LEXTOK(PATH, str, P)
-#define DEBUG 1
-#define dprintf(_B, ...) do { \
- if(_B) printf(__VA_ARGS__); \
- } while (0)
-
-
/* Lexstring is the main lexer for APC and is generated by ragel. It lexes file names of files
that have been scanned and pushes their types and values into the tok_stack, which yyparse
eventually calls during parsing. */
action push_ref { errno = 0;
lval.ref = strtoll((char*)ts,NULL,16);
if (errno)
- { fprintf(stderr, "Invalid hex number in file %s\n",(char*)str);
+ { ulc_fprintf(stderr, "Invalid hex number in file %U\n",str);
exit(1);
}
PUSHREF(lval.ref);
action push_val { errno = 0;
lval.val = strtoll((char*)ts,NULL,10);
if (errno)
- { fprintf(stderr, "strtoll could not parse %s\n", (char*)str);
+ { ulc_fprintf(stderr, "strtoll could not parse %U\n",str);
exit(1);
}
PUSHNUM(lval.val);
}
- action push_name { dprintf(DEBUG, "Lexer_lexstring:: action:push_name: from %s to %s\n", ts, p);
- PUSHNAME(ts);
- }
- action push_map { dprintf(DEBUG, "Lexer_lexstring:: action:push_map: pushing map token\n");
- PUSHOP(MAP);
- }
- action set_ts { dprintf(DEBUG, "Lexer_lexstring:: action:set_ts. ts = %s\n", p);
- ts = p; }
- action push_SS { dprintf(DEBUG, "Lexer_lexstring:: action:push_SS. p = %s\n",p);
- PUSHOP(SS);
- }
- action push_S { dprintf(DEBUG, "Lexer_lexstring:: action:push_S. p = %s\n", p);
- PUSHFACE(SFACE);
- }
- action push_SW { dprintf(DEBUG, "Lexer_lexstring:: action:push_SW. p = %s\n", p);
- PUSHFACE(SWFACE);
- }
- action push_W { dprintf(DEBUG, "Lexer_lexstring:: action:push_W. p = %s\n", p);
- PUSHFACE(WFACE);
- }
- action push_NW { dprintf(DEBUG, "Lexer_lexstring:: action:push_NW. p = %s\n", p);
- PUSHFACE(NWFACE);
- }
- action push_N { dprintf(DEBUG, "Lexer_lexstring:: action:push_N. p = %s\n", p);
- PUSHFACE(NFACE);
- }
- action push_NE { dprintf(DEBUG, "Lexer_lexstring:: action:push_NE. p = %s\n", p);
- PUSHFACE(NEFACE);
- }
- action push_E { dprintf(DEBUG, "Lexer_lexstring:: action:push_N. p = %s\n", p);
- PUSHFACE(EFACE);
- }
- action push_SE { dprintf(DEBUG, "Lexer_lexstring:: action:push_N. p = %s\n", p);
- PUSHFACE(SEFACE);
- }
- action ref_error { dprintf(DEBUG, "ref from %s to %s has an inappropriate amount of hex digits, it must have eight.\n", ts, p);
+ action push_name { PUSHNAME(ts); }
+ action push_map { PUSHOP(MAP); }
+ action set_ts { ts = p; }
+ action push_SS { PUSHOP(SS); }
+ action push_S { PUSHFACE(SFACE); }
+ action push_SW { PUSHFACE(SWFACE); }
+ action push_W { PUSHFACE(WFACE); }
+ action push_NW { PUSHFACE(NWFACE); }
+ action push_N { PUSHFACE(NFACE); }
+ action push_NE { PUSHFACE(NEFACE); }
+ action push_E { PUSHFACE(EFACE); }
+ action push_SE { PUSHFACE(SEFACE); }
+ action ref_error { ulc_fprintf(stderr, "ref from %U to %U has an inappropriate amount of hex digits, it must have eight.\n", ts, p);
exit(1);
}
- action p { dprintf("Lexer_lexstring:: p = %s\n", p);
- }
+ action p { dprintf("Lexer_lexstring:: p = %U\n", p); }
N = 'N' %push_N;
W = 'W' %push_W;
cstate = yycstate_new();
lval_offs = 0;
return !pstate || !cstate;
+ return en_main == 1;
}
void lexer_quit
p = ts = str;
pe = eof = p + size + 1;
- dprintf("|---Begin lexstring on p = %s, pe = %s.\n", (char*)p, pe);
+ dprintf("\n|---Begin lexstring on p = %U, pe = %p.---|\n",p, pe);
%%write init;
%%write exec;
- dprintf("Ending lexstring of file %s, pushed %d tokens.\n", (char*)str, ntok);
+ dprintf("\n|---Ending lexstring of file %U, pushed %d tokens.---|\n",str, ntok);
return ntok;
}
*iter = '_';
PUSHPATH(filename);
return ntok + 1;
- return en_main == 1;
}
int lexer_lexdir
( uint8_t* dirname )
-{ uint8_t* de = dirname;
- int ntok;
+{ int ntok;
ntok = 0;
- de = dirname;
- if (*de) while (*++de);
- ntok = lexer_lexstring(dirname, (int)(de - dirname));
+ PUSHNAME(dirname);
PUSHOP(CLOPEN);
return ntok;
}
#define yyclassld(CS) (ir_classld_from_class(yyclass(CS)))
}
%define parse.error verbose
+%define parse.lac full
%define lr.type ielr
%define api.pure full
%define api.push-pull push
( yycstate* cs,
char const *s
)
-{ fprintf(stderr, "%s\n", s); }
+{ ir_class* iter;
+ for (iter = cs->class_stack; iter < cs->csp; iter++)
+ fprintf(stderr, "%s/", ir_class_name(*iter));
+ fprintf(stderr, "\n\t");
+ fprintf(stderr, "%s\n", s);
+}
yycstate* yycstate_new
( void )
static inline
ir_class yyclass_pop
( yycstate* cs )
-{ return *((cs->csp)--); }
+{ cs->csp--;
+ return *(cs->csp + 1);
+}
static inline
ir_class yyclass_push