Exemplo n.º 1
0
	NIns* Assembler::genPrologue(RegisterMask needSaving)
	{
		/**
		 * Prologue
		 */

		// NJ_RESV_OFFSET is space at the top of the stack for us
		// to use for parameter passing (8 bytes at the moment)
		uint32_t stackNeeded = 4 * _activation.highwatermark + NJ_STACK_OFFSET;
		uint32_t savingCount = 0;

		uint32_t savingMask = 0;
		#if defined(NJ_THUMB_JIT)
		savingCount = 5; // R4-R7, LR
		savingMask = 0xF0;
		(void)needSaving;
		#else
		savingCount = 9; //R4-R10,R11,LR
		savingMask = SavedRegs | rmask(FRAME_PTR);
		(void)needSaving;
		#endif

		// so for alignment purposes we've pushed  return addr, fp, and savingCount registers
		uint32_t stackPushed = 4 * (2+savingCount);
		uint32_t aligned = alignUp(stackNeeded + stackPushed, NJ_ALIGN_STACK);
		int32_t amt = aligned - stackPushed;

		// Make room on stack for what we are doing
		if (amt)
#ifdef NJ_THUMB_JIT
		{
			// largest value is 508 (7-bits << 2)
			if (amt>508)
			{
				int size = 508;
				while (size>0)
				{
					SUBi(SP, size);
					amt -= size;
					size = amt;
					if (size>508)
						size=508;
				}
			}
			else
				SUBi(SP, amt); 

		}
#else
		{ 
			SUBi(SP, amt); 
		}
#endif
		verbose_only( verbose_outputf("         %p:",_nIns); )
Exemplo n.º 2
0
	NIns* Assembler::genPrologue(RegisterMask needSaving)
	{
		/**
		 * Prologue
		 */
		uint32_t stackNeeded = STACK_GRANULARITY * _activation.highwatermark;
		uint32_t savingCount = 0;

		for(Register i=FirstReg; i <= LastReg; i = nextreg(i))
			if (needSaving&rmask(i)) 
				savingCount++;

		// After forcing alignment, we've pushed the pre-alignment SP
		// and savingCount registers.
		uint32_t stackPushed = STACK_GRANULARITY * (1+savingCount);
		uint32_t aligned = alignUp(stackNeeded + stackPushed, NJ_ALIGN_STACK);
		uint32_t amt = aligned - stackPushed;

		// Reserve stackNeeded bytes, padded
		// to preserve NJ_ALIGN_STACK-byte alignment.
		if (amt) 
		{
#if defined NANOJIT_IA32
			SUBi(SP, amt);
#elif defined NANOJIT_AMD64
			SUBQi(SP, amt);
#endif
		}

		verbose_only( verbose_outputf("        %p:",_nIns); )
Exemplo n.º 3
0
int unaryMinusCodegen(c_tree tree, int *registerNo, int topLevel,
		int getAddress, const char *breakLabel, const char *continueLabel)
{
	c_tree op = TREE_EXPR_OPERAND(tree,0);
	if (!topLevel)
	{
		int zeroReg = (*registerNo)++;
		SET(zeroReg, 0, "unary minus getting zero into register", NULL);
		if (TREE_CODE(op) == TREE_INTEGER_CST)
		{
			SUBi(*registerNo, zeroReg, INTEGER_CST(op)->val,
					"unary minus sub the integer const from zero", NULL);
		}
		else
		{
			int opRegister = c_codegen_recurse(op, registerNo, FALSE,
					getAddress, breakLabel, continueLabel);
			SUB(*registerNo, zeroReg, opRegister,
					"unary minus sub the register from zero", NULL);
		}
		return (*registerNo)++;
	}
	else
	{
		c_codegen_recurse(op, registerNo, topLevel, getAddress, breakLabel,
				continueLabel);

		return *registerNo;
	}
}
Exemplo n.º 4
0
int comparisonExprCodegen(c_tree tree, int *registerNo, int topLevel,
		condition cond, int getAddress, const char *breakLabel,
		const char *continueLabel)
{
	static int labelNo = 0;
	static char labelPrefix[] = "COMP";
	char labelArray[LABEL_ARRAY_LENGTH];

	c_tree op1 = TREE_EXPR_OPERAND(tree,0);
	c_tree op2 = TREE_EXPR_OPERAND(tree,1);

	if (!topLevel)
	{
		int resultReg = (*registerNo)++;
		// intially set the result to false
		SET(resultReg, TRUE,
				"comparison expression result register intial value true", NULL);

		int op1Register = c_codegen_recurse(op1, registerNo, topLevel,
				getAddress, breakLabel, continueLabel);

		int subResultReg = (*registerNo)++;
		if (TREE_CODE(op2) == TREE_INTEGER_CST)
		{
			// substract the two values to be compared
			SUBi(subResultReg, op1Register, INTEGER_CST(op2)->val,
					"comparison expression subtract c=a-b", NULL);
		}
		else
		{
			// substract the two values to be compared
			int op2Register = c_codegen_recurse(op2, registerNo, topLevel,
					getAddress, breakLabel, continueLabel);
			SUB(subResultReg, op1Register, op2Register,
					"comparison expression subtract c=a-b", NULL);
		}
		sprintf(labelArray, "%s%d", labelPrefix, labelNo++);

		// create a branch depending upon the condition
		checkConditionAndBranch(cond, subResultReg, labelArray,
				"comparison expression branch on condition", NULL);

		// this set will be skipped depending on condition
		// this set sets the result to false
		SET(resultReg, FALSE, "comparison expression false value", NULL);

		//NOP just to create the label
		NOP("comparison expression just to create a label", labelArray);
		return resultReg;
	}
	else
	{
		// evaluate the LHS and RHS....but dont do the operation
		c_codegen_recurse(op1, registerNo, topLevel, getAddress, breakLabel,
						continueLabel);

		c_codegen_recurse(op2, registerNo, topLevel, getAddress, breakLabel,
				continueLabel);

		return *registerNo;
	}
}
Exemplo n.º 5
0
int assignExprCodegen(c_tree tree, int *registerNo, int topLevel,
		int getAddress, const char *breakLabel, const char *continueLabel)
{
	c_tree rhs = TREE_EXPR_OPERAND(tree,1);
	c_tree lhs = TREE_EXPR_OPERAND(tree,0);
	if (TREE_CODE(lhs) == TREE_DECL && (strcmp(DECL_NAME_STRING(lhs), COUT)
			== 0))
	{
		int rhsValue = c_codegen_recurse(rhs, registerNo, FALSE, FALSE,
				breakLabel, continueLabel);
		ADDi(R0, rhsValue, 0, "copying into R0", NULL);
		COUTASM("Displaying to COUT", "");
		return R0;
	}
	else
	{

		c_tree type = get_type_for_uid(TYPE(TREE_TYPE(lhs))->uid);
		int typeSize = getSize(TREE_TYPE(lhs));

		if(TYPE(type)->code!=STRUCT_TYPE || typeSize==1 )
		{
			int rhsValue = c_codegen_recurse(rhs, registerNo, FALSE, FALSE,
					breakLabel, continueLabel);
			int lhsAddress = c_codegen_recurse(lhs, registerNo, FALSE, TRUE,
					breakLabel, continueLabel);
			STRi(rhsValue, lhsAddress, 0, "assignment", NULL);
		}
		else
		{

			int rhsAddress = c_codegen_recurse(rhs, registerNo, FALSE, TRUE,
					breakLabel, continueLabel);
			int lhsAddress = c_codegen_recurse(lhs, registerNo, FALSE, TRUE,
					breakLabel, continueLabel);

			static int copyCondLabelNo = 0;
			static char copyCondLabelPrefix[] = "SCC";
			char copyCondLabelArray[LABEL_ARRAY_LENGTH];

			static int copyEndLabelNo = 0;
			static char copyEndLabelPrefix[] = "SCE";
			char copyEndLabelArray[LABEL_ARRAY_LENGTH];

			sprintf(copyCondLabelArray, "%s%d", copyCondLabelPrefix,
					copyCondLabelNo++);
			sprintf(copyEndLabelArray, "%s%d", copyEndLabelPrefix,
								copyEndLabelNo++);

			int counterRegister = (*registerNo)++;
			int subResultRegister = (*registerNo)++;
			int tempCopyRegister = (*registerNo)++;

			// loop for copying
			SET(counterRegister, 0, "struct copy counter initial value", NULL);
			SUBi(subResultRegister, counterRegister, typeSize,
					"struct copy condition to end copying", copyCondLabelArray);
			BRnzp(subResultRegister, copyEndLabelArray,
					"struct copy branch to end", NULL, "z");
			LDR(tempCopyRegister, rhsAddress, counterRegister, "struct assignment", NULL);
			STR(tempCopyRegister, lhsAddress, counterRegister, "struct assignment", NULL);
			ADDi(counterRegister, counterRegister, 1, "struct copy increment counter", NULL);
			BRA(copyCondLabelArray, "struct copy branch to condition", NULL);
			NOP("end of struct copying", copyEndLabelArray);

		}

		return c_codegen_recurse(lhs, registerNo,
				topLevel, getAddress, breakLabel, continueLabel);
	}
}