Example #1
0
/*create type of a variable*/
struct type_descriptor*
create_type(struct tree_node* specifier_node){

	assert(specifier_node -> unit_code == Specifier);

	int type_code = get_type_code_from_specifier(specifier_node);
	struct struct_descriptor* sd;
	
	if(type_code == TYPE_INT || type_code == TYPE_FLOAT){
		sd = NULL;
	}
	if(type_code == TYPE_STRUCT){ 

		//Specifier -> StructSpecifier
		struct tree_node* structspecifier_node = specifier_node -> child;
		if(structspecifier_node -> child -> sibling -> unit_code == Tag){	//exist struct
			char *struct_name = structspecifier_node -> child -> sibling -> child -> unit_value;
			sd = find_struct(struct_table_head, struct_name);
			if(sd == NULL){
				printf("Error Type 17 at line %d : Undefined struct %s\n", specifier_node -> lineno, struct_name );
	 			semantic_error_flag = true;
	 			return NULL;
			}
		}
		else{	//new struct
			sd = create_structure(structspecifier_node);
		}
	}
	return create_type_descriptor(type_code, sd);
}
Example #2
0
/*analyze an extdef node*/
void
analyze_extdef_node(struct tree_node* extdef_node){

	assert( extdef_node -> unit_code == ExtDef );
	
	/*switch

		case fundef

		case global var def
				
		case struct def
	*/
	struct tree_node* specifier_node = extdef_node -> child;
	struct tree_node* second_child = extdef_node -> child -> sibling;
	switch(second_child -> unit_code){
		case ExtDecList: {	//ExtDef -> Specifier ExtDecList SEMI
			struct tree_node* extdeclist_node  = second_child;
			while(true){
				struct tree_node* vardec_node = extdeclist_node -> child;
				create_variable(specifier_node, vardec_node, var_table_head, false);
				if(extdeclist_node -> child -> sibling != NULL)
					extdeclist_node = extdeclist_node -> child -> sibling -> sibling;
				else
					break;
			}
			break;
		}
		case FunDec: {		//ExtDef -> Specifier FunDec CompSt
			struct tree_node* fundec_node = second_child;
			struct tree_node* compst_node = fundec_node -> sibling;
			analyze_function_node(specifier_node, fundec_node, compst_node);
			break;
		}
		case SEMI : {		//Extdef -> Specifier SEMI;
			
			if(specifier_node -> child -> unit_code == TYPE){	//Specifier -> TYPE
				printf("Error type 100 at line %d: Empty variable definition\n", specifier_node -> lineno);
				return;
			}
			//Specifier -> StructSpecifier
			struct tree_node* structspecifier_node = specifier_node -> child;
			if(structspecifier_node -> child -> sibling -> unit_code == Tag){	//StructSpecifier -> STRUCT Tag
				printf("Error type 100 at line %d: Empty structure definition\n", structspecifier_node -> lineno);
				return ;  
			}
			if(structspecifier_node -> child -> sibling -> child == NULL){	//OptTag -> empty
				printf("Error type 100 at line %d: Anonymous structure definition without variables\n", structspecifier_node -> lineno);
				return ;
			}
			create_structure(structspecifier_node);
			break;
		}
		default: assert(0);
	}

}
Example #3
0
network::network(const size_t number_oscillators,
                 const conn_type connection_type,
                 const size_t height,
                 const size_t width) {

    m_num_osc = number_oscillators;
    m_conn_type = connection_type;
    m_height = height;
    m_width = width;

    /* check that height and width are correct in case of grid structure */
    if ( (connection_type == conn_type::GRID_EIGHT) || (connection_type == conn_type::GRID_FOUR) ) {
        if ((height * width) != number_oscillators) {
            throw std::runtime_error("Network height (" + STR(height) + ") x width (" + STR(width) + ") must be equal to total size '" + STR(number_oscillators) + "'");
        }
    }

    create_structure();
}
Example #4
0
File: main.c Project: thutt/lmsbw
int
main(int argc, char *argv[])
{
    directory_t *root;
    unsigned int seed = (unsigned int)time(NULL);

    process_arguments(argc, argv);
    validate_arguments();

    if (arg_seed_set) {
        seed = arg_seed;
    }
    srand(seed);

    root = create_structure(0, arg_root);
    create_source_tree(root);
    printf("Random Number Seed: %u\n", seed);
    return 0;
}
Example #5
0
network::network(const size_t number_oscillators, const conn_type connection_type) {
    m_num_osc = number_oscillators;
    m_conn_type = connection_type;

    /* calculate height and width for networks with grid structure */
    if ((conn_type::GRID_EIGHT == connection_type) ||
            (conn_type::GRID_FOUR == connection_type)) {

        const double conv_side_size = std::sqrt((double)number_oscillators);
        if (conv_side_size - std::floor(conv_side_size) > 0) {
            throw std::runtime_error("Invalid number of oscillators in the network for the grid structure");
        }

        m_height = (size_t)conv_side_size;
        m_width = (size_t)conv_side_size;
    }
    else {
        /* in case of non-grid structures height and width are ignored */
        m_height = 0;
        m_width = 0;
    }

    create_structure();
}
Example #6
0
/* *** create the initial structures and agents using the following code in the Model constructor.
Do not change the order of these statements. You should delete this comment. */

	add_structure(create_structure("Rivendale", "Farm", Point(10., 10.)));
	add_structure(create_structure("Sunnybrook", "Farm", Point(0., 30.)));
	add_structure(create_structure("Shire", "Town_Hall", Point(20., 20.)));
	add_structure(create_structure("Paduca", "Town_Hall", Point(30., 30.)));
	
	add_agent(create_agent("Pippin", "Peasant", Point(5., 10.)));
	add_agent(create_agent("Merry", "Peasant", Point(0., 25.)));
	add_agent(create_agent("Zug", "Soldier", Point(20., 30.)));
	add_agent(create_agent("Bug", "Soldier", Point(15., 20.)));

Example #7
0
File: main.c Project: VEROS/VEROS
/* --------------------------------------------------------------------------
 *  start_thread
 *
 *  ARM start thread function
 *
 *  @param	: cyg_addrword_t data
 *  @return	: void
 *  @see	: fpga, parse, create_structure, exti_thread, led_thread
 *
 *  Process:
 *    01. Refresh FPGA;
 *    02. Configure GPIO register;
 *    03. Configure EXTI register;
 *    04. Parse binary file;
 *    05. Create data structure;
 *    06. Attach interrupt;
 *    07. Report device address and data.
 * --------------------------------------------------------------------------
 */
void start_thread(cyg_addrword_t data)
{
	HAL_WRITE_UINT32(CYGARC_REG_SYSTICK_BASE+CYGARC_REG_SYSTICK_RELOAD, 2099 ); 

	cyg_tick_count_t aticks = cyg_current_time();
	if (fpga() == 0)
	{
#ifdef MVBPROJ_BASIC_INFO_SUPPORT
		printf("FPGA init :: ERROR :: ARM STOP\n");
#endif // ifdef MVBPROJ_BASIC_INFO_SUPPORT
		cyg_thread_exit();
	}
	
	cyg_tick_count_t bticks = cyg_current_time();
	UNSIGNED32 time = ((UNSIGNED32)bticks - (UNSIGNED32)aticks) / 10;
	printf("FPGA init :: PROGRAMMING TIME :: %d ms\n", time);

#ifdef MVBPROJ_BASIC_INFO_SUPPORT
	printf("...configuring GPIO...\n");
#endif // ifdef MVBPROJ_BASIC_INFO_SUPPORT
	mvb_arm_init_all_gpio();
	
#ifdef MVBPROJ_BASIC_INFO_SUPPORT
	printf("...configuring EXTI...\n");
#endif // ifdef MVBPROJ_BASIC_INFO_SUPPORT
	mvb_arm_init_exti();

	cyg_thread_create(EXTI_WORKTHREAD_PRI, exti_thread, 0, "EXTI CONFIGURATION", &exti_stack, STACK_SIZE, &exti_thread_handle, &exti_thread_data);
	
	aticks = cyg_current_time();
	if (parse() == 0)
	{
#ifdef MVBPROJ_BASIC_INFO_SUPPORT
		printf("Binary init :: ERROR :: Parsing error, no config data.\n");
#endif // ifdef MVBPROJ_BASIC_INFO_SUPPORT
	}
	bticks = cyg_current_time();
	time = ((UNSIGNED32)bticks - (UNSIGNED32)aticks) / 10;
	printf("Binary init :: ELAPSED TIME :: %d ms\n", time);
	
#ifdef MVBPROJ_BASIC_INFO_SUPPORT
	printf("...creating data structure...\n");
#endif // ifdef MVBPROJ_BASIC_INFO_SUPPORT
	create_structure();

#ifdef MVBPROJ_BASIC_INFO_SUPPORT
	printf("...attaching interrupt...\n");
#endif // ifdef MVBPROJ_BASIC_INFO_SUPPORT

#ifdef MVBPROJ_LED_SUPPORT
	cyg_thread_create(LED_WORKTHREAD_PRI, led_thread, 0, "LED SUPPORT", &led_stack, STACK_SIZE, &led_thread_handle, &led_thread_data);
#endif // ifdef MVBPROJ_LED_SUPPORT

    cyg_thread_resume(exti_thread_handle); // Start it

#ifdef MVBPROJ_LED_SUPPORT
	cyg_thread_resume(led_thread_handle);
#endif // ifdef MVBPROJ_LED_SUPPORT

	cyg_thread_exit();
}