Example #1
0
AZONAL* SymboleAddFunctionCall ( char* name , int azonaltype , int tacktotall , int line ) {

	//	author : Jelo Wang
	//	20110212
	//	(C)TOK

	AZONAL* azonal = 0 ;
	
	ASSERT(name);

	azonal = SCMalloc ( sizeof(AZONAL) ) ;
	ASSERT(azonal) ;
	
	azonal->name = SCMalloc ( sc_strlen ( name ) + 1 ) ;
	ASSERT(azonal->name);
	sc_strcpy ( azonal->name , name ) ;

	azonal->azonaltype = azonaltype ;
	azonal->tack.totall = tacktotall ;
	azonal->line = line ;

	if ( 0 == symbole->funccal.next ) {
		symbole->funccal.next = azonal ;
		symbole->funccal.head = azonal ;
	} else {
		symbole->funccal.next->next = azonal ;
		symbole->funccal.next = azonal ;
	}

	return azonal ;
	
}
Example #2
0
void MMTAdd ( char* file , int line , int length , int address ) {
	
	//	author : Jelo Wang
	//	since : 20100418
	//	(C)TOK

	MEMORY_MONITOR* newmem = 0 ;
		
	newmem	= (MEMORY_MONITOR* ) malloc ( sizeof(MEMORY_MONITOR) ) ;

	if ( 0 == mmt_mask ) MMTCreateMask () ;
	
	memcpy ( (void*)((unsigned int)address+length) , mmt_mask , MMT_MASK_LENGTH ) ;

	if ( file ) {
		newmem->file = (char* ) malloc ( sc_strlen ( file ) + 1 ) ;
		sc_strcpy ( newmem->file , file ) ;
	}

	newmem->line = line ; 
	newmem->length = length ;
	newmem->address = address ;
	newmem->head = 0 ;
	newmem->next = 0 ;
 
	if ( 0 == mem_monitor.head ) {
		mem_monitor.head = newmem ;
		mem_monitor.next = newmem ;
	} else {
		mem_monitor.next->next = newmem ;
		mem_monitor.next = newmem ;
	}

}
Example #3
0
static int asmor_arm_read_variable_inf () {

	
	//	author : Jelo Wang
	//	since : 20100722
	//	(C)TOK

	char R [32] = { 0 } ;
	char Rd [32] = { 0 } ;
	char Rn [32] = { 0 } ;
	char Rm [32] = { 0 } ;

	int state = 0 ;
	
	if ( LAIR_VAR != lexlair->v ) return 0 ;

	sc_strcpy ( R , SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ) ;
	sc_strcat_ex ( "R" , R , Rd ) ;

	while ( !lexlair->stop ) {

		LexerLairGenv () ;
				
		switch ( state ) {
			case 0 :		
				if ( LAIR_EQU == lexlair->v ) {
					state = 1 ;
				}
			break ;
			case 1 :
/*				if ( LAIR_VAR == lexlair->v || LAIR_VREG == lexlair->v ) {
					char* R = SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn )  ) ;
					sc_strcat_ex ( "R" , R , Rn ) ;				
 					THUMB_MOV_RdRn ( Rd , Rn ) ;
					return 1 ;
				} else if ( LAIR_INTNUM == lexlair->v ) {		
 					THUMB_MOV_RdImmed_8 ( Rd , lexlair->token ) ;
					return 1 ;				
				}
*/
 			break ;
		}

	}	

	return 1 ;

}
Example #4
0
AZONAL* SymboleAddFunction ( char* name , int azonaltype , int type , int line ) {

	//	author : Jelo Wang
	//	input : name,type of return value,line
	//	output: insert a function record into symbol table
	//	(C)TOK


	AZONAL* azonal = (AZONAL* ) SCMalloc ( sizeof(AZONAL) ) ;

	if ( !azonal || !symbole  ) return 0 ;
		
	azonal -> name = (char* ) SCMalloc ( sc_strlen (name) + 1 ) ; 
	sc_strcpy ( azonal -> name , name ) ;
		
	azonal->datatype = type ;
	azonal->azonaltype = azonaltype ;
	azonal->line = line ;

	//	jelo 20121027
	//	azonal->DRC.deftimes = 0 ;
	//	azonal->DRC.chain = 0 ;
	//	end

	azonal->tack.head = 0 ;
	azonal->tack.next = 0 ;
	azonal->tack.totall = 0 ;
	
	azonal->number = ++ symbole->functotall ;
	azonal->next = 0 ;

	if ( 0 == symbole->function.next ) {
		symbole->function.next = azonal ;
		symbole->function.head = azonal ;
	} else {
		symbole->function.next->next = azonal ;
		symbole->function.next = azonal ;
	}

	symbole->logicalblocks ++ ;
	
	return azonal ;

}
Example #5
0
AZONAL* SymboleAndNumeric ( char* name , int type ) {

	//	author : Jelo Wang
	//	since : 20110125
	//	(C)TOK

	AZONAL* azonal = (AZONAL* ) SCMalloc ( sizeof(AZONAL) ) ;

	azonal->name = (char* ) SCMalloc ( sc_strlen (name)+1 ) ;

	ASSERT(azonal->name) ;

	sc_strcpy ( azonal->name , name ) ;

	azonal->azonaltype = type ;

	return azonal ;
	
}
Example #6
0
static char* lairgentor_head_label ( int label ) {

	//	author : Jelo Wang
	//	since : 20100503

	static char tempv [64] = {"L"} ;
	static char result [64] = {0} ;
		
	char* A = sc_strcat ( tempv , SCClItoa (label) ) ;
	char* B = sc_strcat ( A , ":" ) ;
	
	SCFree ( A ) ;

	sc_strcpy ( result , B ) ;

	SCFree ( B ) ;

	return result ;
	
}
Example #7
0
static int lairgentor_gen_expr ( EXPR* expression , int drop ) {

	//	author : Jelo Wang
	//	since : 20100425
	//	(C)TOK

	int recursived = 0 ;
	
	if ( !expression ) {
		return 0 ;
	}
	
	if ( expression->left ) {
		recursived = 1 ;
		lairgentor_gen_expr ( expression->left , drop ) ;
	}

	if ( expression->right ) {
		recursived = 1 ;		
		lairgentor_gen_expr ( expression->right , drop ) ;
	}

	if ( EXP_OPERAND == expression->type ) {

		char* name = 0 ; 
		AZONAL* azonal = expression->handle ;

		//	if this azonal is not a parameter
		//	else it would be in LAIR-CALL-FRAME
		if ( 0 == azonal->isparam ) {
		
			name = (char* ) SCMalloc ( sc_strlen (azonal->name) + 1 ) ;
			ASSERT(name) ;	
			sc_strcpy ( name , azonal->name ) ;

	 		if ( ISA_INTEGER != azonal->azonaltype ) {

				LGNOSIA* lgnosia = 0 ;

				//	在最近Alias 的flow中寻找当前flow
				//	如果找到了则不获取多重别名,直接使用最近的alias
				lgnosia = LgnosiaFindContextEx ( SsaGetAliasFlow (azonal) , GET_LAIRGENTOR_LGA() ) ;
		
				if ( 0 != lgnosia && LGNOSIA_CP_IDENT == lgnosia->type ) { 
					
					name = sc_strcat (name,SCClItoa(SsaGetAlias (azonal,lairgentor.identor.deep) ) ) ;
					expression->delt = (char* ) SCMalloc ( sc_strlen (name) + 1 ) ;
					sc_strcpy ( expression->delt  , name ) ;
					
				} else {

					char* multialias = 0 ;
	 				multialias = SsaMakeMultiAliasString(azonal,azonal->name,lairgentor.identor.deep , GET_LAIRGENTOR_LGA() ) ;

					if ( 0 != multialias ) {
						//	using multialias first
						name = multialias ;
						expression->delt = (char* ) SCMalloc ( sc_strlen (name) + sc_strlen ( "$%SSA()" ) ) ;
						sc_strcpy ( expression->delt  , "$%SSA(" ) ;
						sc_strcat_ex ( expression->delt  , name , expression->delt   ) ;
						sc_strcat_ex ( expression->delt  , ")" , expression->delt ) ;
					} else {
						name = sc_strcat (name,SCClItoa(SsaGetAlias (azonal,lairgentor.identor.deep) ) ) ;
						expression->delt = (char* ) SCMalloc ( sc_strlen (name) + 1 ) ;
						sc_strcpy ( expression->delt  , name ) ;
					}
					
				}
						
				SCFree ( name ) ;
				
			} else {		
				expression->delt = (char* ) SCMalloc ( sc_strlen (azonal->name) + 1 ) ;
				sc_strcpy ( expression->delt  , azonal->name ) ;
			}

			if ( ISA_INTEGER == azonal->azonaltype )
				expression->delttype = EXP_DELT_ANLNUMERIC ;
			else 
				expression->delttype = EXP_DELT_ANLDATA ;

		} else {
//			char* frame = LAIRMemoryFrameGet ( azonal->name ) ;
//			//	get LAIR-CALL-FRAME
//			expression->delt = (char* ) SCMalloc ( sc_strlen (frame) + 1 ) ;
//			sc_strcpy ( expression->delt  , frame ) ;		
//			expression->delttype = EXP_DELT_ANLDATA ;			
		}
		
		
	} else if ( EXP_OPERATOR == expression->type ) {

		char* tvalue = 0 ;
		
		LairAddCode ( lairgentor_get_identor () , -1 , -1 ) ;

		tvalue = lairgentor_get_register (lairgentor.delt+1) ;
		expression->delt = (char* ) SCMalloc ( sc_strlen(tvalue) + 1 ) ;
		sc_strcpy ( expression->delt  , tvalue ) ;

		expression->delttype = EXP_DELT_DEFAULT ;
		
		LairAddCode ( expression->delt , LAIR_LVA_DELT , lairgentor.identor.deep ) ;
		LairAddCode ( "=" , -1 , -1 ) ;
		LairAddCode ( expression->left->delt , LAIR_RVA_DELT , lairgentor.identor.deep ) ;
		LairAddCode ( lexerc_get_operator (expression->handle) , -1 , -1 ) ;
		LairAddCode ( expression->right->delt , LAIR_RVA_DELT , lairgentor.identor.deep ) ;
		LairAddCode ( "\r\n" , LAIR_CR , -1 ) ;

		lairgentor.delt = lairgentor.delt + 1 ;
		
		if ( (EXP_DELT_DEFAULT == expression->left->delttype) && (EXP_DELT_DEFAULT == expression->right->delttype) ) {
			lairgentor.delt = 0 ;
		}

		if ( drop ) {
			SCFreeEx ( &expression->left->delt ) ;
			SCFreeEx ( &expression->right->delt ) ;
			SCFreeEx ( &expression->left ) ;
			SCFreeEx ( &expression->right ) ;
		}
		
	}

	return 1 ;
	
}
Example #8
0
static void lairgentor_gen_variable ( LGNOSIA* lgnosia , AZONAL* azonal ) {

	//	author : Jelo Wang
	//	since : 20100425
	//	(C)TOK
	
	EXPR* expression = 0 ;

	if ( 0 == lgnosia->parameter.head ) {
		
		LairAddCode ( lairgentor_get_identor () , -1 , -1 ) ;
		LairAddCode ( "%$STK.Def " , -1 , -1 ) ;	
		LairAddCode ( azonal->name , LAIR_DEF , lairgentor.identor.deep ) ;		
		LairAddCode ( "\r\n" , LAIR_CR , -1 ) ;	

	} else if ( lgnosia->parameter.head ) {

		char* name = 0 ;
			
		expression = (EXPR*)lgnosia->parameter.head->element ;
		lairgentor_gen_expr ( (EXPR*)expression , 1 ) ;

		//	for local azonal
		if ( 0 != azonal->lgabelong ) {
			
			name = (char* ) SCMalloc ( sc_strlen (azonal->name) + sc_strlen ("%$STK.Set ")+ 1 ) ;
			ASSERT(name) ;
			sc_strcpy ( name , "%$STK.Set " ) ;

		} else {
		//	for global azonal
			name = (char* ) SCMalloc ( sc_strlen (azonal->name) + sc_strlen ("%$HEAP.")+ 1 ) ;
			ASSERT(name) ;		
			sc_strcpy ( name , "%$HEAP." ) ;
		}
		
		sc_strcat_ex ( name , azonal->name , name ) ;
		name = sc_strcat (name , SCClItoa(SsaMakeAlias ( GET_LAIRGENTOR_LGA(),azonal,lairgentor.identor.deep) ) ) ;
		SsaCleanMultiAlias ( azonal , GET_LAIRGENTOR_LGA() , azonal,lairgentor.identor.deep ) ;

		LairAddCode ( lairgentor_get_identor () , -1 , -1 ) ;

		LairAddCode ( name , LAIR_LVA_DELT , lairgentor.identor.deep ) ;
		LairAddCode ( "=" , -1 , -1 ) ;

		if ( expression->delttype == EXP_DELT_ANLNUMERIC ) 
			LairAddCode ( ((EXPR*)expression)->delt , -1 , -1 ) ;
		else 
			LairAddCode ( ((EXPR*)expression)->delt , LAIR_RVA_DELT , lairgentor.identor.deep ) ;
		
		LairAddCode ( "\r\n" , LAIR_CR , -1 ) ;

		SCFreeEx ( &((EXPR*)expression)->delt ) ;
		SCFreeEx ( (void**)&expression ) ;
		SCFree ( (void*)name ) ;
		
	}	

	SCFree ( lgnosia ) ;

}
Example #9
0
static int asmor_arm_read_stk () {

	//	author : Jelo Wang
	//	since : 20121031
	//	(C)TOK

	char R [32] = { 0 } ;
	char Rd [32] = { 0 } ;
	char Rn [32] = { 0 } ;
	
	switch ( lexlair->v ) {
		case LAIR_STKCRE :
			LexerLairGenv () ;
			SCClStringAddStr ( &ArmAsm , "SUB SP,SP," ) ;
			SCClStringAddStr ( &ArmAsm , lexlair->token ) ;
			SCClStringAddStr ( &ArmAsm , "\r\n") ;
			MemoryFrameCreate ( SCClAtoi(lexlair->token) , MF_STACK ) ;
		break ;
		case LAIR_STKREL :
			LexerLairGenv () ;
			SCClStringAddStr ( &ArmAsm , "ADD SP,SP," ) ;
			SCClStringAddStr ( &ArmAsm , lexlair->token ) ;
			SCClStringAddStr ( &ArmAsm , "\r\n" ) ;
		break ;		
		case LAIR_STKDEF :
			LexerLairGenv () ;
			MemoryFrameAdd ( lexlair->token , MF_STACK ) ;
		break ;		
		
		case LAIR_STKSET :
		{
			int offset = 0 ;

			SCClStringAddStr ( &ArmAsm , "MOV [SP+" ) ;		

			LexerLairGenv () ;
			offset = MemoryFrameGetAddress ( asmor_asm_split_ssaalias (lexlair->token) ) ;

			SCClStringAddStr ( &ArmAsm , SCClItoa (offset) ) ;	
			SCClStringAddStr ( &ArmAsm , "]," ) ;
			
			//skip LAIR_EQU
			LexerLairGenv () ;
			//Get LAIR_X
			LexerLairGenv () ;

			sc_strcpy ( R , SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ) ;
			sc_strcat_ex ( "R" , R , Rn ) ;
	
			SCClStringAddStr ( &ArmAsm , Rn ) ;
			SCClStringAddStr ( &ArmAsm , "\r\n" ) ;

		}
		break ;
		
		break ;
		case LAIR_STKGET :
		break ;
		case LAIR_STKPUSH :
		break ;
		case LAIR_STKPOP :
		break ;		

		default :
			return 0 ;
	}

	return 1 ;
	
}		
Example #10
0
static int asmor_arm_read_x () {

	
	//	author : Jelo Wang
	//	since : 20121031
	//	(C)TOK

	char R [32] = { 0 } ;
	char Rd [32] = { 0 } ;
	char Rn [32] = { 0 } ;
	char Rm [32] = { 0 } ;

	int state = 0 ;
	
	if ( LAIR_X != lexlair->v ) return 0 ;

	sc_strcpy ( R , SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ) ;
	sc_strcat_ex ( "R" , R , Rd ) ;

	while ( !lexlair->stop ) {

		LexerLairGenv () ;
				
		switch ( state ) {
			case 0 :		
 				if ( LAIR_EQU == lexlair->v ) {
					state = 1 ;
				}
			break ;
			case 1 :
				if ( LAIR_VAR == lexlair->v ) {
					if ( LAIR_CHROW != LexerLairHeadGenv(1) ) {
						char* R = SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn )  ) ;
						sc_strcat_ex ( "R" , R , Rn ) ;
						state = 2 ;
					}
				} else if ( LAIR_INTNUM == lexlair->v ) {		
 					THUMB_MOV_RdImmed_8 ( Rd , lexlair->token ) ;		
				}
 			break ;
			case 2 :

				if ( LAIR_ADD == lexlair->v ) {
					char* R = 0 ;
					LexerLairGenv () ;
					R = SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ;
					sc_strcat_ex ( "R" , R , Rm ) ;
					THUMB_ADD_RdRnRm(Rd,Rn,Rm) ;
					return 1 ;			
				} else if ( LAIR_SUB == lexlair->v ) {
					char* R = 0 ;
					LexerLairGenv () ;
					R = SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ;
					sc_strcat_ex ( "R" , R , Rm ) ;
					THUMB_SUB_RdRnRm(Rd,Rn,Rm) ;
					return 1 ;			
				} else if ( LAIR_MUL == lexlair->v ) {
					char* R = 0 ;
					LexerLairGenv () ;
					R = SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ;
					sc_strcat_ex ( "R" , R , Rm ) ;
					THUMB_MUL_RdRm(Rn,Rm) ;
					//	MOV
					THUMB_MOV_RdRm(Rd,Rn) ;					
					return 1 ;			
				} else if ( LAIR_AND == lexlair->v ) {
					char* R = 0 ;
					LexerLairGenv () ;
					R = SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ;
					sc_strcat_ex ( "R" , R , Rm ) ;
					THUMB_AND_RdRm(Rn,Rm) ;
					//	MOV
					THUMB_MOV_RdRm(Rd,Rn) ;					
					return 1 ;			
				} else if ( LAIR_OR == lexlair->v ) {
					char* R = 0 ;
					LexerLairGenv () ;
					R = SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ;
					sc_strcat_ex ( "R" , R , Rm ) ;
					THUMB_ORR_RdRm(Rn,Rm) ;
					//	MOV
					THUMB_MOV_RdRm(Rd,Rn) ;					
					return 1 ;			
				} else if ( LAIR_SHL == lexlair->v ) {
					char* R = 0 ;
					LexerLairGenv () ;
					R = SCClItoa ( RegocGetRegister ( 0 , lexlair->lsn ) ) ;
					sc_strcat_ex ( "R" , R , Rm ) ;
					THUMB_LSL_RdRs(Rn,Rm) ;
					//	MOV
					THUMB_MOV_RdRm(Rd,Rn) ;					
					return 1 ;			
				}
				
				
			break ;  
		}

	}	

	return 1 ;

}
Example #11
0
AZONAL* SymboleAzonalAddVariable ( 
	
	char* name ,
	int data_type , 
	int azonal_type , 
	int scope ,
	int size , 
	int is_param ,
	int line ,
	int belong ,
	int lgabelong 
	
) {

	//	author : Jelo Wang
	//	notes : add ISA_VARIABLE
	//	since : 20100418
	//	(C)TOK

	//	(1) param : SYMBOLE* 
	//	(2) param : name
	//	(3) param : data type
	//	(4) param : azonal type
	//	(5) param : scope of variable
	//	(6) param : is it parameter of function	
	//	(7) param : line
	//	(8) param : function belong
	
	AZONAL* azonal = 0 ;
	
	if ( !symbole ) return 0 ;
	
	azonal = (AZONAL* ) SCMalloc ( sizeof(AZONAL) ) ;

	azonal->azonaltype = azonal_type ;
	azonal->datatype = data_type ;
	azonal->isparam = is_param ;	
	azonal->scope = scope ;
	azonal->size = size ;
	azonal->line = line ;
	azonal->belong = belong ;
	azonal->used = 0 ;
	azonal->head = 0 ;
	azonal->next = 0 ;
	azonal->lgabelong = lgabelong ;
	
	//	jelo 20121027
	//	azonal->DRC.deftimes = 0 ;
	//	azonal->DRC.chain = 0 ;
	//	end

	azonal->name = (char* ) SCMalloc ( sc_strlen ( name ) + 1 ) ;
	sc_strcpy ( azonal->name , name ) ;
	
	//	for parameters of function
	if ( azonal->isparam ) {
		if ( ISA_FUNCTION == ((AZONAL*)belong)->azonaltype ) {
			//	add procedure's tack
			SCClListInsert ( &((AZONAL*)belong)->tack , azonal ) ;
		}
	}

	if ( belong ) {
		//	caculate procedure size
		((AZONAL*)belong)->size += azonal->size ;
	}

	if ( 0 == symbole->variable.next ) {
		symbole->variable.next = azonal ;
		symbole->variable.head = azonal ;
	} else {
		symbole->variable.next->next = azonal ;
		symbole->variable.next = azonal ; 
	}

	symbole->vartotall ++ ;
	
	return azonal ;
	
}