Exemple #1
0
/*	Compile the source code using the constructed Abstract Syntax Tree 
	Arguments are the root nodes of -
	1) Global declaration AST,
	2) Function definitions AST
	3) main() function definition AST
	*/
void compile(Tnode *gdeclroot,Tnode *fdefroot,Tnode *mainroot)
{
	error = 0;
	loc = 0;

	globalInstall(gdeclroot);
	
	if(fdefroot != NULL)
	{
		funcSemanticCheck(fdefroot);
		checkFuncDecl(fdefroot->LINE);
		funcSemanticCheck(mainroot);
	}
	
	printf("\nRUN - \n");
	if(error == 0)
	{
		Gallocate();
		funcroot = fdefroot;
		mroot = mainroot;
		
		struct Lsymbol *Ltable;
		Ltable = NULL;
		interpreter(mainroot,&Ltable);
		
		fp = fopen("SIMCode","w");
		regcnt = 0;
		labelcnt = -1;
		codeGenerate(mainroot->Ptr2);
		fclose(fp);
	}
}
Exemple #2
0
/*	Check a function's definition for semantic errors
	*/
int funcSemanticCheck(Tnode *root)
{
	ArgStruct *arg;
	struct Lsymbol *Lhead;
	
	Lhead = NULL;
	
	if(root == NULL)
		return;
	
	switch(root->NODETYPE)
	{
		case CONTINUE		:	funcSemanticCheck(root->Ptr1);
								funcSemanticCheck(root->Ptr2);
								return;
		
		case FUNCBLOCK		:	argLocalInstall(root->ArgList,&Lhead);
								
								gtemp = Glookup(root->NAME);
								functype = root->Ptr1->TYPE;
								
								funcTypeCheck(root);
								
								if(gtemp)
								{
									funcArgCheck(root->ArgList);
									
									arg = gtemp->ARGLIST;
									
									while(arg)
									{
										if(arg->FLAG == 0)
										{
											printf("\nSIL:%d: Error: parameter '%s' has been defined in global declaration of function '%s', but is missing in definition",root->ArgList->LINE,arg->NAME,gtemp->NAME);
											error++;
										}
										arg = arg->NEXT;
									}
								}
								
								localInstall(root->Ptr2,&Lhead);
								bodySemanticCheck(root->Ptr3,&Lhead);
								
								return;
		
		case MAINBLOCK		:	functype = root->TYPE;
								localInstall(root->Ptr1,&Lhead);
								bodySemanticCheck(root->Ptr2,&Lhead);
								
								return;
	}
}
Exemple #3
0
/*	Compile the source code using the constructed Abstract Syntax Tree 
	Arguments are the root nodes of -
	1) Global declaration AST,
	2) Function definitions AST
	3) main() function definition AST
	*/
void compile(Tnode *gdeclroot,Tnode *fdefroot,Tnode *mainroot)
{
	error = 0;
	
	locpos = -1;
	labelcnt = 0;
	globalInstall(gdeclroot);
	
	if(fdefroot != NULL)
	{
		funcSemanticCheck(fdefroot);
		checkFuncDecl(fdefroot->LINE);
		funcSemanticCheck(mainroot);
	}
	
	printf("\nRUN - \n");
	if(error == 0)
	{
		module = INTERPRET;
		Gallocate();
		funcroot = fdefroot;
		mroot = mainroot;
		
		struct Lsymbol *Ltable;
		Ltable = NULL;
		interpreter(mainroot,&Ltable);
		
		get = 0;
		fre = 0;
		
		regcnt = -1;
		module = CODEGEN;
		fp = fopen("SIM_Simulator/SIMcode","w");
		funcCodeGen(fdefroot);
		funcCodeGen(mainroot);
		callToMain();
		
		fclose(fp);
	}
}