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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zparser.cpp] - Diff between revs 8 and 9

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

Rev 8 Rev 9
Line 82... Line 82...
}
}
 
 
bool    ZPARSER::parse_op(const char *line, ZPARSER::ZIPA pc,
bool    ZPARSER::parse_op(const char *line, ZPARSER::ZIPA pc,
                ZPARSER::ZIPI &ins, const unsigned lineno) const {
                ZPARSER::ZIPI &ins, const unsigned lineno) const {
        const char      *sp = line;
        const char      *sp = line;
        char    cpy[128], *cp = cpy, *point, *dollar, *plus, *comma,
        char    cpy[128], *cp = cpy, *point, *dollar, *plus, *comma, *paren,
                        *opc, *opb;
                        *opc, *opb, *opa;
        ZPARSER::ZIPREG ra = ZPARSER::ZIP_Rnone, rb = ZPARSER::ZIP_Rnone;
        ZPARSER::ZIPREG ra = ZPARSER::ZIP_Rnone, rb = ZPARSER::ZIP_Rnone;
        ZIPCOND cnd = ZIPC_ALWAYS;
        ZIPCOND cnd = ZIPC_ALWAYS;
        ZIPIMM  imm = 0;
        ZIPIMM  imm = 0;
        bool    valid = true;
        bool    valid = true;
 
 
Line 116... Line 116...
        *cp = '\0';
        *cp = '\0';
        point = strchr(cpy, '.');
        point = strchr(cpy, '.');
        comma = strchr(cpy, ',');
        comma = strchr(cpy, ',');
        plus  = strchr(cpy, '+');
        plus  = strchr(cpy, '+');
        dollar= strchr(cpy, '$');
        dollar= strchr(cpy, '$');
        // paren = strchr(cpy, '(');
        paren = strchr(cpy, '(');
        if (point)  *point++  = '\0';
        if (point)  *point++  = '\0';
        if (comma)  *comma++  = '\0';
        if (comma)  *comma++  = '\0';
        if (plus)   *plus++   = '\0';
        if (plus)   *plus++   = '\0';
        if (dollar) *dollar++ = '\0';
        if (dollar) *dollar++ = '\0';
        // if (paren)  *paren++  = '\0';
        // if (paren)  *paren++  = '\0';
Line 153... Line 153...
 
 
        cp++;
        cp++;
        while(isspace(*cp))
        while(isspace(*cp))
                cp++;
                cp++;
        opb = cp;
        opb = cp;
 
        opa = comma;
 
 
 
        if (paren) {
 
                opb = paren+1;
 
                if ((comma)&&(opb > comma))
 
                        opa = cp;
 
        } else if (plus)
 
                opb = plus;
 
 
        if (dollar) {
        if (dollar) {
                // Figure out the base
                // Figure out the base
                {
                {
                        char *ip = dollar, mxd = 0;
                        char *ip = dollar, mxd = 0;
Line 193... Line 201...
 
 
                                if (neg)
                                if (neg)
                                        imm = -imm;
                                        imm = -imm;
                        }
                        }
                }
                }
                opb = dollar;
 
                if (plus)
 
                        opb = plus;
 
        } else
        } else
                imm = 0;
                imm = 0;
 
 
        if (*opb) for(int i=31; i>=0; i--) {
        if (*opb) for(int i=31; i>=0; i--) {
                // printf("Checking for match: \'%s\' to %s", opb, zop_regstr[i]);
                // printf("%s Checking for match to opB: \'%s\' to %s", opc, opb, zop_regstr[i]);
                if (NULL != strcasestr(opb, zop_regstr[i])) {
                if (NULL != strcasestr(opb, zop_regstr[i])) {
                        // printf(" --- Match\n");
                        // printf(" --- Match\n");
                        rb = (ZIPREG)i;
                        rb = (ZIPREG)i;
                        break;
                        break;
                } // else printf(" -- nope\n");
                } // else printf(" -- nope\n");
        } if (comma) for(int i=31; i>=0; i--) {
        } if (opa) for(int i=31; i>=0; i--) {
                // printf("Checking for match: ,%s to %s", comma, zop_regstr[i]);
                // printf("%s Checking for match to opA: ,%s to %s", opc, opa, zop_regstr[i]);
                if (NULL != strcasestr(comma, zop_regstr[i])) {
                if (NULL != strcasestr(opa, zop_regstr[i])) {
                        ra = (ZIPREG)i;
                        ra = (ZIPREG)i;
                        // printf(" --- Match\n");
                        // printf(" --- Match\n");
                        break;
                        break;
                } // else printf(" -- nope\n");
                } // else printf(" -- nope\n");
        }
        }
Line 278... Line 284...
        } else if ((strcasecmp("LOD",opc)==0)||(strcasecmp("LOAD",opc)==0)) {
        } else if ((strcasecmp("LOD",opc)==0)||(strcasecmp("LOAD",opc)==0)) {
                if (rb != ZIP_Rnone)
                if (rb != ZIP_Rnone)
                        ins = op_lod(cnd,imm,rb,ra);
                        ins = op_lod(cnd,imm,rb,ra);
                else    ins = op_lod(cnd,imm,ra);
                else    ins = op_lod(cnd,imm,ra);
        } else if ((strcasecmp("STO",opc)==0)||(strcasecmp("STOR",opc)==0)) {
        } else if ((strcasecmp("STO",opc)==0)||(strcasecmp("STOR",opc)==0)) {
 
                // printf("STO: Imm = %d, RA = %d, RB = %d\n", imm, ra, rb);
                if (rb != ZIP_Rnone)
                if (rb != ZIP_Rnone)
                        ins = op_sto(cnd,rb,imm,ra);
                        ins = op_sto(cnd,ra,imm,rb);
                else    ins = op_sto(cnd,rb,imm);
                else    ins = op_sto(cnd,ra,imm);
        } else if (strcasecmp("SUB",opc)==0) {
        } else if (strcasecmp("SUB",opc)==0) {
                if (rb != ZIP_Rnone)
                if (rb != ZIP_Rnone)
                        ins = op_sub(cnd,imm,rb,ra);
                        ins = op_sub(cnd,imm,rb,ra);
                else    ins = op_sub(cnd,imm,ra);
                else    ins = op_sub(cnd,imm,ra);
        } else if (strcasecmp("AND",opc)==0) {
        } else if (strcasecmp("AND",opc)==0) {
Line 355... Line 362...
        } else if (strcasecmp("CLRF",opc)==0) {
        } else if (strcasecmp("CLRF",opc)==0) {
                if ((ra == ZIP_Rnone)&&(!dollar)&&(imm==0))
                if ((ra == ZIP_Rnone)&&(!dollar)&&(imm==0))
                        ins = op_clrf(cnd, rb);
                        ins = op_clrf(cnd, rb);
                else    valid = false;
                else    valid = false;
        } else if((strcasecmp("HALT",opc)==0)||(strcasecmp("WAIT",opc)==0)) {
        } else if((strcasecmp("HALT",opc)==0)||(strcasecmp("WAIT",opc)==0)) {
                if ((rb == ZIP_Rnone)&&(ra==ZIP_Rnone)&&(!comma)&&(!dollar))
                if ((rb == ZIP_Rnone)&&(ra==ZIP_Rnone)&&(!opa)&&(!dollar))
                        ins = op_halt(cnd);
                        ins = op_halt(cnd);
                else    valid = false;
                else    valid = false;
        } else if (strcasecmp("BUSY",opc)==0) {
        } else if (strcasecmp("BUSY",opc)==0) {
                if ((rb == ZIP_Rnone)&&(ra==ZIP_Rnone)&&(!comma)&&(!dollar))
                if ((rb == ZIP_Rnone)&&(ra==ZIP_Rnone)&&(!opa)&&(!dollar))
                        ins = op_busy(cnd);
                        ins = op_busy(cnd);
                else    valid = false;
                else    valid = false;
        } else if (strcasecmp("RTU",opc)==0) {
        } else if (strcasecmp("RTU",opc)==0) {
                if ((rb == ZIP_Rnone)&&(ra==ZIP_Rnone)&&(imm==0)&&(!comma)&&(!dollar))
                if ((rb == ZIP_Rnone)&&(ra==ZIP_Rnone)&&(imm==0)&&(!opa)&&(!dollar))
                        ins = op_rtu(cnd);
                        ins = op_rtu(cnd);
                else    { printf("ERRR,RTU, ra=%d,rb=%d,imm=%08x,comma=%s,dollar=%s\n",
                else    { printf("ERRR,RTU, ra=%d,rb=%d,imm=%08x,comma=%s,dollar=%s\n",
                                (int)ra, (int)rb, imm, (comma)?"true":"false",
                                (int)ra, (int)rb, imm, (opa)?"true":"false",
                                (dollar)?"true":"false");
                                (dollar)?"true":"false");
                        valid = false;
                        valid = false;
                }
                }
        } else if (strcasecmp("JMP",opc)==0) {
        } else if (strcasecmp("JMP",opc)==0) {
                if ((rb != ZIP_Rnone)&&(!comma))
                if ((rb != ZIP_Rnone)&&(!opa))
                        ins = op_not(cnd, rb);
                        ins = op_not(cnd, rb);
                else    valid = false;
                else    valid = false;
        } else if (strcasecmp("NOT",opc)==0) {
        } else if (strcasecmp("NOT",opc)==0) {
                if ((rb != ZIP_Rnone)&&(ra==ZIP_Rnone)&&(!comma)&&(!dollar))
                if ((rb != ZIP_Rnone)&&(ra==ZIP_Rnone)&&(!opa)&&(!dollar))
                        ins = op_not(cnd, rb);
                        ins = op_not(cnd, rb);
                else    valid = false;
                else    valid = false;
        } else  valid = false;
        } else  valid = false;
 
 
        return valid;
        return valid;

powered by: WebSVN 2.1.0

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