From: Jordan Date: Fri, 14 Oct 2016 21:06:00 +0000 (-0700) Subject: updating ir X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fwebcc.git;a=commitdiff_plain;h=5204a4831d3ed34270d5fbb260aece8194c859e5 updating ir --- diff --git a/src/apc/ir.c b/src/apc/ir.c old mode 100644 new mode 100755 index f47e25a..421f6e5 --- a/src/apc/ir.c +++ b/src/apc/ir.c @@ -1,465 +1,465 @@ -/*!@file - \brief IR Memory Implementation - \details Intermediary memory management - \author Jordan Lavatai - \date Aug 2016 - ----------------------------------------------------------------------------*/ -#include -#include -#include //uint64_t -#include //memmove -#include //malloc -#include - - - -/* functions needed from irmem.c */ -extern -void -ir_init(void); - -extern -struct cdat* -alloc_cdat(void); - -extern -struct odat* -alloc_odat(void); - -extern -void -alloc_vdat(void); - -extern -struct link* -alloc_link(void); - -extern -struct ref* -alloc_ref(void); - -extern -struct cdat* -curr_cdat(void); - -extern -struct odat* -curr_odat(void); - -extern -struct vdat* -curr_vdat(void); - -extern -struct set* -curr_set(void); - -extern -struct ref* -curr_ref(void); - -extern -struct quad* -curr_quad(void); - -extern -struct model* -curr_model(void); - -/* struct definitions needed from irmem.c */ -extern int num_cdats; -extern struct cdat** cdat_stackp; -extern struct odat* curr_set_odatp; -extern uint64_t ss_ref_id; - -extern int num_vdats; -/* Dynamically allocate memory for a class data structure, - or cdat, after a class has been identified in a grammar. - We also create a stack of class pointers so that - we can access the cdat during processing of that - cdats sets and elements, a requirement because the - nature of recursive classes prevents us from accessing - the cdat based on the previous index into cdat_buf, - which is a list of all allocated cdats*/ -void -push_cdat -( char* name -) -{ - struct cdat* curr_cdatp; - - curr_cdatp = alloc_cdat(); - - memmove(curr_cdatp->name, name, 32); - curr_cdatp->idx = num_cdats; - - /* Set the cdat as a subclass of the previous cdat */ - (*cdat_stackp)->class_list[(*cdat_stackp)->num_classes] = curr_cdatp; - /* Push the cdat onto the cdat_stack */ - *++cdat_stackp = curr_cdatp; - -} - -void -pop_cdat -() -{ - cdat_stackp--; -} - -/* Called in the reduction of a set. While both odats (eles and sets) - have identical label terminals, we are unable to give a single grammatical rule - for both due to how we allocate odats in the odat buf. Due to the - nature of bottom up parsing, the set label is recognized first, and then the - sets elements are recognized. This means that after we have processed the sets elemenets, - the curr_odat is going to be the last element and NOT the set that was first allocated. - To get around this, we create a global variable set_odatp that will store the pointer - to the odat when it is first allocated (in insert_set_label()) so that insert_set() can - have access to it. Curr set points the sets representation in the cdat, curr_set_odatp - points to the sets representation as an odat*/ - -void -insert_set_label -( char* name, - uint64_t ref_id -) -{ - - struct set* curr_setp; - - curr_setp = curr_set(); - curr_set_odatp = alloc_odat(); - - memmove(curr_set_odatp->name, name, 32); - memmove(curr_setp->name, name, 32); - - if(ref_id != -1) - { curr_set_odatp->ref_id = ref_id; - curr_setp->ref_id = ref_id; - } - else - { curr_setp->ref_id = ss_ref_id; - curr_set_odatp->ref_id = ss_ref_id++; - } - -} - -/* Inserting a olink instead of a set. Set is really just a placeholder - for another set. Allocate the memory for the set so taht it can be populated*/ -void -insert_set_olink -( uint64_t ref_id -) -{ - struct set* curr_setp; - - curr_setp = curr_set(); - - curr_setp->ref_id = ref_id; - -} - -void -insert_set_vlink -( uint64_t ref_id, - char* anim_name -) -{ - struct cdat* curr_cdatp; - struct odat* curr_odatp; - struct link* curr_linkp; - - - curr_cdatp = curr_cdat(); - curr_odatp = curr_odat(); - curr_linkp = alloc_link(); - - /* Insert vlink into link_stack so that it gets processed at - output time */ - curr_linkp->type = 2; - /* Store the target odat information*/ - curr_linkp->link_t.vlink.ref_id = ref_id; - memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32); - /* Store the linking odat/cdat information */ - curr_linkp->classp = curr_cdatp; - curr_linkp->odatp = curr_odatp; - curr_linkp->set_idx = curr_cdatp->num_sets; - curr_linkp->ele_idx = -1; - -} - -/* Svlinks dont have animation names */ -void -insert_set_svlink -( uint64_t ref_id -) -{ - struct cdat* curr_cdatp; - struct link* curr_linkp; - - curr_cdatp = curr_cdat(); - curr_linkp = alloc_link(); - - /* Insert svlink into link_stack so that it gets processed at - output time */ - curr_linkp->type = 3; - curr_linkp->classp = curr_cdatp; - curr_linkp->set_idx = curr_cdatp->num_sets; - curr_linkp->ele_idx = -1; - curr_linkp->link_t.svlink.ref_id = ref_id; - -} - -/* At the point of reducing to a set, most of the - sets odat information has already been populated - during the reduction of its right hand side - non terminals (hitbox, root, quad_list). */ -void -insert_set -() -{ uint64_t ref_id; - struct odat* curr_odatp; - struct cdat* curr_cdatp; - struct set* curr_setp; - struct ref* prev_refp; - struct ref* curr_refp; - struct vdat* curr_vdatp; - - curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space - curr_cdatp = curr_cdat(); - curr_setp = curr_set(); - prev_refp = curr_ref(); - curr_refp = alloc_ref(); - curr_vdatp = curr_vdat(); - - curr_vdatp->creator = curr_set_odatp; - - curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx? - memmove(curr_setp->name, curr_odatp->name, 32); - curr_cdatp->num_sets++; - - curr_odatp->cdat_idx = curr_cdatp->idx; - curr_odatp->refp = curr_refp; - - ref_id = curr_setp->ref_id; // ref_id set by insert_set_label(name, ref_id) - - curr_refp->ref_id = ref_id; - curr_refp->lastref = prev_refp; - curr_refp->odatp = curr_odatp; - prev_refp->nextref = curr_refp; - - - -} -/* Created as a seperate function, instead of setting the ODATS vdat_id and - calling inc_vdat() inside of insert_set(), to account for the set reduction - where a vdat is not created (o/v/svlinks). */ -void -insert_set_vdatid -() -{ - struct vdat* curr_vdatp; - - curr_vdatp = curr_vdat(); - - curr_set_odatp->vdat_id = num_vdats; //no vdat_id for odats that have vlinks/svlinks - curr_set_odatp->vdatp = curr_vdatp; - curr_set_odatp = NULL; //This sets odat shouldnt be modified after populating odats vdat info -} - -/* Populates the odat name and ref_id for odat, allocate the odat here for the rest of - the functions to use via curr_odat(). */ -void -insert_ele_label -( char* name, - uint64_t ref_id -) -{ - struct odat* curr_odatp; - - curr_odatp = alloc_odat(); - - memmove(curr_odatp->name, name, 32); - - if(ref_id != -1) - curr_odatp->ref_id = ref_id; - else - curr_odatp->ref_id = ss_ref_id++; - -} - -/* We don't make an odat here, at output time we will resolve - the ref_id to the corresponding odat. */ -void -insert_ele_olink -( uint64_t ref_id -) -{ - /* Do nothing because we already know the ref_id that - the odat needs for this element (in the quad_file) */ -} - -void -insert_ele_vlink -( uint64_t ref_id, - char* anim_name -) -{ - struct cdat* curr_cdatp; - struct set* curr_setp; - struct link* curr_linkp; - - curr_cdatp = curr_cdat(); - curr_setp = curr_set(); - curr_linkp = alloc_link(); - - /* Insert vlink into link_stack so that it gets processed at - output time */ - curr_linkp->classp = curr_cdatp; - curr_linkp->type = 2; - curr_linkp->set_idx = curr_cdatp->num_sets; - //curr_linkp->ele_idx = curr_setp->num_ele; - curr_linkp->link_t.vlink.ref_id = ref_id; - memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32); - -} - -void -insert_ele_svlink -( uint64_t ref_id -) -{ - struct cdat* curr_cdatp; - struct set* curr_setp; - struct link* curr_linkp; - - curr_cdatp = curr_cdat(); - curr_setp = curr_set(); - curr_linkp = alloc_link(); - - curr_linkp->classp = curr_cdatp; - curr_linkp->type = 3; - - //curr_linkp->ele_idx = curr_setp->num_ele; - curr_linkp->link_t.svlink.ref_id = ref_id; - - -} - -//Insert element into odat_buf and cdatpages -void -insert_ele() -{ - uint64_t ref_id; - struct cdat* curr_cdatp; - struct odat* curr_odatp; - struct vdat* curr_vdatp; - struct set* curr_setp; - struct ele* curr_elep; - struct ref* curr_refp; - struct ref* prev_refp; - - - curr_odatp = curr_odat(); //malloced @ insert_ele_label - curr_vdatp = curr_vdat(); - curr_setp = curr_set(); - prev_refp = curr_ref(); - curr_refp = alloc_ref(); - - curr_vdatp->creator = curr_odatp; - - /* Populate odat for ele */ - curr_odatp->cdat_idx = curr_cdatp->idx; - curr_odatp->refp = curr_refp; - - ref_id = curr_odatp->ref_id; - - curr_refp->ref_id = ref_id; - curr_refp->lastref = prev_refp; - curr_refp->odatp = curr_odatp; - prev_refp->nextref = curr_refp; - -} - -void -insert_ele_vdatid -() -{ struct odat* curr_odatp; - curr_odatp = curr_odat(); - curr_odatp->vdat_id = num_vdats; -} - -void -insert_quad -( void* quad_filep -) -{ - struct odat* curr_odatp; - - curr_odatp->quad_filep = quad_filep; -} - -/* Inserting the hitbox into the set - odat. Elements that don't have - a hitbox will use the sets root. */ -void -insert_hitbox -( int hitbox -) -{ struct odat* curr_odatp; - - curr_odatp = curr_odat(); - curr_odatp->hitbox = hitbox; -} - -/* Inserting the root into the set - odat. Elements that don't have - a root will use the sets root. */ -void -insert_root -( int x, - int y, - int z -) -{ struct odat* curr_odatp; - - curr_odatp = curr_odat(); - curr_odatp->root.x = x; - curr_odatp->root.y = y; - curr_odatp->root.z = z; -} - - -void -insert_framesheet -( char direction, - char* name, - uint64_t ref_id, - int height , - int width, - int num_frames -) -{ struct vdat* curr_vdatp; - struct model* curr_modelp; - - curr_vdatp = curr_vdat(); - curr_modelp = curr_model(); - - curr_modelp->spritesheet[(int)direction].height = height; - curr_modelp->spritesheet[(int)direction].width = width; - curr_modelp->spritesheet[(int)direction].num_frames = num_frames; - curr_vdatp->num_models++; -} - -void -insert_frame_pointer -( char direction, - void* frame -) -{ struct model* curr_modelp; - - curr_modelp = curr_model(); - - curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame; -} - +/*!@file + \brief IR Memory Implementation + \details Intermediary memory management + \author Jordan Lavatai + \date Aug 2016 + ----------------------------------------------------------------------------*/ +#include +#include +#include //uint64_t +#include //memmove +#include //malloc +#include + + + +/* functions needed from irmem.c */ +extern +void +ir_init(void); + +extern +struct cdat* +alloc_cdat(void); + +extern +struct odat* +alloc_odat(void); + +extern +void +alloc_vdat(void); + +extern +struct link* +alloc_link(void); + +extern +struct ref* +alloc_ref(void); + +extern +struct cdat* +curr_cdat(void); + +extern +struct odat* +curr_odat(void); + +extern +struct vdat* +curr_vdat(void); + +extern +struct set* +curr_set(void); + +extern +struct ref* +curr_ref(void); + +extern +struct quad* +curr_quad(void); + +extern +struct model* +curr_model(void); + +/* struct definitions needed from irmem.c */ +extern int num_cdats; +extern struct cdat** cdat_stackp; +extern struct odat* curr_set_odatp; +extern uint64_t ss_ref_id; + +extern int num_vdats; +/* Dynamically allocate memory for a class data structure, + or cdat, after a class has been identified in a grammar. + We also create a stack of class pointers so that + we can access the cdat during processing of that + cdats sets and elements, a requirement because the + nature of recursive classes prevents us from accessing + the cdat based on the previous index into cdat_buf, + which is a list of all allocated cdats*/ +void +push_cdat +( char* name +) +{ + struct cdat* curr_cdatp; + + curr_cdatp = alloc_cdat(); + + memmove(curr_cdatp->name, name, 32); + curr_cdatp->idx = num_cdats; + + /* Set the cdat as a subclass of the previous cdat */ + (*cdat_stackp)->class_list[(*cdat_stackp)->num_classes] = curr_cdatp; + /* Push the cdat onto the cdat_stack */ + *++cdat_stackp = curr_cdatp; + +} + +void +pop_cdat +() +{ + cdat_stackp--; +} + +/* Called in the reduction of a set. While both odats (eles and sets) + have identical label terminals, we are unable to give a single grammatical rule + for both due to how we allocate odats in the odat buf. Due to the + nature of bottom up parsing, the set label is recognized first, and then the + sets elements are recognized. This means that after we have processed the sets elemenets, + the curr_odat is going to be the last element and NOT the set that was first allocated. + To get around this, we create a global variable set_odatp that will store the pointer + to the odat when it is first allocated (in insert_set_label()) so that insert_set() can + have access to it. Curr set points the sets representation in the cdat, curr_set_odatp + points to the sets representation as an odat*/ + +void +insert_set_label +( char* name, + uint64_t ref_id +) +{ + + struct set* curr_setp; + + curr_setp = curr_set(); + curr_set_odatp = alloc_odat(); + + memmove(curr_set_odatp->name, name, 32); + memmove(curr_setp->name, name, 32); + + if(ref_id != -1) + { curr_set_odatp->ref_id = ref_id; + curr_setp->ref_id = ref_id; + } + else + { curr_setp->ref_id = ss_ref_id; + curr_set_odatp->ref_id = ss_ref_id++; + } + +} + +/* Inserting a olink instead of a set. Set is really just a placeholder + for another set. Allocate the memory for the set so taht it can be populated*/ +void +insert_set_olink +( uint64_t ref_id +) +{ + struct set* curr_setp; + + curr_setp = curr_set(); + + curr_setp->ref_id = ref_id; + +} + +void +insert_set_vlink +( uint64_t ref_id, + char* anim_name +) +{ + struct cdat* curr_cdatp; + struct odat* curr_odatp; + struct link* curr_linkp; + + + curr_cdatp = curr_cdat(); + curr_odatp = curr_odat(); + curr_linkp = alloc_link(); + + /* Insert vlink into link_stack so that it gets processed at + output time */ + curr_linkp->type = 2; + /* Store the target odat information*/ + curr_linkp->link_t.vlink.ref_id = ref_id; + memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32); + /* Store the linking odat/cdat information */ + curr_linkp->classp = curr_cdatp; + curr_linkp->odatp = curr_odatp; + curr_linkp->set_idx = curr_cdatp->num_sets; + curr_linkp->ele_idx = -1; + +} + +/* Svlinks dont have animation names */ +void +insert_set_svlink +( uint64_t ref_id +) +{ + struct cdat* curr_cdatp; + struct link* curr_linkp; + + curr_cdatp = curr_cdat(); + curr_linkp = alloc_link(); + + /* Insert svlink into link_stack so that it gets processed at + output time */ + curr_linkp->type = 3; + curr_linkp->classp = curr_cdatp; + curr_linkp->set_idx = curr_cdatp->num_sets; + curr_linkp->ele_idx = -1; + curr_linkp->link_t.svlink.ref_id = ref_id; + +} + +/* At the point of reducing to a set, most of the + sets odat information has already been populated + during the reduction of its right hand side + non terminals (hitbox, root, quad_list). */ +void +insert_set +() +{ uint64_t ref_id; + struct odat* curr_odatp; + struct cdat* curr_cdatp; + struct set* curr_setp; + struct ref* prev_refp; + struct ref* curr_refp; + struct vdat* curr_vdatp; + + curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space + curr_cdatp = curr_cdat(); + curr_setp = curr_set(); + prev_refp = curr_ref(); + curr_refp = alloc_ref(); + curr_vdatp = curr_vdat(); + + curr_vdatp->creator = curr_set_odatp; + + curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx? + memmove(curr_setp->name, curr_odatp->name, 32); + curr_cdatp->num_sets++; + + curr_odatp->cdat_idx = curr_cdatp->idx; + curr_odatp->refp = curr_refp; + + ref_id = curr_setp->ref_id; // ref_id set by insert_set_label(name, ref_id) + + curr_refp->ref_id = ref_id; + curr_refp->lastref = prev_refp; + curr_refp->odatp = curr_odatp; + prev_refp->nextref = curr_refp; + + + +} +/* Created as a seperate function, instead of setting the ODATS vdat_id and + calling inc_vdat() inside of insert_set(), to account for the set reduction + where a vdat is not created (o/v/svlinks). */ +void +insert_set_vdatid +() +{ + struct vdat* curr_vdatp; + + curr_vdatp = curr_vdat(); + + curr_set_odatp->vdat_id = num_vdats; //no vdat_id for odats that have vlinks/svlinks + curr_set_odatp->vdatp = curr_vdatp; + curr_set_odatp = NULL; //This sets odat shouldnt be modified after populating odats vdat info +} + +/* Populates the odat name and ref_id for odat, allocate the odat here for the rest of + the functions to use via curr_odat(). */ +void +insert_ele_label +( char* name, + uint64_t ref_id +) +{ + struct odat* curr_odatp; + + curr_odatp = alloc_odat(); + + memmove(curr_odatp->name, name, 32); + + if(ref_id != -1) + curr_odatp->ref_id = ref_id; + else + curr_odatp->ref_id = ss_ref_id++; + +} + +/* We don't make an odat here, at output time we will resolve + the ref_id to the corresponding odat. */ +void +insert_ele_olink +( uint64_t ref_id +) +{ + /* Do nothing because we already know the ref_id that + the odat needs for this element (in the quad_file) */ +} + +void +insert_ele_vlink +( uint64_t ref_id, + char* anim_name +) +{ + struct cdat* curr_cdatp; + struct set* curr_setp; + struct link* curr_linkp; + + curr_cdatp = curr_cdat(); + curr_setp = curr_set(); + curr_linkp = alloc_link(); + + /* Insert vlink into link_stack so that it gets processed at + output time */ + curr_linkp->classp = curr_cdatp; + curr_linkp->type = 2; + curr_linkp->set_idx = curr_cdatp->num_sets; + //curr_linkp->ele_idx = curr_setp->num_ele; + curr_linkp->link_t.vlink.ref_id = ref_id; + memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32); + +} + +void +insert_ele_svlink +( uint64_t ref_id +) +{ + struct cdat* curr_cdatp; + struct set* curr_setp; + struct link* curr_linkp; + + curr_cdatp = curr_cdat(); + curr_setp = curr_set(); + curr_linkp = alloc_link(); + + curr_linkp->classp = curr_cdatp; + curr_linkp->type = 3; + + //curr_linkp->ele_idx = curr_setp->num_ele; + curr_linkp->link_t.svlink.ref_id = ref_id; + + +} + +//Insert element into odat_buf and cdatpages +void +insert_ele() +{ + uint64_t ref_id; + struct cdat* curr_cdatp; + struct odat* curr_odatp; + struct vdat* curr_vdatp; + struct set* curr_setp; + struct ele* curr_elep; + struct ref* curr_refp; + struct ref* prev_refp; + + + curr_odatp = curr_odat(); //malloced @ insert_ele_label + curr_vdatp = curr_vdat(); + curr_setp = curr_set(); + prev_refp = curr_ref(); + curr_refp = alloc_ref(); + + curr_vdatp->creator = curr_odatp; + + /* Populate odat for ele */ + curr_odatp->cdat_idx = curr_cdatp->idx; + curr_odatp->refp = curr_refp; + + ref_id = curr_odatp->ref_id; + + curr_refp->ref_id = ref_id; + curr_refp->lastref = prev_refp; + curr_refp->odatp = curr_odatp; + prev_refp->nextref = curr_refp; + +} + +void +insert_ele_vdatid +() +{ struct odat* curr_odatp; + curr_odatp = curr_odat(); + curr_odatp->vdat_id = num_vdats; +} + +void +insert_quad +( void* quad_filep +) +{ + struct odat* curr_odatp; + + curr_odatp->quad_filep = quad_filep; +} + +/* Inserting the hitbox into the set + odat. Elements that don't have + a hitbox will use the sets root. */ +void +insert_hitbox +( int hitbox +) +{ struct odat* curr_odatp; + + curr_odatp = curr_odat(); + curr_odatp->hitbox = hitbox; +} + +/* Inserting the root into the set + odat. Elements that don't have + a root will use the sets root. */ +void +insert_root +( int x, + int y, + int z +) +{ struct odat* curr_odatp; + + curr_odatp = curr_odat(); + curr_odatp->root.x = x; + curr_odatp->root.y = y; + curr_odatp->root.z = z; +} + + +void +insert_framesheet +( char direction, + char* name, + uint64_t ref_id, + int height , + int width, + int num_frames +) +{ struct vdat* curr_vdatp; + struct model* curr_modelp; + + curr_vdatp = curr_vdat(); + curr_modelp = curr_model(); + + curr_modelp->spritesheet[(int)direction].height = height; + curr_modelp->spritesheet[(int)direction].width = width; + curr_modelp->spritesheet[(int)direction].num_frames = num_frames; + curr_vdatp->num_models++; +} + +void +insert_frame_pointer +( char direction, + void* frame +) +{ struct model* curr_modelp; + + curr_modelp = curr_model(); + + curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame; +} + diff --git a/src/apc/ir.h b/src/apc/ir.h old mode 100644 new mode 100755 index 7983284..3b1d75c --- a/src/apc/ir.h +++ b/src/apc/ir.h @@ -1,271 +1,271 @@ -/*!@file - \brief Intermediate Representation (IR) between Directory Structure and Engine Grammar - \details The IR serves as a storage structure that is populated during the - parsing of the input directory structure. After parsing is complete, - the IR will be condensed (removed of excess allocated space) and then - output as the Engine Grammar. In this file we describe the semantic actions - that are called at each step, and the memory buffers that they populate. - See parser.y for the description on how the input grammar is constructed, - and where/when semantic actions are called. - TODO: or just write it here. - \author Jordan Lavatai - \date Aug 2016 - ----------------------------------------------------------------------------*/ - - -#include - -#define BUF_SIZE 256 -#define MAX_SETS 256 -#define MAX_ELES 256 -#define MAX_QUADS 256 -#define MAX_MODELS 256 -#define MAX_POSTS 256 -#define MAX_CLASS_DEPTH 256 -#define MAX_CLASSES 256 -#define MAX_FRAMES 256 -#define PTRS_IN_PAGE 1024 -#define MAX_CHUNKS 256 -#define PAGES_PER_CHUNK 16 - -/* Sets: elements. The set is populated at parse time AFTER the - elements are populated, due to the nature of bottom up parsing. */ - -struct set { - char name[32]; - uint64_t ref_id; - int cdat_idx; -}; - -/* Cdats: A cdat is a class data structure. Cdats serve as the central */ -/* data types of the IR. For each cdat, sets and element */ -/* ref_ids must be dereferenced to determine the odat information. Cdats */ -/* contain pointers to their subclasses so that the relationship between */ -/* classes can be determined, but the subclasses are not represented inside */ -/* of the cdat itself but rather in subsequent cdats in cdat_buf. We */ -/* can determine the number of subclasses (the last index into cdat_buf */ -/* that represents a subclass of some arbitrary cdat) each cdat has by */ -/* incrementing num_classes during parse time. */ -/* TODO: Should classes point to their parent class? */ - -struct cdat { - char name[32]; - int idx; - int num_classes; - int num_sets; - struct cdat* class_list[MAX_CLASSES]; - struct set set_list[MAX_SETS]; -}; - -/* The cdat_stack is a stack pointers to cdat pointers, the top of which is - the cdat that is currently being parsed. Whenever a new cdat is recognized - by the grammar (CLOPEN), a cdat is pushed onto the cdat_stack, and we refer - to this cdat through the macro CURR_CDAT. By keeping a cdat_stack, we have - access to the current cdat so that the elements and sets can populate themselves - in the cdat accordingly. */ - - -/* Refs: Each set/ele has a reference to its object data (odat) through a ref_id. - Ref_ids are unsigned 64 byte integers that map to the hex values RGBA. During - the construction of the directory structure, users can choose a RGBA value for - each object that any other object can refer to via links (see link). If a user - does not choose an RGBA value, then the object is given one from the system space. - We maintain a doubly linked list of refs in the ref_buf at parse time so that - links can be resolved after the parsing of the directory structure is complete. - For every 16th ref, we create a post so that we can reduce on the search time for - a random access. */ - -struct ref { - int type; - struct ref* nextref; - struct ref* lastref; - struct odat* odatp; - uint64_t ref_id; //0xFFFFFF->digit -}; - - -/* Links: At parse time, a set/ele can include a link in their - grammar representation instead of the actual data and this signifies - to the APC that that set/ele wishes to use the data of another - set/ele, either its video data (vdat) or object data (odat). The link - itself contains the type of link it is, the ref_id OR name, and - which set/ele created the link. During parse time, links can be made - to o/vdats that have yet to be parsed. In order to accomodate for this, - we resolve all links AFTER parse time by iterating through the link_buf, - finding the ref_id that was stored for some object (if the ref_id exists), - and creating a relative pointer from the original object to the data that - was linked */ - -/* Svlinks stand for short vlink, which is a link to a vdat. svlinks - differ from vlinks because they do not have a name */ - -struct svlink { - uint64_t ref_id; -}; - -/* A vlink is what it sounds like, a link to a vdat */ -struct vlink { - uint64_t ref_id; - char anim_name[32]; -}; - -union link_t { - struct vlink vlink; - struct svlink svlink; -}; - -/* From: src odat ()To: dest odat (ref_id)*/ -struct link { - int type; //1 = olink, 2 = vlink, 3 = svlink - union link_t link_t; - struct cdat* classp; - struct odat* odatp; - int set_idx; - int ele_idx; -}; - - -/* Odats: Odats consist of the object data necessary for - each object. Odats are sometimes referred to as archetypes - at compile-time, in order to distinguish the difference from - a runtime object and a compile-time object. - TODO: Need more info about objects at runtime, to described - the reasoning behind odat structure at compile-time*/ - -struct root { - int x, y, z; -}; - -struct odat { - char name[32]; - struct vdat* vdatp; - int vdat_id; // - int cdat_idx; - int hitbox; - uint64_t ref_id; - struct root root; - struct ref* refp; /* pointer to it's ref on ref_list */ - void* quad_filep; -}; - -struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer - //refer to its odat via curr_odat, so save the set odat. - -/* A framesheet is a grouping of animation frames in - a single direction (N,W,S,E) */ -struct framesheet { - int width; - int height; - int num_frames; - void* frames[MAX_FRAMES]; -}; - -/* A model is a collection of framesheets for every - direction (N,W,S,E,NW,NE,SW,SE)*/ -/* NAMED spritesheet */ -struct model { - char name[32]; - struct framesheet spritesheet[8]; //one for each -}; - -/* Vdat: Vdats are the video data of each object. They can not be - created as a stand alone object (because they consist solely - of animation information and not the skeleton on which the - animation manipulates). Vdats have a list of models for every - animation that the vdats odat can do for that vdat*/ -struct vdat { - struct odat* creator; //pointer to odat that made this vdat - int num_models; - struct model model_list[MAX_MODELS]; -}; - -/* Called after the cdat open operator has been recognized in grammar. Allocates - the space for a cdat on the cdat_buf, pushes that pointer onto - the cdat_stack */ -void -push_cdat(char*); - -/* Called after a cdat end operator has been recognized in grammar. Sets - top stack cdat ** to null and decrements stack pointer */ -void -pop_cdat(void); - -/* Called after an odat has been populated. Allocates memory for - the next odat. */ - -void -insert_set_label(char*, uint64_t); - -/* Populate the sets representation in CURR_CDAT with a ref_id and insert a link - into the link_buf that will resolve the ref_id to an actual odat after parse time. */ -void -insert_set_olink(uint64_t); - -/* Put the vlink in the link_buf to be processed after parsetime */ -void -insert_set_vlink(uint64_t, char*); - -/* Put svlink in the link_buf to be processed after parsetime */ -void -insert_set_svlink(uint64_t); - -/* Called for every set reduction except for sets with olinks. Populates the - set data structures in the CDAT and in the ODAT. Uses the name and ref_id - from insert_set_label. Also inserts a ref into the ref_buf with the CURR_ODAT - pointer so that we can also resolve the odat from its ref_id. */ -void -insert_set(void); - -/* Insertion of eles is practically equivalent to how sets are inserted because both - share the same data type (ODAT). Like sets, eles have links, labels - and odats. Eles have the added notion of a parent set, and so must be inserted - into said parent set, but this is the only place they truly differ from sets. */ - -void -insert_set_vdatid(void); - -void -insert_ele_label(char*, uint64_t); - -/* Insert an ele olink into the CURR_ODAT */ -void -insert_ele_olink(uint64_t); - -/* Insert a ele vlink into CURR_ODAT*/ -void -insert_ele_vlink(uint64_t, char*); - -/* Inserts an ele short vlink into CURR_ODAT*/ -void -insert_ele_svlink(uint64_t); - -/* inserts ele into CURR_CLASS and CURR_ODAT */ -void -insert_ele(void); - -void -insert_ele_vdatid(void); - -/* Inserts the hitbox into the CURR_ODAT */ -void -insert_hitbox(int); - -/* Inserts the root into the CURR_ODAT */ -void -insert_root(int, int, int); - -/* Inserts a quad into the CURR_ODAT */ -void -insert_quad(void*); - -void -insert_model(void); - -void -insert_framesheet(char, char*, uint64_t, int, int, int); - -void -insert_frame_pointer(char, void*); - -void -alloc_vdat(void); +/*!@file + \brief Intermediate Representation (IR) between Directory Structure and Engine Grammar + \details The IR serves as a storage structure that is populated during the + parsing of the input directory structure. After parsing is complete, + the IR will be condensed (removed of excess allocated space) and then + output as the Engine Grammar. In this file we describe the semantic actions + that are called at each step, and the memory buffers that they populate. + See parser.y for the description on how the input grammar is constructed, + and where/when semantic actions are called. + TODO: or just write it here. + \author Jordan Lavatai + \date Aug 2016 + ----------------------------------------------------------------------------*/ + + +#include + +#define BUF_SIZE 256 +#define MAX_SETS 256 +#define MAX_ELES 256 +#define MAX_QUADS 256 +#define MAX_MODELS 256 +#define MAX_POSTS 256 +#define MAX_CLASS_DEPTH 256 +#define MAX_CLASSES 256 +#define MAX_FRAMES 256 +#define PTRS_IN_PAGE 1024 +#define MAX_CHUNKS 256 +#define PAGES_PER_CHUNK 16 + +/* Sets: elements. The set is populated at parse time AFTER the + elements are populated, due to the nature of bottom up parsing. */ + +struct set { + char name[32]; + uint64_t ref_id; + int cdat_idx; +}; + +/* Cdats: A cdat is a class data structure. Cdats serve as the central */ +/* data types of the IR. For each cdat, sets and element */ +/* ref_ids must be dereferenced to determine the odat information. Cdats */ +/* contain pointers to their subclasses so that the relationship between */ +/* classes can be determined, but the subclasses are not represented inside */ +/* of the cdat itself but rather in subsequent cdats in cdat_buf. We */ +/* can determine the number of subclasses (the last index into cdat_buf */ +/* that represents a subclass of some arbitrary cdat) each cdat has by */ +/* incrementing num_classes during parse time. */ +/* TODO: Should classes point to their parent class? */ + +struct cdat { + char name[32]; + int idx; + int num_classes; + int num_sets; + struct cdat* class_list[MAX_CLASSES]; + struct set set_list[MAX_SETS]; +}; + +/* The cdat_stack is a stack pointers to cdat pointers, the top of which is + the cdat that is currently being parsed. Whenever a new cdat is recognized + by the grammar (CLOPEN), a cdat is pushed onto the cdat_stack, and we refer + to this cdat through the macro CURR_CDAT. By keeping a cdat_stack, we have + access to the current cdat so that the elements and sets can populate themselves + in the cdat accordingly. */ + + +/* Refs: Each set/ele has a reference to its object data (odat) through a ref_id. + Ref_ids are unsigned 64 byte integers that map to the hex values RGBA. During + the construction of the directory structure, users can choose a RGBA value for + each object that any other object can refer to via links (see link). If a user + does not choose an RGBA value, then the object is given one from the system space. + We maintain a doubly linked list of refs in the ref_buf at parse time so that + links can be resolved after the parsing of the directory structure is complete. + For every 16th ref, we create a post so that we can reduce on the search time for + a random access. */ + +struct ref { + int type; + struct ref* nextref; + struct ref* lastref; + struct odat* odatp; + uint64_t ref_id; //0xFFFFFF->digit +}; + + +/* Links: At parse time, a set/ele can include a link in their + grammar representation instead of the actual data and this signifies + to the APC that that set/ele wishes to use the data of another + set/ele, either its video data (vdat) or object data (odat). The link + itself contains the type of link it is, the ref_id OR name, and + which set/ele created the link. During parse time, links can be made + to o/vdats that have yet to be parsed. In order to accomodate for this, + we resolve all links AFTER parse time by iterating through the link_buf, + finding the ref_id that was stored for some object (if the ref_id exists), + and creating a relative pointer from the original object to the data that + was linked */ + +/* Svlinks stand for short vlink, which is a link to a vdat. svlinks + differ from vlinks because they do not have a name */ + +struct svlink { + uint64_t ref_id; +}; + +/* A vlink is what it sounds like, a link to a vdat */ +struct vlink { + uint64_t ref_id; + char anim_name[32]; +}; + +union link_t { + struct vlink vlink; + struct svlink svlink; +}; + +/* From: src odat ()To: dest odat (ref_id)*/ +struct link { + int type; //1 = olink, 2 = vlink, 3 = svlink + union link_t link_t; + struct cdat* classp; + struct odat* odatp; + int set_idx; + int ele_idx; +}; + + +/* Odats: Odats consist of the object data necessary for + each object. Odats are sometimes referred to as archetypes + at compile-time, in order to distinguish the difference from + a runtime object and a compile-time object. + TODO: Need more info about objects at runtime, to described + the reasoning behind odat structure at compile-time*/ + +struct root { + int x, y, z; +}; + +struct odat { + char name[32]; + struct vdat* vdatp; + int vdat_id; // + int cdat_idx; + int hitbox; + uint64_t ref_id; + struct root root; + struct ref* refp; /* pointer to it's ref on ref_list */ + void* quad_filep; +}; + +struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer + //refer to its odat via curr_odat, so save the set odat. + +/* A framesheet is a grouping of animation frames in + a single direction (N,W,S,E) */ +struct framesheet { + int width; + int height; + int num_frames; + void* frames[MAX_FRAMES]; +}; + +/* A model is a collection of framesheets for every + direction (N,W,S,E,NW,NE,SW,SE)*/ +/* NAMED spritesheet */ +struct model { + char name[32]; + struct framesheet spritesheet[8]; //one for each +}; + +/* Vdat: Vdats are the video data of each object. They can not be + created as a stand alone object (because they consist solely + of animation information and not the skeleton on which the + animation manipulates). Vdats have a list of models for every + animation that the vdats odat can do for that vdat*/ +struct vdat { + struct odat* creator; //pointer to odat that made this vdat + int num_models; + struct model model_list[MAX_MODELS]; +}; + +/* Called after the cdat open operator has been recognized in grammar. Allocates + the space for a cdat on the cdat_buf, pushes that pointer onto + the cdat_stack */ +void +push_cdat(char*); + +/* Called after a cdat end operator has been recognized in grammar. Sets + top stack cdat ** to null and decrements stack pointer */ +void +pop_cdat(void); + +/* Called after an odat has been populated. Allocates memory for + the next odat. */ + +void +insert_set_label(char*, uint64_t); + +/* Populate the sets representation in CURR_CDAT with a ref_id and insert a link + into the link_buf that will resolve the ref_id to an actual odat after parse time. */ +void +insert_set_olink(uint64_t); + +/* Put the vlink in the link_buf to be processed after parsetime */ +void +insert_set_vlink(uint64_t, char*); + +/* Put svlink in the link_buf to be processed after parsetime */ +void +insert_set_svlink(uint64_t); + +/* Called for every set reduction except for sets with olinks. Populates the + set data structures in the CDAT and in the ODAT. Uses the name and ref_id + from insert_set_label. Also inserts a ref into the ref_buf with the CURR_ODAT + pointer so that we can also resolve the odat from its ref_id. */ +void +insert_set(void); + +/* Insertion of eles is practically equivalent to how sets are inserted because both + share the same data type (ODAT). Like sets, eles have links, labels + and odats. Eles have the added notion of a parent set, and so must be inserted + into said parent set, but this is the only place they truly differ from sets. */ + +void +insert_set_vdatid(void); + +void +insert_ele_label(char*, uint64_t); + +/* Insert an ele olink into the CURR_ODAT */ +void +insert_ele_olink(uint64_t); + +/* Insert a ele vlink into CURR_ODAT*/ +void +insert_ele_vlink(uint64_t, char*); + +/* Inserts an ele short vlink into CURR_ODAT*/ +void +insert_ele_svlink(uint64_t); + +/* inserts ele into CURR_CLASS and CURR_ODAT */ +void +insert_ele(void); + +void +insert_ele_vdatid(void); + +/* Inserts the hitbox into the CURR_ODAT */ +void +insert_hitbox(int); + +/* Inserts the root into the CURR_ODAT */ +void +insert_root(int, int, int); + +/* Inserts a quad into the CURR_ODAT */ +void +insert_quad(void*); + +void +insert_model(void); + +void +insert_framesheet(char, char*, uint64_t, int, int, int); + +void +insert_frame_pointer(char, void*); + +void +alloc_vdat(void); diff --git a/src/apc/lexer_lex.rl b/src/apc/lexer_lex.rl old mode 100644 new mode 100755 index 234e941..f7eb429 --- a/src/apc/lexer_lex.rl +++ b/src/apc/lexer_lex.rl @@ -1,115 +1,114 @@ -/* Ragel State Machine for tokenizing text */ -#include -#include -#include - -extern void lexer_pushtok(int, YYSTYPE); - -int lexer_lex(const char*); -int ipow(int, int); -int ttov(const char* str, int); -uint64_t ttor(const char* str, int); -char* ttos(const char* str, int); - - -#define MAX_TOK_LEN 64 -#define MAX_TOKENS 16 -#define MAX_STR_SIZE (MAX_TOK_LEN * MAX_TOKENS) -#define $($)#$ -#define PUSHTOK(TOK,LFUNC,UTYPE) \ - do { \ - printf("PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \ - tok_t = TOK; \ - yylval.UTYPE = LFUNC(ts, p-ts); \ - lexer_pushtok(tok_t, yylval); \ - ++ntok; \ - } while (0) - -%%{ - machine token_matcher; - - # set up yylval and tok_t to be pushed to stack - action set_ref { PUSHTOK(REF, ttor, ref); } - action set_val { PUSHTOK(NUM, ttov, val); } - action set_name { PUSHTOK(NAME, ttos, str); } - action set_ts { ts = p; } - action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);} - - # instantiate machines for each possible token - ref = '0x' xdigit+ %set_ref; - val = digit+ %set_val; - name = alpha+ %set_name; - tok = ref | val | name; - segment = (tok . '_') %set_ts; - - main := segment* . tok $lerr(lex_error); -}%% - - -%%write data; - -/* Scan filename and push the its tokens - onto the stack */ -int lexer_lex (const char* str) -{ - const char *p, *pe, *ts, *eof; - int cs, tok_t, ntok = 0; - printf ("Lexing: %s\n",str); - p = ts = str; - pe = p + strlen(str); - %%write init; - %%write exec; - printf ("Lexed %i tokens\n",ntok); - return ntok; -} - -int ipow(int base, int exp) -{ - int result = 1; - while (exp) - { - if (exp & 1) - result = result * base; - exp = exp >> 1; - base *= base; - } - - return result; -} - -/* Token to Value */ -int ttov(const char* str, int len) -{ - int i, val = 0; - - for (i = 0; i < len; i++) - { - val += ((str[len - (i + 1)] - '0') * ipow(10,i)); - } - - return val; -} - -uint64_t ttor(const char* str, int len) -{ - int i; - uint64_t num = 0; - - for (i = 0; i < len; i++) - { - num += ((str[len - (i + 1)] - '0') * ipow(10,i)); - } - - return num; -} - -char* ttos(const char* str, int len) -{ - int i; - char token_buf[MAX_TOK_LEN]; - - memmove(token_buf, str, len); - token_buf[len+1] = '\0'; - - return strdup(token_buf); -} +/* Ragel State Machine for tokenizing text */ +#include +#include +#include + +extern void lexer_pushtok(int, YYSTYPE); + +int lexer_lex(const char*); +int ipow(int, int); +int ttov(const char* str, int); +uint64_t ttor(const char* str, int); +char* ttos(const char* str, int); + + +#define MAX_TOK_LEN 64 +#define MAX_TOKENS 16 +#define MAX_STR_SIZE (MAX_TOK_LEN * MAX_TOKENS) +#define $($)#$ +#define PUSHTOK(TOK,LFUNC,UTYPE) \ + do { \ + printf("PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \ + tok_t = TOK; \ + yylval.UTYPE = LFUNC(ts, ts-p-1); \ + lexer_pushtok(tok_t, yylval); \ + ++ntok; \ + } while (0) + +%%{ + machine token_matcher; + + # set up yylval and tok_t to be pushed to stack + action set_ref { PUSHTOK(REF, ttor, ref); } + action set_val { PUSHTOK(NUM, ttov, val); } + action set_name { PUSHTOK(NAME, ttos, str); } + action set_ts { ts = p; } + action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);} + + # instantiate machines for each possible token + ref = '0x'. xdigit+ . '_' %set_ref; + val = digit+ . '_' %set_val; + name = alpha+ . '_' %set_name; + tok = (ref | val | name) %set_ts; + + main := alpha+ @set_name; +}%% + + +%%write data; +/* Scan filename and push the its tokens + onto the stack */ +int lexer_lex (const char* str) +{ + const char *p, *pe, *ts, *eof; + int cs, tok_t, ntok = 0; + printf ("Lexing: %s\n",str); + p = ts = str; + pe = p + strlen(str); + printf("p = %s \n", p); + %%write init; + %%write exec; + printf ("Lexed %i tokens\n",ntok); + return ntok; +} + +int ipow(int base, int exp) +{ + int result = 1; + while (exp) + { + if (exp & 1) + result = result * base; + exp = exp >> 1; + base *= base; + } + + return result; +} + +/* Token to Value */ +int ttov(const char* str, int len) +{ + int i, val = 0; + + for (i = 0; i < len; i++) + { + val += ((str[len - (i + 1)] - '0') * ipow(10,i)); + } + + return val; +} + +uint64_t ttor(const char* str, int len) +{ + int i; + uint64_t num = 0; + + for (i = 0; i < len; i++) + { + num += ((str[len - (i + 1)] - '0') * ipow(10,i)); + } + + return num; +} + +char* ttos(const char* str, int len) +{ + int i; + char token_buf[MAX_TOK_LEN]; + + memmove(token_buf, str, len); + token_buf[len+1] = '\0'; + + return strdup(token_buf); +} diff --git a/src/apc/parser.y b/src/apc/parser.y index 2b17d83..e6d145c 100644 --- a/src/apc/parser.y +++ b/src/apc/parser.y @@ -79,7 +79,7 @@ class_list class ; class: - NAME CLOPEN {push_cdat($1);} class_block CLCLOSE {pop_cdat();}; + CLOPEN NAME {push_cdat($2);} class_block CLCLOSE {pop_cdat();}; ; class_block: @@ -94,14 +94,14 @@ set_list set ; root: -RT NUM NUM NUM {insert_root($2, $3, $4);}; +RT NUM NUM NUM {insert_root($2, $3, $4);}; ; quad_file: QOPEN QPTR QCLOSE {insert_quad($2);}; hitbox: -HB NUM {insert_hitbox($2);} +HB NUM {insert_hitbox($2);} ; set_map_data: @@ -114,7 +114,7 @@ quad_file ; set: -SOPEN set_label set_map_data element_list {alloc_vdat();} vdat SCLOSE {insert_set(); insert_set_vdatid();}; +SOPEN set_label set_map_data element_list {alloc_vdat();} vdat SCLOSE {insert_set(); insert_set_vdatid();}; | SOPEN set_label set_map_data element_list set_vlink SCLOSE {insert_set();}; | SOPEN set_label set_map_data element_list set_svlink SCLOSE {insert_set_svlink($5); insert_set(); }; | SOPEN set_label element_list {alloc_vdat();} vdat SCLOSE {insert_set(); insert_set_vdatid();}; @@ -125,8 +125,8 @@ SOPEN set_label set_map_data element_list {alloc_vdat();} vdat SCLOSE { set_label: -HP NAME REF {insert_set_label($2,$3);}; -| LP NAME {insert_set_label($2, -1);}; +HP NAME REF {insert_set_label($2,$3);}; +| LP NAME {insert_set_label($2, -1);}; ; set_svlink: @@ -135,7 +135,7 @@ REF ; set_vlink: -REF NAME {insert_set_vlink($1, $2);}; +REF NAME {insert_set_vlink($1, $2);}; ; olink: @@ -149,12 +149,12 @@ element_list element MP ; ele_label: -HP NAME REF {insert_ele_label($2, $3);}; -| LP NAME {insert_ele_label($2, -1);}; +HP NAME REF {insert_ele_label($2, $3);}; +| LP NAME {insert_ele_label($2, -1);}; ; ele_vlink: -REF NAME {insert_ele_vlink($1, $2);}; +REF NAME {insert_ele_vlink($1, $2);}; ; ele_svlink: @@ -167,7 +167,7 @@ EOPEN ele_label hitbox root {alloc_vdat();} vdat ECLOSE { | EOPEN ele_label hitbox root ele_svlink ECLOSE {insert_ele_svlink($5);insert_ele(); }; | EOPEN ele_label root {alloc_vdat();} vdat ECLOSE {insert_ele(); insert_ele_vdatid();}; | EOPEN ele_label root ele_vlink ECLOSE {insert_ele(); }; -| EOPEN ele_label root ele_svlink ECLOSE {insert_ele_svlink($4); insert_ele(); }; +| EOPEN ele_label root ele_svlink ECLOSE {insert_ele_svlink($4); insert_ele(); }; | EOPEN olink ECLOSE {insert_ele_olink($2);}; ; @@ -194,8 +194,8 @@ SSD NAME REF HEIGHT WIDTH NUM_PTRS frame_pointers LP {insert ; frame_pointers: -frame_pointers SSD HP FPTR {insert_frame_pointer($2, $4);}; -| SSD FPTR {insert_frame_pointer($1, $2);}; +frame_pointers SSD HP FPTR {insert_frame_pointer($2, $4);}; +| SSD FPTR {insert_frame_pointer($1, $2);}; ; %%