Example #1
0
CodeBlock* VariableEntry::codeGen(){
	CodeBlock* var_block = new CodeBlock();
	if(initVal() != NULL){
		var_block->append(initVal()->codeGen());

		ICode::ICodeType store_type = ICode::ICodeType::STI;
		ICode get_addr;

		if(varKind() == VariableEntry::VarKind::GLOBAL_VAR){
			ICode::ICodeType mov_type = ICode::ICodeType::MOVI;
			get_addr = ICode(mov_type,new Value(offSet(),Type::TypeTag::INT),&mem_register_);
		} else {
			ICode::ICodeType add_type = ICode::ICodeType::ADD;
			get_addr = ICode(add_type,&MemoryMgr::basePointerRegister(),new Value(offSet(),Type::TypeTag::INT),&mem_register_);
		}

		if(type()->tag() == Type::TypeTag::BOOL){
			CodeBlock* true_block = new CodeBlock();

			ICode store_true_val(store_type,new Value(1,Type::TypeTag::UINT),&mem_register_);
			ICode jmp_end(ICode::ICodeType::JMP,endLabel());

			true_block->setStartLabel(trueLabel());
			true_block->append(get_addr);
			true_block->append(store_true_val);
			true_block->append(jmp_end);

			CodeBlock* false_block = new CodeBlock();

			ICode store_false_val(store_type,new Value(0,Type::TypeTag::UINT),&mem_register_);

			false_block->setStartLabel(falseLabel());
			false_block->append(get_addr);
			false_block->append(store_false_val);
			false_block->setEndLabel(endLabel());

			var_block->append(true_block);
			var_block->append(false_block);
		} else {
			if(initVal()->reg().isFloat()){
				store_type = ICode::ICodeType::STF;
			}
			ICode store_val(store_type,&initVal()->reg(),&mem_register_);
			

			var_block->append(get_addr);
			var_block->append(store_val);
			
		}
	}
	ICode incr_stack(ICode::ICodeType::ADD,&MemoryMgr::stackPointerRegister(),new Value(1,Type::TypeTag::INT),&MemoryMgr::stackPointerRegister());
	var_block->append(incr_stack);

	return var_block;
}
Example #2
0
 ExecStatus
 Tan<A,B>::propagate(Space& home, const ModEventDelta&) {
   GECODE_ME_CHECK(x1.eq(home,tan(x0.domain())));
   FloatVal iv = fmod(x0.domain(),FloatVal::pi());
   FloatNum offSet(Round.sub_down(x0.min(),iv.min()));
   GECODE_ES_CHECK(aTanProject(x1,iv));
   GECODE_ME_CHECK(x0.eq(home,iv + offSet));
   return (x0.assigned() && x1.assigned()) ? home.ES_SUBSUMED(*this) : ES_FIX;
 }
Example #3
0
void VariableEntry::memAlloc(MemoryMgr &mm){
	offSet(mm.getNextAddress());
	if(initVal()!=NULL){
		if(type()->tag() == Type::TypeTag::BOOL){
	      trueLabel(new Label(Label::LabelType::BOOL_TRUE));
	      falseLabel(new Label(Label::LabelType::BOOL_FALSE));
	      endLabel(new Label(Label::LabelType::BOOL_END));
	      initVal()->trueLabel(trueLabel());
	      initVal()->falseLabel(falseLabel());
	    }
		reg(mm.getNextRegister(true));
		mm.addRegister(reg());
		initVal()->memAlloc(mm);
		if(type()->tag() != Type::TypeTag::BOOL){
			mm.freeRegister(initVal()->reg());
		}
		mm.freeRegister(reg());
	}
}
Example #4
0
void VariableEntry::print(ostream& out, int indent) const{
	if(type()==NULL || (type()->tag()==Type::TypeTag::CLASS && type()->typeDesc()==NULL)){
		return;
	}
	for(int i=0;i<indent;++i){
		out << "\t";
	}
	out << type()->fullName()<<" "<< name();
	out << "(offset = " << offSet();
	if(reg().isValid()){
		out << ", mem_register = " << reg();
	}
	out << ")";
	if(initVal()!=NULL){
		out << " = ";
		initVal()->print(out,0);
	}
	out << ";" << endl;
}
Example #5
0
void VariableEntry::memAlloc(int reset_AR)
{
    if (varKind() == VariableEntry::GLOBAL_VAR) {
	offSet(memAllocUtil(type(), EntryKind::GLOBAL, 0));
	LOG("Allocation of GLOBAL name: " << name() << ", offSet: " << offSet());
    } else if (varKind() == VariableEntry::LOCAL_VAR) {
	offSet(memAllocUtil(type(), EntryKind::LOCAL, reset_AR));
	LOG("Allocation of LOCAL, name: " << name() << ", offSet:" << offSet());
    } else if (varKind() == VariableEntry::PARAM_VAR) {
	offSet(memAllocUtil(type(), EntryKind::FUNCTION_PARAMETER, reset_AR));
	LOG("Allocation of PARAM, name: " << name() << ", offSet: " << offSet());
    } else {
	LOG("Allocation failed for, name: " << name() << ", VarKind not set! Cannot know where to allocate this.");
    }

    return;
}
void Foam::layerAR::addZonesAndModifiers()
{
    // Add the zones and mesh modifiers to operate piston motion

    if
    (
        pointZones().size() > 0
     || faceZones().size() > 0
     || cellZones().size() > 0
    )
    {
        Info<< "void layerAR::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        if (topoChanger_.size() == 0)
        {
            FatalErrorIn
            (
                "void layerAR::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        setVirtualPistonPosition();
        checkAndCalculate();

        return;
    }

    checkAndCalculate();

    Info<< "Time = " << engTime().theta() << endl
        << "Adding zones to the engine mesh" << endl;

    //fz = 1: faces where layer are added/removed
    //pz = 2: points below the virtual piston faces and head points

    List<pointZone*> pz(2);
    List<faceZone*> fz(1);
    List<cellZone*> cz(0);

    label nPointZones = 0;
    label nFaceZones = 0;

    // Add the piston zone
    if (piston().patchID().active() && offSet() > SMALL)
    {

        // Piston position

        label pistonPatchID = piston().patchID().index();

        scalar zPist = max(boundary()[pistonPatchID].patch().localPoints()).z();

        scalar zPistV = zPist + offSet();

        labelList zone1(faceCentres().size());
        boolList flipZone1(faceCentres().size(), false);
        label nZoneFaces1 = 0;

        bool foundAtLeastOne = false;
        scalar zHigher = GREAT;
        scalar dh = GREAT;
        scalar dl = GREAT;

        forAll (faceCentres(), faceI)
        {
            scalar zc = faceCentres()[faceI].z();
            vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
            scalar dd = n & vector(0,0,1);

            if (dd > 0.1)
            {
                if (zPistV - zc > 0 && zPistV - zc < dl)
                {
                    dl = zPistV - zc;
                }

                if (zc - zPistV > 0 && zc - zPistV < dh)
                {
                    zHigher = zc;
                    dh = zc - zHigher;
                }

                if
                (
                    zc > zPistV - delta()
                    && zc < zPistV + delta()
                )
                {
                    foundAtLeastOne = true;
                    if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
                    {
                        flipZone1[nZoneFaces1] = true;
                    }

                    zone1[nZoneFaces1] = faceI;
                    nZoneFaces1++;
                }
            }
        }
void Foam::simpleTwoStroke::addZonesAndModifiers()
{
    // Add the zones and mesh modifiers to operate piston motion

    if
    (
        pointZones().size() > 0
        || faceZones().size() > 0
        || cellZones().size() > 0
    )
    {
        Info<< "Time = " << engTime().theta() << endl;
        Info<< "void simpleTwoStroke::addZonesAndModifiers() : "
            << "Zones and modifiers already present.  Skipping."
            << endl;

        if (topoChanger_.size() == 0)
        {
            FatalErrorIn
            (
                "void simpleTwoStroke::addZonesAndModifiers()"
            )   << "Mesh modifiers not read properly"
                << abort(FatalError);
        }

        setVirtualPistonPosition();
        checkAndCalculate();

        return;


    }

    Info << "checkAndCalculate()" << endl;
    checkAndCalculate();

    Info<< "Time = " << engTime().theta() << endl
        << "Adding zones to the engine mesh" << endl;


    //fz = 4: virtual piston, outSidePort, insidePort, cutFaceZone
    //pz = 2: piston points, cutPointZone
    //cz = 1: moving mask

    List<pointZone*> pz(3);
    List<faceZone*> fz(4);
    List<cellZone*> cz(1);

    label nPointZones = 0;
    label nFaceZones = 0;
    label nCellZones = 0;

    // Add the piston zone
    if (piston().patchID().active())
    {

        // Piston position

        Info << "Adding face zone for piston layer addition/removal" << endl;

        label pistonPatchID = piston().patchID().index();

        scalar zPist =
            max(boundary()[pistonPatchID].patch().localPoints()).z();

        scalar zPistV = zPist + offSet();

        labelList zone1(faceCentres().size());
        boolList flipZone1(faceCentres().size(), false);
        label nZoneFaces1 = 0;

        bool foundAtLeastOne = false;
        scalar zHigher = GREAT;
        scalar dh = GREAT;
        scalar dl = GREAT;

        forAll (faceCentres(), faceI)
        {
            // The points have to be in the cylinder and not in the ports....

            scalar zc = faceCentres()[faceI].z();

            scalar xc = faceCentres()[faceI].x();
            scalar yc = faceCentres()[faceI].y();

            vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
            scalar dd = n & vector(0,0,1);

            if(sqrt(sqr(xc)+sqr(yc)) <  0.5 * engTime().bore().value())
            {
                if (dd > 0.1)
                {
                    if (zPistV - zc > 0 && zPistV - zc < dl)
                    {
                        dl = zPistV - zc;
                    }

                    if (zc - zPistV > 0 && zc - zPistV < dh)
                    {
                        zHigher = zc;
                        dh = zc - zHigher;
                    }

                    if
                    (
                        zc > zPistV - delta()
                        && zc < zPistV + delta()
                    )
                    {
                        foundAtLeastOne = true;
                        if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
                        {
                            flipZone1[nZoneFaces1] = true;
                        }

                        zone1[nZoneFaces1] = faceI;
                        nZoneFaces1++;
                    }
                }
            }
        }
Example #8
0
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;
}