Beispiel #1
0
void createListProbLoop(xmlNode *node, tloop_node *loop_node)
{
	char *type, *pdf, *idloop;

	type = getAttrStr(node, "type");
	idloop = getAttrStr(node, "idloop");
	strncpy(loop_node->idloop, idloop, 8);
	free(idloop);
	loop_node->type_loop = type[0];
	switch (type[0])
	{
		case '1': {
				loop_node->probability.prob_start = 1;
				loop_node->probability.prob_finish = getAttrDbl(node, "max-times");
				loop_node->probability.probability_density_function =  '1';
			} break;
		case '2': {
				loop_node->probability.prob_start = getAttrDbl(node, "start");
				loop_node->probability.prob_finish = getAttrDbl(node, "finish");
				start_range = getAttrDbl(node, "start-range");
				end_range = getAttrDbl(node, "end-range");
				step = getAttrDbl(node, "step");
				pdf = getAttrStr(node, "pdf");
				loop_node->probability.probability_density_function = pdf[0];
				free(pdf);
			} break;
	}
	free(type);
}
Beispiel #2
0
void SVG_Image::drawNode(Node node)
{
    auto nodeXY = getCoords(node, gridSize);
    pugi::xml_node xmlNode = nodes.append_child("circle");
    xmlNode.append_attribute("cx") = getAttrStr(nodeXY.first).c_str();
    xmlNode.append_attribute("cy") = getAttrStr(nodeXY.second).c_str();
    xmlNode.append_attribute("r") = getAttrStr(nodeRadius).c_str();
}
Beispiel #3
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;
	}
}
Beispiel #4
0
void SVG_Image::drawEdge(Node from, Node to)
{
    auto fromXY = getCoords(from, gridSize);
    auto toXY = getCoords(to, gridSize);
    pugi::xml_node xmlNode = edges.append_child("line");
    xmlNode.append_attribute("x1") = getAttrStr(fromXY.first).c_str();
    xmlNode.append_attribute("y1") = getAttrStr(fromXY.second).c_str();
    xmlNode.append_attribute("x2") = getAttrStr(toXY.first).c_str();
    xmlNode.append_attribute("y2") = getAttrStr(toXY.second).c_str();
}
Beispiel #5
0
double xmlutils::getAttrDouble(tinyxml2::XMLElement *e, std::string name, double defaultValue)
{
    if(!hasAttr(e, name)) return defaultValue;

    std::string value = getAttrStr(e, name);

    return boost::lexical_cast<double>(value);
}
Beispiel #6
0
float xmlutils::getAttrFloat(tinyxml2::XMLElement *e, std::string name, float defaultValue)
{
    if(!hasAttr(e, name)) return defaultValue;

    std::string value = getAttrStr(e, name);

    return boost::lexical_cast<float>(value);
}
Beispiel #7
0
std::string xmlutils::getAttrStr(tinyxml2::XMLElement *e, std::string name, std::string defaultValue)
{
    if(!hasAttr(e, name)) return defaultValue;

    std::string value = getAttrStr(e, name);

    return value;
}
Beispiel #8
0
/*
 * Initialize the SVG file. SVG is just xml. Initialize from a string holding a
 * base SVG tag. Create groups for edges and nodes.
 */
void SVG_Image::init_xml()
{
    doc.load("<svg width=\"9cm\" height=\"7cm\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"></svg>");
    pugi::xml_node rootNode = doc.child("svg");

    // If edges appear first in the document, they will be rendered "below"
    // the nodes for a clean appearance.
    edges = rootNode.append_child("g");
    edges.append_attribute("id") = "edges";
    edges.append_attribute("stroke") = "black";
    edges.append_attribute("stroke-width") = getAttrStr(edgeThickness).c_str();

    nodes = rootNode.append_child("g");
    nodes.append_attribute("id") = "nodes";
    nodes.append_attribute("fill") = "red";
    nodes.append_attribute("stroke") = "black";
    nodes.append_attribute("stroke-width") = getAttrStr(nodeThickness).c_str();
}
Beispiel #9
0
bool xmlutils::getAttrBool(tinyxml2::XMLElement *e, std::string name, bool defaultValue)
{
    if(!hasAttr(e, name)) return defaultValue;

    std::string value = getAttrStr(e, name);

    if(value == "true")
        return true;
    if(value == "false")
        return false;

    std::stringstream ss;
    ss << "invalid value '" << value << "' for attribute '" << name << "': must be true or false";
    throw std::range_error(ss.str());
}
Beispiel #10
0
/***
	addBlock: Adds the current node in the queue of blocks
	current: Current node from cfg's nodes list
*/
void addBlock(xmlNode *current)
{
	char *id;

	id = getAttrStr(current, "id");

	if (start_block == NULL)
	{
		//puts("inicio entao\n");
		start_block = (tblock *) malloc(sizeof(tblock));
		start_block->next_block = NULL;
		strncpy(start_block->info_node.id, id, 5);
		start_block->info_node.clock_cycles = getAttrInt(current, "clock-cycles");
		start_block->class_node = getAttrChr(current, "class");
		start_block->info_node.energy = getAttrDbl(current, "energy");
		start_block->info_node.consumed_cycles = 0;
		start_block->info_node.consumed_energy = 0;
		start_block->timesexec = 0;
		start_block->node = createNode(current);
		end_block = start_block;
		//puts("fim entao\n");
	}
	else
	{
		puts("inicio senao\n");
		puts(id);
		tblock *new_block;

		new_block = (tblock *) malloc(sizeof(tblock));
		new_block->next_block = NULL;
		end_block->next_block = new_block;
		end_block = new_block;
		strncpy(new_block->info_node.id, id, 5);
		new_block->info_node.clock_cycles = getAttrInt(current, "clock-cycles");
		new_block->info_node.energy = getAttrDbl(current, "energy");
		new_block->info_node.consumed_cycles = 0;
		new_block->info_node.consumed_energy = 0;
		new_block->timesexec = 0;
		new_block->class_node = getAttrChr(current, "class");
		new_block->node = createNode(current);
		puts("fim senao\n");
	}

	free(id);
}
Beispiel #11
0
/***
	This function builds the list of clauses wich belong to IF node
*/
void buildClauses(xmlNode *node, tclauses_cond *clauses){

	int qtclauses, i;
	xmlNode *current, *probability;
	char *tmp;

	qtclauses = countElement(node, "condition");
	if (qtclauses > 0){
		clauses->lconditions = (tcondition *) malloc(sizeof(tcondition) * qtclauses);
		clauses->qtclauses = qtclauses;
		current = node->children;
		i=0;
		while(current) // scan tags condition
		{
			if (!strcmp((char *)current->name, "condition")){ // "probability"
				clauses->lconditions[i].timesexec = 0;
				tmp = getAttrStr(current, "id");
				strncpy(clauses->lconditions[i].info_cond.id, tmp, 5);
				free(tmp);
				clauses->lconditions[i].info_cond.clock_cycles = getAttrDbl(current, "clock-cycles");
				clauses->lconditions[i].info_cond.energy = getAttrDbl(current, "energy");
				clauses->lconditions[i].info_cond.consumed_cycles = 0.0;
				clauses->lconditions[i].info_cond.consumed_energy = 0.0;
				probability = current->children;
				while(probability) // scan tags probability
				{
					if (!strcmp((char *)probability->name, "probability")){
						start_range = getAttrDbl(probability, "start-range");
						end_range = getAttrDbl(probability, "end-range");
						step = getAttrDbl(probability, "step");
						clauses->lconditions[i].probability.prob_start = getAttrDbl(probability, "start");
						clauses->lconditions[i].probability.prob_finish = getAttrDbl(probability, "finish");
						clauses->lconditions[i].probability.probability_density_function = getAttrChr(probability, "pdf");
					}
					probability = probability->next;
				}
				i++;
			}
			current = current->next;
		}
	}
}
Beispiel #12
0
std::vector<int> xmlutils::getAttrIntV(tinyxml2::XMLElement *e, std::string name, std::vector<int> defaultValue, int minLength, int maxLength, const char *sep)
{
    if(hasAttr(e, name))
    {
        try
        {
            std::vector<int> ret;
            string2vector(getAttrStr(e, name), ret, minLength, maxLength, sep);
            return ret;
        }
        catch(std::range_error &ex)
        {
            std::stringstream ss;
            ss << "attribute '" << name << "' " << ex.what();
            throw std::range_error(ss.str());
        }
    }
    else
    {
        return defaultValue;
    }
}
Beispiel #13
0
/***
	createNode: This function creates a new node wich will be pointed by the current block of the graph
	current: Current node (block) of the graph
*/
void *createNode(xmlNode *current)
{
	char class, *tmp;
	xmlNode *axcurrent=NULL;

	class = getAttrChr(current, "class");
	switch(class)
	{
		case 48: // sequential block
			{
				tsequential_node *snode;
				snode = (tsequential_node *) malloc(sizeof(tsequential_node));
				snode->next_node = NULL;
				return ((void *) snode);
			} break;
		case 49: // branch block
			{
				tbranch_node *bnode;
				bnode = (tbranch_node *) malloc(sizeof(tbranch_node));
				bnode->clauses = (tclauses_cond *) malloc(sizeof(tclauses_cond));
				bnode->then_node = NULL;
				bnode->else_node = NULL;
				bnode->clauses->root_express = NULL;
				tmp = getAttrStr(current, "bool-express");
				strncpy(bnode->clauses->bexpress, tmp, 100);
				free(tmp);
				buildClauses(current, bnode->clauses);
				buildTreeExpress(bnode->clauses);
				printf("ROOT: %p\n", bnode->clauses->root_express);
				return ((void *) bnode);
			} break;
		case 50:  // loop block
			{
				tloop_node *lnode;
				lnode = (tloop_node *) malloc(sizeof(tloop_node));
				lnode->next_node = NULL;
				lnode->exit_node = NULL;
				lnode->clauses = NULL;
				lnode->nrloops   = 0;
				lnode->running = 0;

				if (getAttrStr(current, "bool-express") == NULL){
					current = getElement(current, "probability");
					createListProbLoop(current, lnode);
				} else {
					lnode->clauses = (tclauses_cond *) malloc(sizeof(tclauses_cond));
					axcurrent =  getElement(current, "condition");
					axcurrent =  getElement(axcurrent, "probability");
					strcpy(lnode->idloop, getAttrStr(axcurrent, "idloop"));
					lnode->type_loop = '3';
					tmp = getAttrStr(current, "bool-express");
					strncpy(lnode->clauses->bexpress, tmp, 100);
					free(tmp);
					buildClauses(current, lnode->clauses);
					buildTreeExpress(lnode->clauses);
					printf("WHILE ROOT: %p\n", lnode->clauses->root_express);
				}
				return ((void *) lnode);
			} break;
		case 51:  // switch block
			{
				tbranch_switch_node *lswitch;
				lswitch = (tbranch_switch_node *) malloc(sizeof(tbranch_switch_node));
				lswitch->first_case = NULL;
				lswitch->last_case  = NULL;
				lswitch->prob_cases = NULL;
				lswitch->qtcases = 0;
				createListProbSwitch(current, lswitch);
				return ((void *) lswitch);
			} break;
		case 52:  // case block
			{
				tcase_node *lcase;
				lcase = (tcase_node *) malloc(sizeof(tcase_node));
				return ((void *) lcase);
			}

	}

	return NULL;
}