Exemple #1
0
/*
 *	clean-up and exit the software
 */
int	main_exit( void)
{
/*
 *	print the symbol table 
 */
#ifdef	YYDEBUG
	if( IS_FLAGS_SYMBOL( data.flags))
	{
		print_symbol_table();
	}
#endif
/*
 *	deallocate the symbol table list
 */
	free_tuple_list( data.symbol_table);
	free_tuple_list( data.symbol_table_free);
/*
 *	check if memory leak
 */
	if( data.memory)
		fprintf( stderr, "Error: memory deallocation error: %d\n", data.memory);
/*
 *	check if compiler warnings
 */
	if( data.warnings)
		fprintf( stderr, "Warning: compiler warnings: %d\n", data.warnings);
/*
 *	check if compiler errors 
 */
	if( data.errors)
		fprintf( stderr, "Error: compiler errors: %d\n", data.errors);
	return( data.errors);
}
/*
 *	convert postfix expression into tuple
		$$.tuple = tuple_postfix_expr( $1.tuple, 0);
		$$.tuple = tuple_postfix_expr( $1.tuple, $3.tuple);
 */
TUPLE	*tuple_postfix_expr( TUPLE *postfix_expr, TUPLE *argument_expr_list)
{
	TUPLE	*lists;
	TUPLE	*tuple_next;
/*
 *	special case is printf, after each argument insert call to printf
 */
	if( ! strcmp( postfix_expr->buffer, "printf"))
	{
		for( lists = argument_expr_list; lists; )
		{
			if( lists->mask & MASK_W_REG)
			{
				tuple_next = lists->next;
				lists->next = new_tuple( I_CALL, 0, 0, MASK_LABEL, "printf", sizeof( "printf") + 1); /* call printf */
				lists->next->next = tuple_next;
				lists = lists->next->next;
			}
			else
			{
				lists = lists->next;
			}
		}
		free_tuple_list( postfix_expr);
		return( argument_expr_list);
	}
	postfix_expr->token = I_CALL;
	postfix_expr->mask = MASK_LABEL;
	tuple_tail_to_head( postfix_expr, argument_expr_list);
	return( postfix_expr);
}
/*
 *	update a value of an identifier in symbol table
		$$.tuple = symbol_init_declarator( $1.tuple, $3.tuple);
 */
TUPLE	*symbol_init_declarator( TUPLE *declarator, TUPLE *initializer)
{
	TUPLE	*lists;
/*
 *	can be a list of identifiers
 */
	for( lists = declarator; lists; lists = lists->next)
	{
/*
 *	create a symbol with this value and copy it to identifier list
 */
		if( initializer)
		{
			create_symbol( 0, initializer->value, lists->buffer, lists->length);
			lists->value = initializer->value;
		}
		else
			create_symbol( 0, 0, lists->buffer, lists->length);
	}
/*
 *	free the initializer linked list
 */
	free_tuple_list( initializer);
	return( declarator);
}
/*
 *	code generator for the pic16f84 processor
		code_generator_pic16f84( $1.tuple);
 */
void	code_generator_pic16f84( TUPLE *tuple_list)
{
	TUPLE *tuple;
/*
 *	debug tuple list
 */
#ifdef	YYDEBUG
	if( IS_FLAGS_DEBUG( data.flags))
		print_tuple_list( tuple_list);
#endif
/*
 *	generate the header
 */
	code_generator_pic_prefix();
/*
 *	walk the tuple list and generate PIC16F85 assembler code
 */
	for( tuple = tuple_list; tuple; tuple = tuple->next)
	{
		code_generator_instr( tuple);
	}
/*
 *	generate the end of pic code
 */
	code_generator_pic_postfix();
/*
 *	deallocate the tuple linked list
 */
	free_tuple_list( tuple_list);
	return;
}
/*
 *	generate initialize code for this list of identifiers
		$$.tuple = tuple_declaration( $1.token, $$.tuple);
 */
TUPLE	*tuple_declaration( int declaration_specifiers, TUPLE *init_declarator_list)
{
	TUPLE	*lists;
	TUPLE	*symbol;
	TUPLE	*tuple;
	TUPLE	*tuple_head = 0;
/*
 *	can be a list of identifiers
 */
	for( lists = init_declarator_list; lists; lists = lists->next)
	{
/*
 *	find the identifier in the symbol table (shall already be there!)
 */
		symbol = find_symbol( 0, lists->buffer, lists->length);
/*
 *	generate the intermediate code to initialize the variables
 */
		if( symbol)
		{
			if( symbol->level == 0 || symbol->value)
			{
				tuple = new_tuple( I_MOV, symbol->value, 0, MASK_VALUE, 0, 0);
				tuple_head = tuple_tail_to_head( tuple_head, tuple);
			}
			if( IS_FLAGS_ADDRESS( data.flags))
				tuple = new_tuple( I_MOV, 0, symbol->address, MASK_ADDRESS, 0, 0);
			else
				tuple = new_tuple( I_MOV, 0, 0, MASK_LABEL, symbol->buffer, symbol->length);
			tuple->level = symbol->level;
			tuple_head = tuple_tail_to_head( tuple_head, tuple);
		}
	}
	free_tuple_list( init_declarator_list);
	return( tuple_head);
}
Exemple #6
0
void backwards(int * trace, int * max_used_color,
               int * vertex_max_color, int * current_vertex,
               int * satur_degree, Graph * graph, tuple * base,
               int * popularity, int * coloring,
               int * depth, int upper_bound, int lower_bound) {
  
  // Se determina la posición en la traza donde se encuentra
  // el vértice desde el cual se hace backtracking
  int vertex_position = lin_search(trace, *current_vertex, *depth);
  
  
  // Se averigua si el vértice de donde se parte
  // el backtracking es la raiz
  if (vertex_position == 0) {
    int vertex_color = graph[trace[vertex_position]].color;
    update_all(trace, graph, base, popularity, *depth,
               vertex_position, satur_degree);
    // Quitamos su color del FC
    graph[trace[vertex_position]].FC[vertex_color] = 0;

    // Se determina el máximo color utilizado hasta ahora
    max_color(popularity, max_used_color, upper_bound);
    
    if (valid_FC(graph, trace[vertex_position],lower_bound+1)) {
      *current_vertex = trace[vertex_position];
      *vertex_max_color = 0;
      return;
    }
    else {
      // Se ha llegado a la raiz y no hay mas colores 
      // posibles que introducir
      *current_vertex = -1;
      return;
    }
  }
  else {
    tuple_list * candidates = NULL;
    
    if (vertex_position == -1) {
      // Significa que el vértice donde quedó forward 
      // tuvo FC vació, por lo tanto no se encontró en 
      // la traza. Se llama directamente label
      candidates = label(graph, *depth + 1,
                         *max_used_color, trace, *current_vertex);
      vertex_position = *depth + 1;
    }
    else {
      // Se logró una coloración completa. Por lo tanto:
      // Se decolorean todos los vértices subiendo en el 
      // árbol hasta llegar al vértice de mínimo rango 
      // con el mayor color usado en la coloración parcial actual
      update_all(trace, graph, base, popularity, *depth,
                 vertex_position, satur_degree);
      
      // Se procede a hacer el etiquetado partiendo del vértice
      // con coloración más alta y de rango mínimo. O partiendo 
      // del vértice cuyo FC se hizo vacío
      candidates = label(graph, vertex_position,
                         *max_used_color, trace, *current_vertex);
    }

    // Se verifica que la lista de candidatos del label
    // sea distinta de Nula. En caso contrario no hay más
    // backtracking que hacer y se consiguió una coloración
    while (candidates != NULL) {
      
      int vertex_color = graph[candidates->vertex].color;
 
      // Se decolorean todos los vértices que están a partir
      // de una posición anterior desde donde se hizo labeling 
      // hasta el vértice de rango máximo entre todos los 
      // etiquetados
      update_all(trace, graph, base, popularity,
                 vertex_position - 1, candidates->position,
                 satur_degree);
 
      // Se elimina de su FC el color que tiene actualmente
      graph[candidates->vertex].FC[vertex_color] = 0;
    
      // Se determina el máximo color utilizado hasta ahora
 
      max_color(popularity, max_used_color, upper_bound);
 
      // Se verifica que el vértice de máximo rango etiquetado
      // no tenga un FC vacío. Al ser su FC no vació se hace
      // retornar el algoritmo
    
      if (valid_FC(graph, candidates->vertex, *max_used_color)) {
        // Se determina la posición en la traza
        // del vértice de mínimo rango que tiene
        // el color máximo utilizado
        det_vertex_max_color(graph, trace,*max_used_color,
                             vertex_max_color, candidates->position);
        // Se indica la posición en la traza del vértice 
        // del cual se parte para hacer forward.
        *current_vertex = candidates->vertex;
        *depth = candidates->position;
        free_tuple_list(candidates);
        return;
      }
      else {
        tuple_list * tmp = candidates;
        candidates = candidates->next;
        tmp->next = NULL;
        free_tuple_list(tmp);
      }
    }
  }
  // La lista CP está vacía por lo tanto se retorna el
  // algoritmo con current_vertex siendo cero.
  *current_vertex = -1;
  return;
}
/*
 *	if main( int argc, char *argv[]) then delete parameters
		$$.tuple = tuple_parameter_list( $1.tuple, $3.tuple);
 */
TUPLE	*tuple_parameter_list( TUPLE *parameter_list, TUPLE *parameter_declaration)
{
	free_tuple_list( parameter_list);
	free_tuple_list( parameter_declaration);
	return( (TUPLE*)0);
}