OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zpp.l] - Diff between revs 36 and 46

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 36 Rev 46
Line 502... Line 502...
        }
        }
 
 
        void    addmacro(const char *name, const char *str) {
        void    addmacro(const char *name, const char *str) {
                TBLT::iterator i = lookup(name);
                TBLT::iterator i = lookup(name);
                if (i == m_tbl.end()) {
                if (i == m_tbl.end()) {
                        fprintf(stderr, "INTERNAL ERR, %s NOT DEFINED!\n", name);
                        fprintf(stderr, "ADDMACRO::INTERNAL ERR, \'%s\' NOT DEFINED!\n", name);
                } *(*i) += str;
                } *(*i) += str;
        }
        }
 
 
        void    addargs(const char *name, const char *str) {
        void    addargs(const char *name, const char *str) {
                TBLT::iterator i = lookup(name);
                TBLT::iterator i = lookup(name);
Line 521... Line 521...
                } return (*i)->hasargs();
                } return (*i)->hasargs();
        }
        }
        const   char *getdefn(const char *name) {
        const   char *getdefn(const char *name) {
                TBLT::iterator i = lookup(name);
                TBLT::iterator i = lookup(name);
                if (i == m_tbl.end()) {
                if (i == m_tbl.end()) {
                        fprintf(stderr, "INTERNAL ERR, %s NOT DEFINED!\n", name);
                        fprintf(stderr, "GETDEFN::INTERNAL ERR, \'%s\' NOT DEFINED!\n", name);
                        return NULL;
                        return NULL;
                } (*i)->getdefn().c_str();
                } (*i)->getdefn().c_str();
        }
        }
 
 
        std::string     expand(const char *name, const char *ptr) {
        std::string     expand(const char *name, const char *ptr) {
Line 539... Line 539...
 
 
SYMTABLE_ENTRY  *last = NULL;
SYMTABLE_ENTRY  *last = NULL;
SYMBOL_TABLE    syms;
SYMBOL_TABLE    syms;
std::string     last_define;
std::string     last_define;
 
 
 
char    *stb_trim(const char *str) {
 
        // fprintf(stderr, "Checking whether %s needs to be expanded\n",str);
 
        char *dup = strdup(str), *chr;
 
        chr = strchr(dup, '(');
 
        if (chr != NULL)
 
                *chr = '\0';
 
        // fprintf(stderr, "\tLooking it up by the name \'%s\'\n", dup);
 
 
 
        // Now, let's trim our string
 
        char    *end = dup+strlen(dup)-1;
 
        while((*dup)&&(end>dup)&&(isspace(*end)))
 
                *end-- = '\0';
 
        return dup;
 
}
 
 
void    stb_define(const char *str) {
void    stb_define(const char *str) {
        /*
        /*
        if (last_define.size()>0) {
        if (last_define.size()>0) {
                fprintf(stderr, "LAST-DEFINE(%s): %s\n", last_define.c_str(),
                fprintf(stderr, "LAST-DEFINE(%s): %s\n", last_define.c_str(),
                        stb_getdefn(last_define.c_str()));
                        stb_getdefn(last_define.c_str()));
        } */
        } */
 
        char    *alt = stb_trim(str);
        if (syms.defined(str)) {
        if (syms.defined(alt)) {
                fprintf(stderr, "WARNING!  Symbol \'%s\' is already defined!\n", str);
                fprintf(stderr, "WARNING!  Symbol \'%s\' is already defined!\n", str);
                syms.undefine(str);
                syms.undefine(str);
        }
        }
 
 
        syms.define(str);
        syms.define(alt);
        last_define = str;
        last_define = alt;
 
        free(alt);
}
}
 
 
void    stb_args(const char *args) {
void    stb_args(const char *args) {
        syms.addargs(last_define.c_str(), args);
        syms.addargs(last_define.c_str(), args);
}
}
Line 568... Line 584...
void    stb_addmacro(const char *value) {
void    stb_addmacro(const char *value) {
        syms.addmacro(last_define.c_str(),value);
        syms.addmacro(last_define.c_str(),value);
}
}
 
 
bool    stb_isdefined(const char *str) {
bool    stb_isdefined(const char *str) {
        const char *ptr;
        char    *dup = stb_trim(str);
        if ((ptr = strchr(str, '('))!=NULL) {
 
                // fprintf(stderr, "Checking whether %s needs to be expanded\n",str);
 
                char *dup = strdup(str), *chr;
 
                chr = strchr(dup, '(');
 
                *chr = '\0';
 
                // fprintf(stderr, "\tLooking it up by the name \'%s\'\n", dup);
 
                bool r = (syms.defined(dup));
                bool r = (syms.defined(dup));
                free(dup);
                free(dup);
                return r;
                return r;
        } else {
 
                return syms.defined(str);
 
        }
 
}
}
 
 
const char *stb_getdefn(const char *str) {
const char *stb_getdefn(const char *str) {
        return syms.getdefn(str);
        char    *dup = stb_trim(str);
 
        const char      *r;
 
        r = syms.getdefn(dup);
 
        free(dup);
 
        return r;
}
}
 
 
bool    stb_current(const char *str) {
bool    stb_current(const char *str) {
        return (strcmp(str, last_define.c_str())==0);
        return (strcmp(str, last_define.c_str())==0);
}
}
 
 
bool    stb_hasargs(const char *str) {
bool    stb_hasargs(const char *str) {
        const char *ptr;
        char    *dup = stb_trim(str);
        if ((ptr = strchr(str, '('))!=NULL) {
 
                char *dup = strdup(str), *chr;
 
                chr = strchr(dup, '(');
 
                *chr = '\0';
 
                bool r = (syms.hasargs(dup));
                bool r = (syms.hasargs(dup));
                // fprintf(stderr, "\t%s has %sarguments\n", dup, (r)?"":"no ");
                // fprintf(stderr, "\t%s has %sarguments\n", dup, (r)?"":"no ");
                free(dup);
                free(dup);
                return r;
                return r;
        } else {
 
                return syms.hasargs(str);
 
        }
 
}
}
 
 
std::string     stb_expand(const char *macro) {
std::string     stb_expand(const char *macro) {
        const   char    *ptr;
        const   char    *ptr;
        std::string     str;
        std::string     str;

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.