Esempio n. 1
0
void push_string (char * str) {
	// push onto string stack
	// save the label value into the offset field
	ipush (strstack, str, UNKNOWN, 0, strlabelcount, REFERENCE);
	// push onto operand stack - store offset in val field
	ipush (inststack, NULL, STRING, strlabelcount, 0, IMMEDIATE);
	// increment string label
	strlabelcount++;
}
Esempio n. 2
0
void generate_num2str () {
	fprintf (fp, "\tpushl\t$12\n");
	fprintf (fp, "\tcall\tmalloc\n");
	fprintf (fp, "\taddl\t$4, %%esp\n");
	fprintf (fp, "\tpushl\t$.LC%d\n", strlabelcount);
	fprintf (fp, "\tpushl\t%%eax\n");
	fprintf (fp, "\tcall\tsprintf\n");
	fprintf (fp, "\tmovl\t0(%%esp), %%eax\n");
	fprintf (fp, "\taddl\t$12, %%esp\n");
	fprintf (fp, "\tpushl\t%%eax\n");
	// write format integer string to strstack
	ipush (strstack, "%d", UNKNOWN, 0, strlabelcount, REFERENCE);
	strlabelcount++;
}
Esempio n. 3
0
void push_fparam ( char * id, TYPE t, MEMTYPE mt, int val ) {
	unsigned int offsetoverride = 0;
	int valoverride = val;
	// check for arithmetic result argument and mark stack position
	if (mt == RESULT) {
		param_spoffset += 4;
		offsetoverride = param_spoffset;
	} else if (mt == IMMEDIATE && t == STRING) {
		valoverride = strlabelcount-1;
		dump_operands (); // dump unused operands remaining in inststack
	} else {
		dump_operands ();
	}
	ipush (paramstack, id, t, valoverride, offsetoverride, mt);
}
Esempio n. 4
0
void push_operand ( char * id, int val, MEMTYPE m ) {
	node * temp;
	TYPE tt;
	// check if this is a FOR loop condition
	if (sts->current_scope->loopBegLabel > 0 && !suppressIter) {
		//fprintf (fp, "set for iteration\n");
		generate_for_iter_inst ();
		suppressIter = 1;
	}
	// if we're pushing an id then we need to lookup in the symtab
	if (m == REFERENCE) {
		if ( (temp = lookup (sts, id)) == NULL )
			error_handler(UNDECLARED_ID_ERROR, id);
		tt = temp->t;
	} else {
		tt = INT;
	}
	// push operand onto instruction stack
	ipush (inststack, id, tt, val, 0, m);
}
Esempio n. 5
0
void push_back_global ( char * id ) {
	// push on global declaration stack
	ipush (globstack, id, UNKNOWN, 0, 0, REFERENCE);
}
Esempio n. 6
0
void
parse(char *f, int fd, int varoverride)
{
    int hline;
    char *body;
    Word *head, *tail;
    int attr, set, pid;
    char *prog, *p;
    int newfd;
    Biobuf in;
    Bufblock *buf;

    if(fd < 0) {
        perror(f);
        Exit();
    }
    ipush();
    infile = strdup(f);
    mkinline = 1;
    Binit(&in, fd, OREAD);
    buf = newbuf();
    while(assline(&in, buf)) {
        hline = mkinline;
        switch(rhead(buf->start, &head, &tail, &attr, &prog))
        {
        case '<':
            p = wtos(tail, ' ');
            if(*p == 0) {
                SYNERR(-1);
                fprint(2, "missing include file name\n");
                Exit();
            }
            newfd = open(p, OREAD);
            if(newfd < 0) {
                fprint(2, "warning: skipping missing include file: ");
                perror(p);
            } else
                parse(p, newfd, 0);
            break;
        case '|':
            p = wtos(tail, ' ');
            if(*p == 0) {
                SYNERR(-1);
                fprint(2, "missing include program name\n");
                Exit();
            }
            execinit();
            pid=pipecmd(p, envy, &newfd);
            if(newfd < 0) {
                fprint(2, "warning: skipping missing program file: ");
                perror(p);
            } else
                parse(p, newfd, 0);
            while(waitup(-3, &pid) >= 0)
                ;
            if(pid != 0) {
                fprint(2, "bad include program status\n");
                Exit();
            }
            break;
        case ':':
            body = rbody(&in);
            addrules(head, tail, body, attr, hline, prog);
            break;
        case '=':
            if(head->next) {
                SYNERR(-1);
                fprint(2, "multiple vars on left side of assignment\n");
                Exit();
            }
            if(symlook(head->s, S_OVERRIDE, 0)) {
                set = varoverride;
            } else {
                set = 1;
                if(varoverride)
                    symlook(head->s, S_OVERRIDE, (void *)"");
            }
            if(set) {
                /*
                char *cp;
                dumpw("tail", tail);
                cp = wtos(tail, ' '); print("assign %s to %s\n", head->s, cp); free(cp);
                */
                setvar(head->s, (void *) tail);
                symlook(head->s, S_WESET, (void *)"");
            }
            if(attr)
                symlook(head->s, S_NOEXPORT, (void *)"");
            break;
        default:
            SYNERR(hline);
            fprint(2, "expected one of :<=\n");
            Exit();
            break;
        }
    }
    close(fd);
    freebuf(buf);
    ipop();
}