static void reg_not(const addr_type address, const reg_type value) { *reinterpret_cast<volatile reg_type*>(address) &= reg_type(~value); }
 static void reg_msk(const addr_type address, const reg_type value,
                     const reg_type mask_value)                     { *reinterpret_cast<volatile reg_type*>(address) = reg_type(reg_type(reg_get(address) & reg_type(~mask_value)) | reg_type(value & mask_value)); }
示例#3
0
文件: STEClasses.C 项目: arunov/dory
void VariableEntry::codeGen(IntermediateCodeGen * list)
{
    LOG("");

    int isInt, regPtr = -1, hackyReg = -1;
    Instruction *instr = NULL;
    Instruction *getParam = NULL;
    Instruction *hackyinstr = NULL;
    Instruction *instrAddOffset = NULL;
    Value *immediate = NULL;
    Value *immediate1 = NULL;

    if (type()->isIntegral(type()->tag()) || type()->isBool(type()->tag())) {
	setReg(get_vreg_int(), VREG_INT);
	isInt = 1;
    } else {
	setReg(get_vreg_float(), VREG_FLOAT);
	isInt = 0;
    }

    if (varKind() == VariableEntry::VarKind::PARAM_VAR) {
        immediate1 = new Value(1, Type::TypeTag::INT);
        instr = new Instruction(Instruction::Mnemonic::ADD);
        instr->operand_src1(get_vreg_temp_stack(), NULL, VREG_INT);
        instr->operand_src2(-1, immediate1, Instruction::OpType::IMM);
        instr->operand_dest(get_vreg_temp_stack(), NULL, VREG_INT);

        list->addInstruction(instr);

	getParam = new Instruction(Instruction::typedMnemonic(isInt, Instruction::Mnemonic::LDI));
	getParam->operand_src1(get_vreg_temp_stack(), NULL, VREG_INT);
	getParam->operand_dest(getReg(), NULL, reg_type());

	list->addInstruction(getParam);
    } else if (varKind() == VariableEntry::VarKind::LOCAL_VAR) {
	if (initVal()) {
	    initVal()->codeGen(list);

	    if (!isInt && initVal()->reg_type() == VREG_INT) {
		hackyinstr = new Instruction(Instruction::Mnemonic::MOVIF);
		hackyinstr->operand_src1(initVal()->getReg(), NULL, initVal()->reg_type());
		hackyReg = get_vreg_float();
		hackyinstr->operand_dest(hackyReg, NULL, VREG_FLOAT);
		list->addInstruction(hackyinstr);

	    	getParam = new Instruction(Instruction::typedMnemonic(isInt, Instruction::Mnemonic::STI));
	    	getParam->operand_src1(hackyReg, NULL, VREG_FLOAT);
	    	getParam->operand_dest(get_vreg_sp(), NULL, VREG_INT);
	    	list->addInstruction(getParam);
	    } else {
	    	getParam = new Instruction(Instruction::typedMnemonic(isInt, Instruction::Mnemonic::STI));
	    	getParam->operand_src1(initVal()->getReg(), NULL, initVal()->reg_type());
	    	getParam->operand_dest(get_vreg_sp(), NULL, VREG_INT);
	    	list->addInstruction(getParam);
	    }
	}

        immediate1 = new Value(1, Type::TypeTag::INT);
        instr = new Instruction(Instruction::Mnemonic::SUB);
        instr->operand_src1(get_vreg_sp(), NULL, VREG_INT);
        instr->operand_src2(-1, immediate1, Instruction::OpType::IMM);
        instr->operand_dest(get_vreg_sp(), NULL, VREG_INT);

        list->addInstruction(instr);
    } else if (varKind() == VariableEntry::VarKind::GLOBAL_VAR) {
	instrAddOffset = new Instruction();
        instrAddOffset->opcode(Instruction::Mnemonic::ADD);
        instrAddOffset->operand_src1(get_vreg_global(), NULL, VREG_INT);
	immediate = new Value(offSet(), Type::TypeTag::INT);
	instrAddOffset->operand_src2(-1, immediate, Instruction::OpType::IMM);
	regPtr = get_vreg_int();
	instrAddOffset->operand_dest(regPtr, NULL, VREG_INT);
	list->addInstruction(instrAddOffset);

	if (initVal()) {
	    initVal()->codeGen(list);
	    instr = new Instruction(Instruction::typedMnemonic(isInt, Instruction::Mnemonic::STI));
	    instr->operand_dest(regPtr, NULL, VREG_INT);
	    instr->operand_src1(initVal()->getReg(), NULL, initVal()->reg_type());
	    list->addInstruction(instr);
	}
    }

    return;
}