Exemplo n.º 1
0
/* remove an element from the list */
t_list * removeElement(t_list *list, void * data)
{
	t_list *current_elem;
	
	/* preconditions: the list shouldn't be empty */
	if (list == NULL)
		return NULL;
	
	/* intialize the value of `current_elem' */
	current_elem = list;
	while (  (current_elem != NULL)
			   && (LDATA(current_elem) != data))
	{
		current_elem = LNEXT(current_elem);
	}
	
	/* the value hasn't been found */
	if (current_elem == NULL)
		return list;
	
	/* the value is found */
	if (LPREV(current_elem) != NULL)
	{
		SET_NEXT(LPREV(current_elem), LNEXT(current_elem));
		if (LNEXT(current_elem) != NULL)
			SET_PREV(LNEXT(current_elem), LPREV(current_elem));
		
		_FREE_FUNCTION(current_elem);
	}
	else
	{
		/* check the preconditions */
		assert(list == current_elem);
		
		if (LNEXT(current_elem) != NULL)
      {
			SET_PREV(LNEXT(current_elem), NULL);
			
         /* update the new head of the list */
		   list = LNEXT(current_elem);
      }
      else
         list = NULL;
		
		_FREE_FUNCTION(current_elem);
	}
	
	/* postconditions: return the new head of the list */
	return list;
}
Exemplo n.º 2
0
static void
free_event(kherr_event * e)
{
    EnterCriticalSection(&cs_error);

    assert(IS_KHERR_EVENT(e));
#ifdef DEBUG
    assert(LNEXT(e) == NULL);
    assert(LPREV(e) == NULL);
#endif

    if(e->flags & KHERR_RF_FREE_SHORT_DESC) {
        assert(e->short_desc);
        PFREE((void *) e->short_desc);
    }
    if(e->flags & KHERR_RF_FREE_LONG_DESC) {
        assert(e->long_desc);
        PFREE((void *) e->long_desc);
    }
    if(e->flags & KHERR_RF_FREE_SUGGEST) {
        assert(e->suggestion);
        PFREE((void *) e->suggestion);
    }

    free_event_params(e);

    ZeroMemory(e, sizeof(*e));

    LPUSH(&evt_free_list, e);
    LeaveCriticalSection(&cs_error);
}
Exemplo n.º 3
0
int performLivenessIteration(t_cflow_Graph *graph)
{
   int modified;
   t_list *current_element;
   t_basic_block *current_bblock;

   /* initialize the value of the local variable `modified' */
   modified = 0;

   /* test the preconditions */
   if (graph == NULL) {
      cflow_errorcode = CFLOW_GRAPH_UNDEFINED;
      return modified;
   }

   /* test if `graph->endingBlock' is valid */
   if (graph->endingBlock == NULL) {
      cflow_errorcode = CFLOW_INVALID_BBLOCK;
      return modified;
   }

   /* retrieve the last basic block in the list */
   current_element = getLastElement(graph->blocks);
   
   while(current_element != NULL)
   {
      t_list *live_out_vars;
      
      current_bblock = (t_basic_block *) LDATA(current_element);
      assert(current_bblock != NULL);

      /* retrieve the variables that will be live out from this block */
      live_out_vars = computeLiveOutVars(graph, current_bblock);

      /* test if an error occurred */
      if (cflow_errorcode != CFLOW_OK)
         return modified;

      /* retrieve the liveness informations for the current bblock */
      if (performLivenessOnBlock(current_bblock, live_out_vars))
         modified = 1;

      /* remove the list `out' */
      freeList(live_out_vars);

      /* test if an error occurred */
      if (cflow_errorcode != CFLOW_OK) {
         return modified;
      }

      /* retrieve the previous element in the list */
      current_element = LPREV(current_element);
   }

   /* return 1 if another liveness iteration is required */
   return modified;
}
Exemplo n.º 4
0
/* remove a link from the list `list' */
extern t_list * removeElementLink(t_list *list, t_list *element)
{
	t_list *current_elem;
	
	/* preconditions */
	if (list == NULL || element == NULL)
		return list;
	
	if ((LPREV(element) == NULL) && (element != list))
		return list;
	
	/* intialize the value of `current_elem' */
	current_elem = list;
	while(	(LDATA(current_elem) != LDATA(element))
			|| (LPREV(current_elem) != LPREV(element))
			|| (LNEXT(current_elem) != LNEXT(element)) )
	{
		/* retrieve the next element from the list */
		current_elem = LNEXT(current_elem);
		
		/* test if we reached the end of the list */
		if (current_elem == NULL)
			return list;
	}

   if (LPREV(element) == NULL)
   {
      assert(list == element);
      
      if (LNEXT(element) != NULL)
      {
         list = LNEXT(element);
         SET_PREV(LNEXT(element), NULL);
      }
      else
         list = NULL;

      /* remove the allocated memory of element */
      _FREE_FUNCTION(element);
      return list;
   }
   
	/* we found the element */
	if (LPREV(element) != NULL)
	{
		/* we found the element, and it is the top of the list */
		SET_NEXT(LPREV(element), LNEXT(element));
	}
	
	if (LNEXT(element) != NULL)
		SET_PREV(LNEXT(element), LPREV(element));
	
	/* remove the allocated memory of element */
	_FREE_FUNCTION(element);
	
	/* return the new top of the list */
	return list;
}
Exemplo n.º 5
0
/* MUST be called with cs_error held */
static void
add_event(kherr_context * c, kherr_event * e)
{
    kherr_event * te;

    assert(IS_KHERR_CTX(c));
    assert(IS_KHERR_EVENT(e));
#ifdef DEBUG
    assert(LPREV(e) == NULL && LNEXT(e) == NULL);
#endif

    te = QBOTTOM(c);
    if (te && !(te->flags & KHERR_RF_COMMIT)) {
        commit_event(c, te);
    }

    QPUT(c,e);
}
Exemplo n.º 6
0
int performLivenessOnBlock(t_basic_block *bblock, t_list *out)
{
   t_list *current_element;
   t_list *cloned_list;
   t_cflow_Node *next_node;
   t_cflow_Node *current_node;
   int modified;

   /* initialize the local variables */
   modified = 0;

   if (bblock == NULL || bblock->nodes == NULL) {
      cflow_errorcode = CFLOW_INVALID_BBLOCK;
      return modified;
   }

   current_element = getLastElement(bblock->nodes);
   current_node = (t_cflow_Node *) LDATA(current_element);
   assert(current_node != NULL);

   /* update the out set */
   current_node->out = addListToSet
         (current_node->out, out, NULL, &modified);

   /* update the in list */
   cloned_list = cloneList(current_node->out);
   
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
   if ((current_node->uses)[0] != NULL && (current_node->uses)[0]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[0], NULL);
   if ((current_node->uses)[1] != NULL && (current_node->uses)[1]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[1], NULL);
   if ((current_node->uses)[2] != NULL && (current_node->uses)[2]->ID != REG_0)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[2], NULL);
#else
   if ((current_node->uses)[0] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[0], NULL);
   if ((current_node->uses)[1] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[1], NULL);
   
   if ((current_node->uses)[2] != NULL)
      cloned_list = addVariableToSet
            (cloned_list, (current_node->uses)[2], NULL);
#endif



#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
   if (current_node->def != NULL && (current_node->def)->ID != REG_0)
#else
   if (current_node->def != NULL)
#endif
   {
      int found = 0;
      int current_use_idx = 0;
      
      do
      {
         if ((current_node->uses)[current_use_idx] != NULL)
         {
            if ((current_node->uses)[current_use_idx]->ID == current_node->def->ID)
               found = 1;
         }
         
         current_use_idx++;
         
      } while((found == 0) && (current_use_idx < 3));
      
      if (!found)
         cloned_list = removeElement(cloned_list, current_node->def);
   }
   
   current_node->in = addListToSet
         (current_node->in, cloned_list, NULL, &modified);

   /* remove the cloned list */
   freeList(cloned_list);
   
   /* set the new value of next_node */
   next_node = current_node;
   current_element = LPREV(current_element);
   while (current_element != NULL)
   {
      /* take a new node */
      current_node = (t_cflow_Node *) LDATA(current_element);
      assert(current_node != NULL);

      /* clone the `in' list of the next_node */
      cloned_list = cloneList(next_node->in);
      
      /* update the out list */
      current_node->out = addListToSet
            (current_node->out, cloned_list, NULL, &modified);
      
      /* remove the cloned list */
      freeList(cloned_list);

      /* clone the `in' list of the next_node */
      cloned_list = cloneList(current_node->out);
      
      /* update the in list */
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
      if ((current_node->uses)[0] != NULL && (current_node->uses)[0]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[0], NULL);
      if ((current_node->uses)[1] != NULL && (current_node->uses)[1]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[1], NULL);
      if ((current_node->uses)[2] != NULL && (current_node->uses)[2]->ID != REG_0)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[2], NULL);
#else
      if ((current_node->uses)[0] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[0], NULL);
      if ((current_node->uses)[1] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[1], NULL);
      if ((current_node->uses)[2] != NULL)
         cloned_list = addVariableToSet
               (cloned_list, (current_node->uses)[2], NULL);
#endif
      
#if CFLOW_ALWAYS_LIVEIN_R0 == (1)
      if (current_node->def != NULL && (current_node->def)->ID != REG_0)
#else
      if (current_node->def != NULL)
#endif
      {
         int found = 0;
         int current_use_idx = 0;
      
         do
         {
            if ((current_node->uses)[current_use_idx] != NULL)
            {
               if ((current_node->uses)[current_use_idx]->ID
                        == current_node->def->ID)
               {
                  found = 1;
               }
            }
            current_use_idx++;
         
         } while((found == 0) && (current_use_idx < 3));
      
         if (!found)
            cloned_list = removeElement(cloned_list, current_node->def);
      }

      current_node->in = addListToSet
            (current_node->in, cloned_list, NULL, &modified);

      /* remove the cloned list */
      freeList(cloned_list);
      
      /* update the loop control informations */
      current_element = LPREV(current_element);
      next_node = current_node;
   }

   /* return the `modified' value */
   return modified;
}
Exemplo n.º 7
0
/* add an element `data' to the list `list' at position `pos'. If pos is negative
 * , or is larger than the number of elements in the list, the new element is
 * added on to the end of the list. Function `addElement' returns a pointer
 * to the new head of the list */
t_list * addElement(t_list *list, void * data, int pos)
{
	t_list *result;
	t_list *current_elem;
	t_list *last_elem;
	int	current_pos;
	
	/* initialize the value of `result' */
	result = newElement(data);

	if (list == NULL)
		return result;
	
	if (pos == 0)
	{
		/* update the control informations */
		SET_NEXT(result, list);
		SET_PREV(list, result);
		
		/* return the new head of the list */
		return result;
	}
	
	/* retrieve the last element of the list */
	last_elem = getLastElement(list);
	assert(last_elem != NULL);
	
	if (pos < 0)
	{
		/* update the control informations */
		SET_NEXT(last_elem, result);
		SET_PREV(result, last_elem);
		
		/* update the value of result */
		return list;
	}
	
	/* `pos' is a positive integer */
	current_pos = 0;
	current_elem = list;
	
	while(current_pos < pos)
	{
		if (current_elem == last_elem)
		{
			/* update the control informations */
			SET_NEXT(last_elem, result);
			SET_PREV(result, last_elem);
			
			/* update the value of result */
			return list;
		}
		
		/* update the loop informations */
		current_elem = LNEXT(current_elem);
		current_pos++;
	}

	/* assertions */
	assert(current_elem != NULL);
	
	/* update the control informations */
	SET_NEXT(result, current_elem);
	SET_PREV(result, LPREV(current_elem));
	SET_NEXT(LPREV(current_elem), result);
	SET_PREV(current_elem, result);
	
	/* return the new head of the list */
	return list;
}