Exemplo n.º 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);
	}
}
Exemplo n.º 2
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);
	}
}