declreps.c 3.15 KB
/*====================================================================
 * declreps.c
 *
 * Copyright 1993, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

#include <assert.h>
#include "ic.h"
#include "y.tab.h"

List    *objectList = 0;
int     objectID = 0;

void declInit() 
{
    objectList = calloc(1,sizeof(List));
    assert(objectList);
    listNew(objectList);    

    makebankfiledecl();
    
}

int declSize(Decl *d)
{
    return (d->size + 7) & ~7;
}

void declPrint(Decl *d)
{
    printf("\tId:\t\t%d\n", d->id);    
    printf("\tOffset:\t\t0x%x\n",d->offset);
    printf("\tSize:\t\t%d\n", d->size);
    printf("\tClass:\t\t%d\n",d->declclass);
}

/*  Allocate a new decl and fill in decltype field. */
struct decl *makedecl(int declclass)
{
    struct decl *declptr = (struct decl *) calloc(1, sizeof(struct decl));
    declptr->declclass = declclass;
    return declptr;
}

/*
 * Make a constant decl for an enumerated type.
 */
struct decl *makeenumconstdecl(int value)
{
    struct decl *declptr = makedecl(CONST);
    declptr->value = value;
    return declptr;
}

struct decl *maketypedecl()
{
    struct decl *declptr = makedecl(TYPE);
    return declptr;
}

struct decl *makebankfiledecl()
{
    ICBankFile *b = calloc(1,sizeof(ICBankFile));
    assert(b);
    
    bankfNew(b);
    listAppend(objectList, b);
    curBankFile = b; /* ### temp kludge */
    
    return (Decl *)b;
}

struct decl *makebankdecl()
{
    ICBank *b = calloc(1,sizeof(ICBank));
    assert(b);
    
    bankNew(b);
    listAppend(objectList, b);
    
    /*
     * ### kludge, should put bank in the grammar
     */
    bankfAddBank(curBankFile, b, 0);
    
    return (Decl *)b;
}

struct decl *makeinstdecl()
{
    ICInst *i = calloc(1, sizeof(ICInst));
    assert(i);
    
    instNew(i);
    listAppend(objectList, i);
    
    return (Decl *)i;
}

struct decl *makesounddecl()
{
    ICSound *s = calloc(1, sizeof(ICSound));
    assert(s);
    
    soundNew(s);
    listAppend(objectList, s);
    
    return (Decl *)s;
}

struct decl *makekeydecl()
{
    ICKeyMap *k = calloc(1, sizeof(ICKeyMap));
    assert(k);
    
    keyNew(k);
    listAppend(objectList, k);
    
    return (Decl *)k;
}

struct decl *makeenvdecl()
{
    ICEnvelope *env = calloc(1, sizeof(ICEnvelope));
    assert(env);

    envNew(env);
    listAppend(objectList, env);

    return (Decl *)env;
}

struct decl *makefiledecl(char *s)
{
    struct decl *declptr = makedecl(SFILE);
    return declptr;
}