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

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.26/] [fp/] [investigate/] [main.c] - Diff between revs 15 and 270

Only display areas with differences | Details | Blame | View Log

Rev 15 Rev 270
#include "c.h"
#include "c.h"
 
 
static char rcsid[] = "$Name: v4_2 $($Id: main.c,v 1.1 2002/08/28 23:12:44 drh Exp $)";
static char rcsid[] = "$Name: v4_2 $($Id: main.c,v 1.1 2002/08/28 23:12:44 drh Exp $)";
 
 
static void typestab(Symbol, void *);
static void typestab(Symbol, void *);
 
 
static void stabline(Coordinate *);
static void stabline(Coordinate *);
static void stabend(Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *);
static void stabend(Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *);
Interface *IR = NULL;
Interface *IR = NULL;
 
 
int Aflag;              /* >= 0 if -A specified */
int Aflag;              /* >= 0 if -A specified */
int Pflag;              /* != 0 if -P specified */
int Pflag;              /* != 0 if -P specified */
int glevel;             /* == [0-9] if -g[0-9] specified */
int glevel;             /* == [0-9] if -g[0-9] specified */
int xref;               /* != 0 for cross-reference data */
int xref;               /* != 0 for cross-reference data */
Symbol YYnull;          /* _YYnull  symbol if -n or -nvalidate specified */
Symbol YYnull;          /* _YYnull  symbol if -n or -nvalidate specified */
Symbol YYcheck;         /* _YYcheck symbol if -nvalidate,check specified */
Symbol YYcheck;         /* _YYcheck symbol if -nvalidate,check specified */
 
 
static char *comment;
static char *comment;
static Interface stabIR;
static Interface stabIR;
static char *currentfile;       /* current file name */
static char *currentfile;       /* current file name */
static int currentline;         /* current line number */
static int currentline;         /* current line number */
static FILE *srcfp;             /* stream for current file, if non-NULL */
static FILE *srcfp;             /* stream for current file, if non-NULL */
static int srcpos;              /* position of srcfp, if srcfp is non-NULL */
static int srcpos;              /* position of srcfp, if srcfp is non-NULL */
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
        int i, j;
        int i, j;
        for (i = argc - 1; i > 0; i--)
        for (i = argc - 1; i > 0; i--)
                if (strncmp(argv[i], "-target=", 8) == 0)
                if (strncmp(argv[i], "-target=", 8) == 0)
                        break;
                        break;
        if (i > 0) {
        if (i > 0) {
                char *s = strchr(argv[i], '\\');
                char *s = strchr(argv[i], '\\');
                if (s != NULL)
                if (s != NULL)
                        *s = '/';
                        *s = '/';
                for (j = 0; bindings[j].name && bindings[j].ir; j++)
                for (j = 0; bindings[j].name && bindings[j].ir; j++)
                        if (strcmp(&argv[i][8], bindings[j].name) == 0) {
                        if (strcmp(&argv[i][8], bindings[j].name) == 0) {
                                IR = bindings[j].ir;
                                IR = bindings[j].ir;
                                break;
                                break;
                        }
                        }
                if (s != NULL)
                if (s != NULL)
                        *s = '\\';
                        *s = '\\';
        }
        }
        if (!IR) {
        if (!IR) {
                fprint(stderr, "%s: unknown target", argv[0]);
                fprint(stderr, "%s: unknown target", argv[0]);
                if (i > 0)
                if (i > 0)
                        fprint(stderr, " `%s'", &argv[i][8]);
                        fprint(stderr, " `%s'", &argv[i][8]);
                fprint(stderr, "; must specify one of\n");
                fprint(stderr, "; must specify one of\n");
                for (i = 0; bindings[i].name; i++)
                for (i = 0; bindings[i].name; i++)
                        fprint(stderr, "\t-target=%s\n", bindings[i].name);
                        fprint(stderr, "\t-target=%s\n", bindings[i].name);
                exit(EXIT_FAILURE);
                exit(EXIT_FAILURE);
        }
        }
        init(argc, argv);
        init(argc, argv);
        t = gettok();
        t = gettok();
        (*IR->progbeg)(argc, argv);
        (*IR->progbeg)(argc, argv);
        for (i = 1; i < argc; i++)
        for (i = 1; i < argc; i++)
                if (strcmp(argv[i], "-n") == 0) {
                if (strcmp(argv[i], "-n") == 0) {
                        if (!YYnull) {
                        if (!YYnull) {
                                YYnull = install(string("_YYnull"), &globals, GLOBAL, PERM);
                                YYnull = install(string("_YYnull"), &globals, GLOBAL, PERM);
                                YYnull->type = func(voidptype, NULL, 1);
                                YYnull->type = func(voidptype, NULL, 1);
                                YYnull->sclass = EXTERN;
                                YYnull->sclass = EXTERN;
                                (*IR->defsymbol)(YYnull);
                                (*IR->defsymbol)(YYnull);
                        }
                        }
                } else if (strncmp(argv[i], "-n", 2) == 0) {     /* -nvalid[,check] */
                } else if (strncmp(argv[i], "-n", 2) == 0) {     /* -nvalid[,check] */
                        char *p = strchr(argv[i], ',');
                        char *p = strchr(argv[i], ',');
                        if (p) {
                        if (p) {
                                YYcheck = install(string(p+1), &globals, GLOBAL, PERM);
                                YYcheck = install(string(p+1), &globals, GLOBAL, PERM);
                                YYcheck->type = func(voidptype, NULL, 1);
                                YYcheck->type = func(voidptype, NULL, 1);
                                YYcheck->sclass = EXTERN;
                                YYcheck->sclass = EXTERN;
                                (*IR->defsymbol)(YYcheck);
                                (*IR->defsymbol)(YYcheck);
                                p = stringn(argv[i]+2, p - (argv[i]+2));
                                p = stringn(argv[i]+2, p - (argv[i]+2));
                        } else
                        } else
                                p = string(argv[i]+2);
                                p = string(argv[i]+2);
                        YYnull = install(p, &globals, GLOBAL, PERM);
                        YYnull = install(p, &globals, GLOBAL, PERM);
                        YYnull->type = func(voidptype, NULL, 1);
                        YYnull->type = func(voidptype, NULL, 1);
                        YYnull->sclass = EXTERN;
                        YYnull->sclass = EXTERN;
                        (*IR->defsymbol)(YYnull);
                        (*IR->defsymbol)(YYnull);
                } else {
                } else {
                        profInit(argv[i]);
                        profInit(argv[i]);
                        traceInit(argv[i]);
                        traceInit(argv[i]);
                }
                }
        if (glevel && IR->stabinit)
        if (glevel && IR->stabinit)
                (*IR->stabinit)(firstfile, argc, argv);
                (*IR->stabinit)(firstfile, argc, argv);
        program();
        program();
        if (events.end)
        if (events.end)
                apply(events.end, NULL, NULL);
                apply(events.end, NULL, NULL);
        memset(&events, 0, sizeof events);
        memset(&events, 0, sizeof events);
        if (glevel || xref) {
        if (glevel || xref) {
                Symbol symroot = NULL;
                Symbol symroot = NULL;
                Coordinate src;
                Coordinate src;
                foreach(types,       GLOBAL, typestab, &symroot);
                foreach(types,       GLOBAL, typestab, &symroot);
                foreach(identifiers, GLOBAL, typestab, &symroot);
                foreach(identifiers, GLOBAL, typestab, &symroot);
                src.file = firstfile;
                src.file = firstfile;
                src.x = 0;
                src.x = 0;
                src.y = lineno;
                src.y = lineno;
                if ((glevel > 2 || xref) && IR->stabend)
                if ((glevel > 2 || xref) && IR->stabend)
                        (*IR->stabend)(&src, symroot,
                        (*IR->stabend)(&src, symroot,
                                ltov(&loci,    PERM),
                                ltov(&loci,    PERM),
                                ltov(&symbols, PERM), NULL);
                                ltov(&symbols, PERM), NULL);
                else if (IR->stabend)
                else if (IR->stabend)
                        (*IR->stabend)(&src, NULL, NULL, NULL, NULL);
                        (*IR->stabend)(&src, NULL, NULL, NULL, NULL);
        }
        }
        finalize();
        finalize();
        (*IR->progend)();
        (*IR->progend)();
        deallocate(PERM);
        deallocate(PERM);
        return errcnt > 0;
        return errcnt > 0;
}
}
/* main_init - process program arguments */
/* main_init - process program arguments */
void main_init(int argc, char *argv[]) {
void main_init(int argc, char *argv[]) {
        char *infile = NULL, *outfile = NULL;
        char *infile = NULL, *outfile = NULL;
        int i;
        int i;
        static int inited;
        static int inited;
 
 
        if (inited)
        if (inited)
                return;
                return;
        inited = 1;
        inited = 1;
        type_init(argc, argv);
        type_init(argc, argv);
        for (i = 1; i < argc; i++)
        for (i = 1; i < argc; i++)
                if (strcmp(argv[i], "-g") == 0 || strcmp(argv[i], "-g2") == 0)
                if (strcmp(argv[i], "-g") == 0 || strcmp(argv[i], "-g2") == 0)
                        glevel = 2;
                        glevel = 2;
                else if (strncmp(argv[i], "-g", 2) == 0) {       /* -gn[,x] */
                else if (strncmp(argv[i], "-g", 2) == 0) {       /* -gn[,x] */
                        char *p = strchr(argv[i], ',');
                        char *p = strchr(argv[i], ',');
                        glevel = atoi(argv[i]+2);
                        glevel = atoi(argv[i]+2);
                        if (p) {
                        if (p) {
                                comment = p + 1;
                                comment = p + 1;
                                if (glevel == 0)
                                if (glevel == 0)
                                        glevel = 1;
                                        glevel = 1;
                                if (stabIR.stabline == NULL) {
                                if (stabIR.stabline == NULL) {
                                        stabIR.stabline = IR->stabline;
                                        stabIR.stabline = IR->stabline;
                                        stabIR.stabend = IR->stabend;
                                        stabIR.stabend = IR->stabend;
                                        IR->stabline = stabline;
                                        IR->stabline = stabline;
                                        IR->stabend = stabend;
                                        IR->stabend = stabend;
                                }
                                }
                        }
                        }
                } else if (strcmp(argv[i], "-x") == 0)
                } else if (strcmp(argv[i], "-x") == 0)
                        xref++;
                        xref++;
                else if (strcmp(argv[i], "-A") == 0) {
                else if (strcmp(argv[i], "-A") == 0) {
                        ++Aflag;
                        ++Aflag;
                } else if (strcmp(argv[i], "-P") == 0)
                } else if (strcmp(argv[i], "-P") == 0)
                        Pflag++;
                        Pflag++;
                else if (strcmp(argv[i], "-w") == 0)
                else if (strcmp(argv[i], "-w") == 0)
                        wflag++;
                        wflag++;
                else if (strcmp(argv[i], "-v") == 0)
                else if (strcmp(argv[i], "-v") == 0)
                        fprint(stderr, "%s %s\n", argv[0], rcsid);
                        fprint(stderr, "%s %s\n", argv[0], rcsid);
                else if (strncmp(argv[i], "-s", 2) == 0)
                else if (strncmp(argv[i], "-s", 2) == 0)
                        density = strtod(&argv[i][2], NULL);
                        density = strtod(&argv[i][2], NULL);
                else if (strncmp(argv[i], "-errout=", 8) == 0) {
                else if (strncmp(argv[i], "-errout=", 8) == 0) {
                        FILE *f = fopen(argv[i]+8, "w");
                        FILE *f = fopen(argv[i]+8, "w");
                        if (f == NULL) {
                        if (f == NULL) {
                                fprint(stderr, "%s: can't write errors to `%s'\n", argv[0], argv[i]+8);
                                fprint(stderr, "%s: can't write errors to `%s'\n", argv[0], argv[i]+8);
                                exit(EXIT_FAILURE);
                                exit(EXIT_FAILURE);
                        }
                        }
                        fclose(f);
                        fclose(f);
                        f = freopen(argv[i]+8, "w", stderr);
                        f = freopen(argv[i]+8, "w", stderr);
                        assert(f);
                        assert(f);
                } else if (strncmp(argv[i], "-e", 2) == 0) {
                } else if (strncmp(argv[i], "-e", 2) == 0) {
                        int x;
                        int x;
                        if ((x = strtol(&argv[i][2], NULL, 0)) > 0)
                        if ((x = strtol(&argv[i][2], NULL, 0)) > 0)
                                errlimit = x;
                                errlimit = x;
                } else if (strncmp(argv[i], "-little_endian=", 15) == 0)
                } else if (strncmp(argv[i], "-little_endian=", 15) == 0)
                        IR->little_endian = argv[i][15] - '0';
                        IR->little_endian = argv[i][15] - '0';
                else if (strncmp(argv[i], "-mulops_calls=", 18) == 0)
                else if (strncmp(argv[i], "-mulops_calls=", 18) == 0)
                        IR->mulops_calls = argv[i][18] - '0';
                        IR->mulops_calls = argv[i][18] - '0';
                else if (strncmp(argv[i], "-wants_callb=", 13) == 0)
                else if (strncmp(argv[i], "-wants_callb=", 13) == 0)
                        IR->wants_callb = argv[i][13] - '0';
                        IR->wants_callb = argv[i][13] - '0';
                else if (strncmp(argv[i], "-wants_argb=", 12) == 0)
                else if (strncmp(argv[i], "-wants_argb=", 12) == 0)
                        IR->wants_argb = argv[i][12] - '0';
                        IR->wants_argb = argv[i][12] - '0';
                else if (strncmp(argv[i], "-left_to_right=", 15) == 0)
                else if (strncmp(argv[i], "-left_to_right=", 15) == 0)
                        IR->left_to_right = argv[i][15] - '0';
                        IR->left_to_right = argv[i][15] - '0';
                else if (strncmp(argv[i], "-wants_dag=", 11) == 0)
                else if (strncmp(argv[i], "-wants_dag=", 11) == 0)
                        IR->wants_dag = argv[i][11] - '0';
                        IR->wants_dag = argv[i][11] - '0';
                else if (*argv[i] != '-' || strcmp(argv[i], "-") == 0) {
                else if (*argv[i] != '-' || strcmp(argv[i], "-") == 0) {
                        if (infile == NULL)
                        if (infile == NULL)
                                infile = argv[i];
                                infile = argv[i];
                        else if (outfile == NULL)
                        else if (outfile == NULL)
                                outfile = argv[i];
                                outfile = argv[i];
                }
                }
 
 
        if (infile != NULL && strcmp(infile, "-") != 0
        if (infile != NULL && strcmp(infile, "-") != 0
        && freopen(infile, "r", stdin) == NULL) {
        && freopen(infile, "r", stdin) == NULL) {
                fprint(stderr, "%s: can't read `%s'\n", argv[0], infile);
                fprint(stderr, "%s: can't read `%s'\n", argv[0], infile);
                exit(EXIT_FAILURE);
                exit(EXIT_FAILURE);
        }
        }
        if (outfile != NULL && strcmp(outfile, "-") != 0
        if (outfile != NULL && strcmp(outfile, "-") != 0
        && freopen(outfile, "w", stdout) == NULL) {
        && freopen(outfile, "w", stdout) == NULL) {
                fprint(stderr, "%s: can't write `%s'\n", argv[0], outfile);
                fprint(stderr, "%s: can't write `%s'\n", argv[0], outfile);
                exit(EXIT_FAILURE);
                exit(EXIT_FAILURE);
        }
        }
}
}
/* typestab - emit stab entries for p */
/* typestab - emit stab entries for p */
static void typestab(Symbol p, void *cl) {
static void typestab(Symbol p, void *cl) {
        if (*(Symbol *)cl == 0 && p->sclass && p->sclass != TYPEDEF)
        if (*(Symbol *)cl == 0 && p->sclass && p->sclass != TYPEDEF)
                *(Symbol *)cl = p;
                *(Symbol *)cl = p;
        if ((p->sclass == TYPEDEF || p->sclass == 0) && IR->stabtype)
        if ((p->sclass == TYPEDEF || p->sclass == 0) && IR->stabtype)
                (*IR->stabtype)(p);
                (*IR->stabtype)(p);
}
}
 
 
/* stabline - emit source code for source coordinate *cp */
/* stabline - emit source code for source coordinate *cp */
static void stabline(Coordinate *cp) {
static void stabline(Coordinate *cp) {
        if (cp->file && cp->file != currentfile) {
        if (cp->file && cp->file != currentfile) {
                if (srcfp)
                if (srcfp)
                        fclose(srcfp);
                        fclose(srcfp);
                currentfile = cp->file;
                currentfile = cp->file;
                srcfp = fopen(currentfile, "r");
                srcfp = fopen(currentfile, "r");
                srcpos = 0;
                srcpos = 0;
                currentline = 0;
                currentline = 0;
        }
        }
        if (currentline != cp->y && srcfp) {
        if (currentline != cp->y && srcfp) {
                char buf[512];
                char buf[512];
                if (srcpos > cp->y) {
                if (srcpos > cp->y) {
                        rewind(srcfp);
                        rewind(srcfp);
                        srcpos = 0;
                        srcpos = 0;
                }
                }
                for ( ; srcpos < cp->y; srcpos++)
                for ( ; srcpos < cp->y; srcpos++)
                        if (fgets(buf, sizeof buf, srcfp) == NULL) {
                        if (fgets(buf, sizeof buf, srcfp) == NULL) {
                                fclose(srcfp);
                                fclose(srcfp);
                                srcfp = NULL;
                                srcfp = NULL;
                                break;
                                break;
                        }
                        }
                if (srcfp && srcpos == cp->y)
                if (srcfp && srcpos == cp->y)
                        print("%s%s", comment, buf);
                        print("%s%s", comment, buf);
        }
        }
        currentline = cp->y;
        currentline = cp->y;
        if (stabIR.stabline)
        if (stabIR.stabline)
                (*stabIR.stabline)(cp);
                (*stabIR.stabline)(cp);
}
}
 
 
static void stabend(Coordinate *cp, Symbol p, Coordinate **cpp, Symbol *sp, Symbol *stab) {
static void stabend(Coordinate *cp, Symbol p, Coordinate **cpp, Symbol *sp, Symbol *stab) {
        if (stabIR.stabend)
        if (stabIR.stabend)
                (*stabIR.stabend)(cp, p, cpp, sp, stab);
                (*stabIR.stabend)(cp, p, cpp, sp, stab);
        if (srcfp)
        if (srcfp)
                fclose(srcfp);
                fclose(srcfp);
}
}
 
 

powered by: WebSVN 2.1.0

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