コード例 #1
0
ファイル: ParseFunction.c プロジェクト: BigEd/Cores
/*
 *      funcbody starts with the current symbol being either
 *      the first parameter id or the begin for the local
 *      block. If begin is the current symbol then funcbody
 *      assumes that the function has no parameters.
 */
int ParseFunction(SYM *sp)
{
	int poffset, i;
	int oldglobal;
    SYM *sp1, *sp2;
	Statement *stmt;

	if (sp==NULL) {
		fatal("Compiler error: ParseFunction: SYM is NULL\r\n");
	}
	sp->stkname = stkname;
	if (verbose) printf("Parsing function: %s\r\n", sp->name);
		oldglobal = global_flag;
        global_flag = 0;
        poffset = 24;            /* size of return block */
        nparms = 0;
		iflevel = 0;
		// There could be unnamed parameters in a function prototype.
        if(lastst == id || 1) {              /* declare parameters */
                //while(lastst == id) {
                //        names[nparms++] = litlate(lastid);
                //        NextToken();
                //        if( lastst == comma)
                //                NextToken();
                //        else
                //                break;
                //        }
                //needpunc(closepa);
//                dodecl(sc_member);      /* declare parameters */
				sp->parms = (SYM *)NULL;
				ParseParameterDeclarations(1);
                for(i = 0;i < nparms;++i) {
                        if( (sp1 = search(names[i],&lsyms)) == NULL)
                                sp1 = makeint(names[i]);
						//if( sp1->tp->size < 8 )
						//{
						//	sp1->value.i = poffset;// + (8 - sp1->tp->size);
						//	poffset += 8;
						//}
						//else
						//{
						//	sp1->value.i = poffset;
						//	poffset += sp1->tp->size;
						//}
						sp1->value.i = poffset;
						// Check for aggregate types passed as parameters. Structs
						// and unions use the type size. 
					//	if (sp1->tp->type==bt_struct || sp1->tp->type==bt_union) {
    						poffset += round8(sp1->tp->size);
    						if (round8(sp1->tp->size) > 8)
    						   sp->IsLeaf = FALSE;
                    //     }
                    //     else
                    //         poffset += 8;
						//sp1->value.i = poffset;
						//poffset += 8;
                        sp1->storage_class = sc_auto;
						sp1->nextparm = (SYM *)NULL;
						// record parameter list
						if (sp->parms == (SYM *)NULL) {
							sp->parms = sp1;
						}
						else {
							sp1->nextparm = sp->parms;
							sp->parms = sp1;
						}
					}
					// Process extra hidden parameter
					if (sp->tp->btp->type==bt_struct || sp->tp->btp->type==bt_union) {
                         sp1 = makeint(litlate("_pHiddenStructPtr"));
                         sp1->value.i = poffset;
                         poffset += 8;
                         sp1->storage_class = sc_auto;
  	  	 	 	 	 	 sp1->nextparm = (SYM *)NULL;
						// record parameter list
						if (sp->parms == (SYM *)NULL) {
							sp->parms = sp1;
						}
						else {
							sp1->nextparm = sp->parms;
							sp->parms = sp1;
						}
						nparms++;
                    }
                }
		if (lastst == closepa)
			NextToken();
		if (sp->tp->type == bt_pointer) {
			if (lastst==assign) {
				doinit(sp);
			}
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsKernel = isKernel;
			sp->IsInterrupt = isInterrupt;
			sp->IsTask = isTask;
			sp->NumParms = nparms;
			isPascal = FALSE;
			isKernel = FALSE;
			isOscall = FALSE;
			isInterrupt = FALSE;
			isTask = FALSE;
			isNocall = FALSE;
		    ReleaseLocalMemory();        /* release local symbols (parameters)*/
			global_flag = oldglobal;
			return 1;
		}
		if (lastst == semicolon) {	// Function prototype
			sp->IsPrototype = 1;
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsKernel = isKernel;
			sp->IsInterrupt = isInterrupt;
			sp->IsTask = isTask;
			sp->NumParms = nparms;
			isPascal = FALSE;
			isKernel = FALSE;
			isOscall = FALSE;
			isInterrupt = FALSE;
			isTask = FALSE;
			isNocall = FALSE;
		    ReleaseLocalMemory();        /* release local symbols (parameters)*/
			goto j1;
		}
		else if(lastst != begin) {
//			NextToken();
			ParseParameterDeclarations(2);
			// for old-style parameter list
			//needpunc(closepa);
			if (lastst==semicolon) {
				sp->IsPrototype = 1;
				sp->IsNocall = isNocall;
				sp->IsPascal = isPascal;
    			sp->IsKernel = isKernel;
				sp->IsInterrupt = isInterrupt;
    			sp->IsTask = isTask;
				sp->NumParms = nparms;
				isPascal = FALSE;
    			isKernel = FALSE;
				isOscall = FALSE;
				isInterrupt = FALSE;
    			isTask = FALSE;
				isNocall = FALSE;
				ReleaseLocalMemory();        /* release local symbols (parameters)*/
			}
			// Check for end of function parameter list.
			else if (funcdecl==2 && lastst==closepa) {
				;
			}
			else {
				sp->IsNocall = isNocall;
				sp->IsPascal = isPascal;
    			sp->IsKernel = isKernel;
				sp->IsInterrupt = isInterrupt;
    			sp->IsTask = isTask;
				isPascal = FALSE;
    			isKernel = FALSE;
				isOscall = FALSE;
				isInterrupt = FALSE;
    			isTask = FALSE;
				isNocall = FALSE;
				sp->NumParms = nparms;
				stmt = ParseFunctionBody(sp);
				funcbottom(stmt);
			}
		}
//                error(ERR_BLOCK);
        else {
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsKernel = isKernel;
			sp->IsInterrupt = isInterrupt;
			sp->IsTask = isTask;
			isPascal = FALSE;
			isKernel = FALSE;
			isOscall = FALSE;
			isInterrupt = FALSE;
			isTask = FALSE;
			isNocall = FALSE;
			sp->NumParms = nparms;
			stmt = ParseFunctionBody(sp);
			funcbottom(stmt);
        }
j1:
		global_flag = oldglobal;
		return 0;
}
コード例 #2
0
ファイル: ParseDeclarations.c プロジェクト: BigEd/Cores
// Take care of the () or [] trailing part of a declaration
//
void ParseDeclarationSuffix()
{
	TYP     *temp1;
	int fd, npf;
	char *odecl;
	TYP *tempHead, *tempTail;

    switch (lastst) {
    case openbr:
        NextToken();
        temp1 = maketype(bt_pointer,0);
        temp1->val_flag = 1;
        temp1->isArray = TRUE;
        temp1->btp = head;
        if(lastst == closebr) {
			temp1->size = 0;
			NextToken();
        }
        else if(head != NULL) {
			temp1->size = GetIntegerExpression((ENODE **)NULL) * head->size;
			temp1->alignment = head->alignment;
			needpunc(closebr);
		}
        else {
			temp1->size = GetIntegerExpression((ENODE **)NULL);
			needpunc(closebr);
		}
        head = temp1;
        if( tail == NULL)
                tail = head;
        ParseDeclarationSuffix();
        break;
    case openpa:
        NextToken();
        temp1 = maketype(bt_func,0);
        temp1->val_flag = 1;
        temp1->btp = head;
        head = temp1;
		needParseFunction = TRUE;
		if (tail==NULL) {
			if (temp1->btp)
				tail = temp1->btp;
			else
				tail = temp1;
		}
        if( lastst == closepa) {
            NextToken();
//            temp1->type = bt_ifunc;			// this line wasn't present
			if(lastst == begin) {
                temp1->type = bt_ifunc;
			}
			else
				needParseFunction = FALSE;
        }
		else {
            temp1->type = bt_ifunc;
			// Parse the parameter list for a function pointer passed as a
			// parameter.
			// Parse parameter list for a function pointer defined within
			// a structure.
			if (parsingParameterList || isStructDecl) {
				fd = funcdecl;
				needParseFunction = FALSE;
				odecl = declid;
				tempHead = head;
				tempTail = tail;
				ParseParameterDeclarations(10);	// parse and discard
				head = tempHead;
				tail = tempTail;
				declid = odecl;
				funcdecl = fd;
				needpunc(closepa);
				if (lastst != begin)
					temp1->type = bt_func;
			}
		}
        break;
    }
}
コード例 #3
0
ファイル: ParseFunction.c プロジェクト: freecores/raptor64
/*
 *      funcbody starts with the current symbol being either
 *      the first parameter id or the begin for the local
 *      block. If begin is the current symbol then funcbody
 *      assumes that the function has no parameters.
 */
void ParseFunction(SYM *sp)
{
	int poffset, i;
	int oldglobal;
    SYM *sp1, *sp2, *makeint();

		oldglobal = global_flag;
        global_flag = 0;
        poffset = 24;            /* size of return block */
        nparms = 0;
        if(lastst == id || 1) {              /* declare parameters */
                //while(lastst == id) {
                //        names[nparms++] = litlate(lastid);
                //        NextToken();
                //        if( lastst == comma)
                //                NextToken();
                //        else
                //                break;
                //        }
                //needpunc(closepa);
//                dodecl(sc_member);      /* declare parameters */
				sp->parms = NULL;
				ParseParameterDeclarations(1);
                for(i = 0;i < nparms;++i) {
                        if( (sp1 = search(names[i],&lsyms)) == NULL)
                                sp1 = makeint(names[i]);
						//if( sp1->tp->size < 8 )
						//{
						//	sp1->value.i = poffset;// + (8 - sp1->tp->size);
						//	poffset += 8;
						//}
						//else
						//{
						//	sp1->value.i = poffset;
						//	poffset += sp1->tp->size;
						//}
						sp1->value.i = poffset;
						poffset += 8;
                        sp1->storage_class = sc_auto;
						sp1->nextparm = NULL;
						// record parameter list
						if (sp->parms == NULL) {
							sp->parms = sp1;
						}
						else {
							sp1->nextparm = sp->parms;
							sp->parms = sp1;
						}
					}
                }
		if (lastst == closepa)
			NextToken();
		if (lastst == semicolon) {	// Function prototype
			sp->IsPrototype = 1;
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsInterrupt = isInterrupt;
			sp->NumParms = nparms;
			isPascal = FALSE;
			isOscall = FALSE;
			isInterrupt = FALSE;
			isNocall = FALSE;
		    ReleaseLocalMemory();        /* release local symbols (parameters)*/
		}
		else if(lastst != begin) {
			NextToken();
			ParseParameterDeclarations(2);
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsInterrupt = isInterrupt;
			sp->NumParms = nparms;
			ParseFunctionBody(sp);
			funcbottom();
		}
//                error(ERR_BLOCK);
        else {
			sp->IsNocall = isNocall;
			sp->IsPascal = isPascal;
			sp->IsInterrupt = isInterrupt;
			sp->NumParms = nparms;
			ParseFunctionBody(sp);
			funcbottom();
        }
		global_flag = oldglobal;
}