Example #1
0
static kbool_t FuelVM_VisitIfNode(KonohaContext *kctx, KBuilder *builder, kNode *stmt, void *thunk)
{
	kNode *expr    = kNode_getFirstNode(kctx, stmt);
	Block *ThenBB  = CreateBlock(BLD(builder));
	Block *ElseBB  = CreateBlock(BLD(builder));
	Block *MergeBB = CreateBlock(BLD(builder));
	/* if */
	SUGAR VisitNode(kctx, builder, expr, thunk);
	CreateBranch(BLD(builder), FuelVM_getExpression(builder), ThenBB, ElseBB);
	{ /* then */
		IRBuilder_setBlock(BLD(builder), ThenBB);
		SUGAR VisitNode(kctx, builder, kNode_getFirstBlock(kctx, stmt), thunk);
		if(!Block_HasTerminatorInst(BLD(builder)->Current)) {
			IRBuilder_JumpTo(BLD(builder), MergeBB);
		}
	}
	{ /* else */
		IRBuilder_setBlock(BLD(builder), ElseBB);
		SUGAR VisitNode(kctx, builder, kNode_getElseBlock(kctx, stmt), thunk);
		if(!Block_HasTerminatorInst(BLD(builder)->Current)) {
			IRBuilder_JumpTo(BLD(builder), MergeBB);
		}
	}
	/* endif */
	IRBuilder_setBlock(BLD(builder), MergeBB);
	return true;
}
Example #2
0
static kbool_t MiniVM_VisitDoWhileNode(KonohaContext *kctx, KBuilder *builder, kUntypedNode *node, void *thunk)
{
	bblock_t HeadBB  = new_BasicBlockLABEL(kctx);
	bblock_t BodyBB  = new_BasicBlockLABEL(kctx);
	bblock_t MergeBB = new_BasicBlockLABEL(kctx);

	kUntypedNode_SetLabelBlock(kctx, node, KSymbol_("continue"), HeadBB);
	kUntypedNode_SetLabelBlock(kctx, node, KSymbol_("break"),    MergeBB);

	MiniVMBuilder_JumpTo(kctx, builder, BodyBB);
	{ /* Head */
		MiniVMBuilder_setBlock(kctx, builder, HeadBB);
		KLIB VisitNode(kctx, builder, kUntypedNode_getFirstNode(kctx, node), thunk);
		CreateBranch(kctx, builder, MiniVM_getExpression(builder), MergeBB, BodyBB, true);
	}

	{ /* Body */
		MiniVMBuilder_setBlock(kctx, builder, BodyBB);
		KLIB VisitNode(kctx, builder, kUntypedNode_getFirstBlock(kctx, node), thunk);
		MiniVMBuilder_JumpTo(kctx, builder, HeadBB);
	}

	MiniVMBuilder_setBlock(kctx, builder, MergeBB);
	return true;
}
Example #3
0
/*
	 "Break a branch into two parts staring from a node"
	 */
branch_t* circuit_t::SeparateBranch (branch_t* a, node_t* n)
{
	/*
		Create new branch object b, with nodes from n to a->BottomNode()
	*/
		branch_t* b = CreateBranch (branches.size(), n, a->BottomNode());
	
	/*		
		Starting first member / item in a that has n as its top node:
		
	*/
	bool first_item_reached = false;
	
	for (list<item_t>::iterator i = a->items.begin(); i != a->items.end(); i++)
	{
		if (i->e->TopNode() == n)
		  first_item_reached = true;
		  
		if (first_item_reached)
		{		    
			/*
				Change all parent branches from a to b, remove and move to b->items.
			*/
			i->e->SetParentBranch(b);
			b->add_item(*i);
			a->items.erase (i);
				
			/*		
				TODO: Move all a current relations that concern members now in new branch to b.		
			*/
		} /* if */
	} /* for */
	
	return b;
} /* circuit_t::SeparateBranch */
Example #4
0
static void CreateCond(KonohaContext *kctx, KBuilder *builder, kNode *expr, enum ConditionalOp Op, void *thunk)
{
	kNode *LHS = kNode_At(expr, 1);
	kNode *RHS = kNode_At(expr, 2);

	Block *HeadBB  = CreateBlock(BLD(builder));
	Block *ThenBB  = CreateBlock(BLD(builder));
	Block *MergeBB = CreateBlock(BLD(builder));

	/* [CondExpr]
	 * LogicalAnd case
	 *       | goto Head
	 * Head  | let bval = LHS
	 *       | if(bval) { goto Then } else { goto Merge }
	 * Then  | bval = RHS
	 *       | goto Merge
	 * Merge | ...
	 */

	INode *Node;
	IRBuilder_JumpTo(BLD(builder), HeadBB);
	{ /* Head */
		IRBuilder_setBlock(BLD(builder), HeadBB);
		Node = CreateLocal(BLD(builder), TYPE_boolean);
		SUGAR VisitNode(kctx, builder, LHS, thunk);
		INode *Left = FuelVM_getExpression(builder);
		CreateUpdate(BLD(builder), Node, Left);

		if(Op == LogicalAnd) {
			CreateBranch(BLD(builder), Left, ThenBB, MergeBB);
		} else {
			CreateBranch(BLD(builder), Left, MergeBB, ThenBB);
		}
	}
	{ /* Then */
		IRBuilder_setBlock(BLD(builder), ThenBB);
		SUGAR VisitNode(kctx, builder, RHS, thunk);
		INode *Right = FuelVM_getExpression(builder);
		CreateUpdate(BLD(builder), Node, Right);
		IRBuilder_JumpTo(BLD(builder), MergeBB);
	}

	IRBuilder_setBlock(BLD(builder), MergeBB);
	builder->Value = Node;
}
Example #5
0
static void CreateCond(KonohaContext *kctx, KBuilder *builder, kUntypedNode *expr, enum ConditionalOp Op, void *thunk)
{
	intptr_t cond;
	kUntypedNode *LHS = kUntypedNode_At(expr, 1);
	kUntypedNode *RHS = kUntypedNode_At(expr, 2);

	bblock_t HeadBB  = new_BasicBlockLABEL(kctx);
	bblock_t ThenBB  = new_BasicBlockLABEL(kctx);
	bblock_t MergeBB = new_BasicBlockLABEL(kctx);

	/* [CondExpr]
	 * LogicalAnd case
	 *       | goto Head
	 * Head  | let bval = LHS
	 *       | if(bval) { goto Then } else { goto Merge }
	 * Then  | bval = RHS
	 *       | goto Merge
	 * Merge | ...
	 */

	MiniVMBuilder_JumpTo(kctx, builder, HeadBB);
	cond = builder->stackbase;
	builder->stackbase += 1;
	{ /* Head */
		MiniVMBuilder_setBlock(kctx, builder, HeadBB);
		KLIB VisitNode(kctx, builder, LHS, thunk);
		CreateUpdate(kctx, builder, KType_Boolean, cond, MiniVM_getExpression(builder));
		if(Op == LogicalAnd)
			CreateBranch(kctx, builder, cond, ThenBB, MergeBB, false);
		else {
			CreateBranch(kctx, builder, cond, ThenBB, MergeBB, true);
		}
	}
	{ /* Then */
		MiniVMBuilder_setBlock(kctx, builder, ThenBB);
		KLIB VisitNode(kctx, builder, RHS, thunk);
		CreateUpdate(kctx, builder, KType_Boolean, cond, MiniVM_getExpression(builder));
		MiniVMBuilder_JumpTo(kctx, builder, MergeBB);
	}

	MiniVMBuilder_setBlock(kctx, builder, MergeBB);
	builder->stackbase -= 1;
	builder->Value = builder->stackbase;
}
Example #6
0
element_t* circuit_t::AddElement (branch_t* p_branch, ElementType etype, ident sch_id, bool initially_reversed, node_t* a, node_t* b)
{
	
	if (p_branch == NONE)
	{
		p_branch = CreateBranch (branches.size(), a,b);
	} /*if*/

	/* Add element to table */
	element_t* element= new element_t (p_branch, etype, sch_id /* IDENT */);

	element->SetTopNode    (a);
	element->SetBottomNode (b);	
	element->SetReversed (initially_reversed);
	elements.push_back (element );

	/* Create new item for this element */
	item_t item (element, initially_reversed ); 		
	//TODO: correct insertion order
	
	/* 
		handle correct item location
	*/
	
	if (p_branch->items.size() == 0) 
	{
		p_branch->add_item (item);  
	} /* if */
	else
	{
	
		for (list<item_t>::iterator i = p_branch->items.begin(); i != p_branch->items.end(); i++)
		{
			
			if (i->e->TopNode() == a && i->e->BottomNode() == b  && a != NONE && b != NONE ) 
			{
				i->e = element;
				break;
			} /* if */
			else if (i->e->TopNode() == b && i->e->BottomNode() == a  && a != NONE && b != NONE   ) 
			{
				i->e = element;
				i->direction = ! i->direction;
				break;
			} /* else if */
			else if (next(i) == p_branch->items.end())
			{
				p_branch-> add_item (item); 
				break;
			 
			} /* else if */	
		
		} /* for */	
	} /* else */	
    
} /* circuit_t::AddElement */
Example #7
0
////////// ////////// ////////// ////////// //////////
void 
SingleTreeMaker::FillBranch(const TString varName, const TString varType, const TString *val)
{
  fMethodName = "FillBranch";

  TString i = varName;

  // If the branch named varName does not exist, then create it and its buffer variable.
  if( !fBranchName[i].Contains(varName) ) CreateBranch(i,varType,1);

  // Fill the buffer variable for the branch named varName.
  sprintf(fVarChar[i],"%s",val->Data());

}//END of FillBranch()
Example #8
0
////////// ////////// ////////// ////////// //////////
void 
SingleTreeMaker::FillBranch(const TString varName, const TString varType, Double_t *val, const Int_t nEls)
{
  fMethodName = "FillBranch";

  TString i = varName;

  // If the branch named varName does not exist, then create it and its buffer variable.
  if( !fBranchName[i].Contains(varName) ) CreateBranch(i,varType,nEls);

  // Fill each element of the buffer variable for the branch named varName.
  for(Int_t j=0; j<nEls; j++) fVarDouble[i][j] = val[j];

}//END of FillBranch()
Example #9
0
static kbool_t MiniVM_VisitLoopNode(KonohaContext *kctx, KBuilder *builder, kUntypedNode *node, void *thunk, enum LoopType Loop)
{
	kUntypedNode *ItrBlock;
	bblock_t HeadBB  = new_BasicBlockLABEL(kctx);
	bblock_t BodyBB  = new_BasicBlockLABEL(kctx);
	bblock_t ItrBB   = new_BasicBlockLABEL(kctx);
	bblock_t MergeBB = new_BasicBlockLABEL(kctx);

	kUntypedNode_SetLabelBlock(kctx, node, KSymbol_("continue"), ItrBB);
	kUntypedNode_SetLabelBlock(kctx, node, KSymbol_("break"),    MergeBB);

	ItrBlock = KLIB kUntypedNode_GetNode(kctx, node, KSymbol_("Iterator"), NULL);
	if(ItrBlock != NULL) {
		assert(Loop == ForLoop);
		MiniVMBuilder_JumpTo(kctx, builder, HeadBB);
	}
	else if(Loop == WhileLoop) {
		MiniVMBuilder_JumpTo(kctx, builder, HeadBB);
	} else {
		MiniVMBuilder_JumpTo(kctx, builder, BodyBB);
	}

	{ /* Head */
		MiniVMBuilder_setBlock(kctx, builder, HeadBB);
		KLIB VisitNode(kctx, builder, kUntypedNode_getFirstNode(kctx, node), thunk);
		CreateBranch(kctx, builder, MiniVM_getExpression(builder), BodyBB, MergeBB, false);
	}

	{ /* Body */
		MiniVMBuilder_setBlock(kctx, builder, BodyBB);
		KLIB VisitNode(kctx, builder, kUntypedNode_getFirstBlock(kctx, node), thunk);
		MiniVMBuilder_JumpTo(kctx, builder, ItrBB);

		/* Itr */
		MiniVMBuilder_setBlock(kctx, builder, ItrBB);
		if(ItrBlock != NULL) {
			KLIB VisitNode(kctx, builder, ItrBlock, thunk);
		}
		MiniVMBuilder_JumpTo(kctx, builder, HeadBB);
	}

	MiniVMBuilder_setBlock(kctx, builder, MergeBB);
	return true;
}
Example #10
0
static kbool_t MiniVM_VisitIfNode(KonohaContext *kctx, KBuilder *builder, kUntypedNode *node, void *thunk)
{
	bblock_t ThenBB  = new_BasicBlockLABEL(kctx);
	bblock_t ElseBB  = new_BasicBlockLABEL(kctx);
	bblock_t MergeBB = new_BasicBlockLABEL(kctx);
	/* if */
	KLIB VisitNode(kctx, builder, kUntypedNode_getFirstNode(kctx, node), thunk);
	CreateBranch(kctx, builder, MiniVM_getExpression(builder), ThenBB, ElseBB, false);
	{ /* then */
		MiniVMBuilder_setBlock(kctx, builder, ThenBB);
		KLIB VisitNode(kctx, builder, kUntypedNode_getFirstBlock(kctx, node), thunk);
		if(!Block_HasTerminatorInst(kctx, builder->bbMainId))
			MiniVMBuilder_JumpTo(kctx, builder, MergeBB);
	}
	{ /* else */
		MiniVMBuilder_setBlock(kctx, builder, ElseBB);
		KLIB VisitNode(kctx, builder, kUntypedNode_getElseBlock(kctx, node), thunk);
		if(!Block_HasTerminatorInst(kctx, builder->bbMainId))
			MiniVMBuilder_JumpTo(kctx, builder, MergeBB);
	}
	/* endif */
	MiniVMBuilder_setBlock(kctx, builder, MergeBB);
	return true;
}
Example #11
0
Plant::Plant(float iter) {
	if (!cylinder)
		CreateBranch();
	if (!leaf)
		CreateLeaf();
	if (!sphere)
		CreateSphere();

	branchLength = iter;

	growRate = 0.07f;
	branches = 3;

	memUsage = sizeof(*leaf) + sizeof(*cylinder) + sizeof(*sphere);

	trunk = new SceneNode();
	trunk->SetMesh(cylinder);
	trunk->SetModelScale(Vector3(0,0,0));
	trunk->SetTransform(Matrix4::Translation(Vector3(0, 0, 0)));
	memUsage += sizeof(*trunk);
	AddChild(trunk);

	CreateTree(trunk, branchLength);
}
Example #12
0
static kbool_t FuelVM_VisitLoopNode(KonohaContext *kctx, KBuilder *builder, kNode *stmt, void *thunk, enum LoopType Loop)
{
	Block *HeadBB  = CreateBlock(BLD(builder));
	Block *BodyBB  = CreateBlock(BLD(builder));
	Block *ItrBB   = CreateBlock(BLD(builder));
	Block *MergeBB = CreateBlock(BLD(builder));

	kNode_SetLabelBlock(kctx, stmt, KSymbol_("continue"), ItrBB);
	kNode_SetLabelBlock(kctx, stmt, KSymbol_("break"),    MergeBB);

	kNode *itrBlock = SUGAR kNode_GetNode(kctx, stmt, KSymbol_("Iterator"), NULL);
	if(itrBlock != NULL) {
		assert(Loop == ForLoop);
		IRBuilder_JumpTo(BLD(builder), HeadBB);
	}
	else if(Loop == WhileLoop) {
		/* [WhileStmt]
		 * "Head" is Join Node
		 * Head  : if(COND) { goto Body } else {goto Merge }
		 * Body  : Body
		 *         ...
		 *         goto Itr
		 * Itr   : Body3
		 *         goto Head
		 * Merge : ...
		 */
		IRBuilder_JumpTo(BLD(builder), HeadBB);
	} else {
		/* [LoopStmt] (e.g. do-while loop)
		 * "Body" is Join Node
		 * Body  : Body
		 *         ...
		 *         goto Itr
		 * Itr   : Body3
		 *         goto Head
		 * Head  : if(COND) { goto Body } else {goto Merge }
		 * Merge : ...
		 */
		IRBuilder_JumpTo(BLD(builder), BodyBB);
	}

	{ /* Head */
		IRBuilder_setBlock(BLD(builder), HeadBB);
		SUGAR VisitNode(kctx, builder, kNode_getFirstNode(kctx, stmt), thunk);
		CreateBranch(BLD(builder), FuelVM_getExpression(builder), BodyBB, MergeBB);
	}

	{ /* Body */
		IRBuilder_setBlock(BLD(builder), BodyBB);
		SUGAR VisitNode(kctx, builder, kNode_getFirstBlock(kctx, stmt), thunk);
		IRBuilder_JumpTo(BLD(builder), ItrBB);

		/* Itr */
		IRBuilder_setBlock(BLD(builder), ItrBB);
		if(itrBlock != NULL) {
			SUGAR VisitNode(kctx, builder, itrBlock, thunk);
		}
		IRBuilder_JumpTo(BLD(builder), HeadBB);
	}

	IRBuilder_setBlock(BLD(builder), MergeBB);
	return true;
}