예제 #1
0
/***
	buildGraphFromEdges: This function builds the execution graph based on structs defined in control-flow-graph.h
	edges: Set of edges loaded from cfg xml file
*/
void buildGraphFromEdges(xmlNode *edges)
{
	xmlNode *current = NULL;
	tblock *from = NULL, *to = NULL;
	char *tmp;

	current = edges->children;
	while(current) {
		if (current->type == XML_ELEMENT_NODE) {
			tmp = getAttrStr(current, "from-idnode");
			from = searchBlock(start_block, tmp);
			free(tmp);
			tmp = getAttrStr(current, "to-idnode");
			to = searchBlock(start_block, tmp);
			free(tmp);
			printf("%s->%s\n",from->info_node.id, to->info_node.id);
			if (from && to) {
				switch(from->class_node) {
					case 48: // normal block
						((tsequential_node *) (from->node))->next_node = to; break;
					case 49: // branch block
						{
							if (!((tbranch_node *) (from->node))->then_node)
								((tbranch_node *) (from->node))->then_node = to;
							else ((tbranch_node *) (from->node))->else_node = to;
						} break;
					case 50: // loop block
						{
							if (!((tloop_node *) from->node)->next_node)
								((tloop_node *) from->node)->next_node = to;
							else ((tloop_node *) from->node)->exit_node = to;
						} break;
					case 51: // switch block
						{
							tswitch_case *new_case;
							new_case = (tswitch_case *) malloc(sizeof(tswitch_case));
							new_case->node_case = to;
							new_case->next_case = NULL;

							if (((tbranch_switch_node *) from->node)->first_case == NULL){

								((tbranch_switch_node *) from->node)->first_case = new_case;
								((tbranch_switch_node *) from->node)->last_case = new_case;
							}
							else{
								((tbranch_switch_node *) from->node)->last_case->next_case = new_case;
								((tbranch_switch_node *) from->node)->last_case = new_case;
							}

						} break;
					case 52: // case node
							((tcase_node *) from->node)->next_node = to; break;
				}
			}
		}
		current = current->next;
	}
}
예제 #2
0
ofInterObj * demoAnim::searchForObject(ofTag & tag, int & _x, int & _y)
{
  ofInterObj * ret=0;
  string where=tag.getAttribute("where");
  string xTemp=tag.getAttribute("x");
  string yTemp=tag.getAttribute("y");
  vector<string> whSplit = ofSplitString(where, "[].");
  if(whSplit[0]=="sidebar"){
    if(whSplit.size()==2) ret=((*sideBar)[ofToInt(whSplit[1])]);
    if(whSplit.size()==3) ret=&((*(*sideBar)[ofToInt(whSplit[1])])[ofToInt(whSplit[2])]);
  }
  if(whSplit[0]=="openBar"){
	  if(whSplit.size()==2&&sideBar->openBar()){
		  if(whSplit[1]=="drop") ret=&((as_dynamic(sideBar->openBar()))->select);
		  else ret=&((*(sideBar->openBar()))[ofToInt(whSplit[1])]);
	  }
  }
  else if(whSplit[0]=="sidebarButton"){
    if(whSplit.size()==2) ret=&((*sideBar)[ofToInt(whSplit[1])])->button;
  }
  else if(whSplit[0]=="base"){
    if(whSplit.size()==1) ret=&(blocks->base);
    else if(whSplit.size()>=2&&whSplit[1]=="last") ret=searchBlock(whSplit,blocks->base.blocksOn.back(),2);
    else if(whSplit.size()>=2) ret=searchBlock(whSplit,blocks->base.blocksOn[ofToInt(whSplit[1])],2);
  }
  else if(whSplit[0]=="upload"){
    ret=&blocks->base.uploadBut;
    //TODO: update the base block to include the upload button.
  }
  else if(whSplit[0]=="test"){
    ret=&blocks->base.testBut;
  }
  vector<string> xSpl = ofSplitString(xTemp, "+-/*");
  if(xSpl.size()==1) _x=ofToInt(xSpl[0]);
  else if(xSpl.size()==2) _x=operaterByChar(ret->w,xTemp[xSpl[0].length()],ofToFloat(xSpl[1]));
  vector<string> ySpl = ofSplitString(yTemp, "+-/*");
  if(ySpl.size()==1) _y=ofToInt(ySpl[0]);
  else if(ySpl.size()==2) _y=operaterByChar(ret->h,yTemp[ySpl[0].length()],ofToFloat(ySpl[1]));
  
  return ret;
}
예제 #3
0
ofInterObj * demoAnim::searchBlock(vector<string> spl, block & currentBlock, int offset)
{
  ofInterObj * ret=0;
  if(offset>=spl.size()) ret=&currentBlock;
  else {
    string which=spl[offset];
    int num=((offset>=spl.size()-1)?ofToInt(spl[offset+1]):0);
    if(which=="inside") ret=searchBlock(spl,currentBlock.blocksIn[ofToInt(spl[offset+1])],offset+2);
    else if(which=="drop") ret=&(currentBlock.ddGroup[ofToInt(spl[offset+1])]);
  }
  return ret;
}
예제 #4
0
void checkAndInsert(int x){
    int lru_index;
    int pos;
    cache_blk_t *blkPtr;
    blkPtr=searchBlock(x); 
    int index;
    if(!blkPtr){ //value not found 
                //insert new value to lru pos
                //and promote
        
        #ifdef DEBUG
        printf("cache miss, inserting value %d\n",x);
        #endif 
        if(strategy_type==PLRU){
            blkPtr=find_plru();
            lru_index=getIndex(blkPtr);
            printf("evicting value:%d on pos %d for %d\n",blkPtr->value,lru_index,x);
            blkPtr->value=x;
            promote(blkPtr);
        }
        else{ //using IPV vector
            placeValue(x,15, ipv[16]); //17 position denodes the position a value is placed
        }
    }
    else{
        #ifdef DEBUG
        printf("cache hit!..promoting %d\n",getIndex(blkPtr));
        #endif
        if(strategy_type==PLRU)
            promote(blkPtr); 
        else{
                index=getIndex(blkPtr);
                placeValue(x,index,ipv[index]);
        }
    }
}