Beispiel #1
0
bool process_component_statements(evl_components &components, evl_statement &s, evl_wires &wires, evl_checkpoints &check) {
	//assert(s.type == evl_statement::COMPONENT);

	enum state_type {INIT, TYPE, NAME, PINS, PIN_NAME, PINS_DONE, BUS, BUS_MSB, BUS_COLON, BUS_LSB, BUS_DONE, DONE};
	
	std::string comp_type = "";
	std::string comp_name = "NONE";
	std::string pin_name = "";
	int bus_msb = -1;
	int bus_lsb = -1;
	int count = 0;
	int count_2;
	state_type state = INIT;

	for(; !s.tokens.empty() && (state != DONE); s.tokens.pop_front()){
		evl_token t = s.tokens.front();
		
		if (state == INIT) {
			if(t.type == evl_token::NAME) {
				comp_type = t.str;
				state = TYPE;
			}
		    else {
				state = TYPE;				
			}
		}
		else if (state == TYPE){
			if (t.type == evl_token::SINGLE && t.str == "(") {
				state = PINS;
			}
			else {
				std::cerr << "Need a NAME or a '(' but found '" << t.str << "' at line " << t.line_no << std::endl;
				return false;
			}
			evl_component component;
			component.type = comp_type;
			component.name = comp_name;
			components.push_back(component);
		
			count_2 = 0;

		}
		else if (state == PINS) {
			//int count = 0;
			if (t.type == evl_token::NAME) {
				evl_wires::iterator it = wires.find(t.str);
				if (it == wires.end()) {
					std::cerr << "Wire '" << t.str << "' on line " << t.line_no << " is not defined" << std::endl;
					return false;
				}
				count = it->second + count_2;
				it->second = ++count;
				pin_name = t.str;
			}
			state = PIN_NAME;			
		}
		else if (state == PIN_NAME) {
			bus_msb = -1;
			bus_lsb = -1;
			//int count = 0;
			if (t.str == ")"){
				evl_wires::iterator it = wires.find(pin_name);
				count = it->second + count_2;
				it->second = ++count; 
				//if (it->second >= 2) {
				//	bus_msb = it->second-1;
				//	bus_lsb = 0;
				//}
				evl_pin pins;
				pins.lsb = bus_lsb;
				pins.msb = bus_msb;
				pins.pin_name = pin_name;
							
				components.back().comp_pins.push_back(pins);
				
				state = DONE;
			}
			else if (t.str == ","){
				evl_wires::iterator it = wires.find(pin_name);
				//if (it->second >= 2) {
				//	bus_msb = it->second-1;
				//	bus_lsb = 0;
				//}
				count = it->second + count_2;
				it->second = ++count; 
				evl_pin pins;			
				pins.lsb = bus_lsb;
				pins.msb = bus_msb;
				pins.pin_name = pin_name;	

				components.back().comp_pins.push_back(pins);
				
				state = PINS;
			}
			else { 
				std::cerr << "Need ',' or ')' or '[' but found '" << t.str << "' on line " << t.line_no <<std::endl;
				return false;
			}
		}
		else {
			assert(false); //never should get here
		}
	}
	if (!s.tokens.empty() || (state != DONE)) {
		std::cerr << "something wrong with the statement in Comp" << std::endl;
		return false;
	}

	return true;
}
bool process_component_statements(evl_components &components, evl_statement &s, const evl_wires &wires) {
	assert(s.type == evl_statement::COMPONENT);

	enum state_type {INIT, TYPE, NAME, PINS, PIN_NAME, PINS_DONE, BUS, BUS_MSB, BUS_COLON, BUS_LSB, BUS_DONE, DONE};
	
	std::string comp_type = "";
	std::string comp_name = "NONE";
	std::string pin_name = "";
	int bus_msb = -1;
	int bus_lsb = -1;

	state_type state = INIT;
	
	for(; !s.tokens.empty() && (state != DONE); s.tokens.pop_front()){
		evl_token t = s.tokens.front();
		
		if (state == INIT) {
			if(t.type == evl_token::NAME) {
				comp_type = t.str;
				state = TYPE;
			}
		    else {
				state = TYPE;				
			}
		}
		else if (state == TYPE){
			if (t.type == evl_token::NAME) {
				comp_name = t.str;
				state = NAME;
			}
			else if (t.type == evl_token::SINGLE && t.str == "(") {
				state = PINS;
			}
			else {
				std::cerr << "Need a NAME or a '(' but found '" << t.str << "' at line " << t.line_no << std::endl;
				return false;
			}
			evl_component component;
			component.type = comp_type;
			component.name = comp_name;
			components.push_back(component);
			
		}
		else if (state == NAME) {
			if (t.type == evl_token::SINGLE &&  t.str == "("){
				state = PINS;
			}
			else {
				std::cerr << "Need '(' but found '" << t.str << "' at line " << t.line_no << std::endl;
				return false;
			}
		}
		else if (state == PINS) {
			
			if (t.type == evl_token::NAME) {
				evl_wires::const_iterator it = wires.find(t.str);
				if (it == wires.end()) {
					std::cerr << "Wire '" << t.str << "' on line " << t.line_no << " is not defined" << std::endl;
					return false;
				}
				pin_name = t.str;
			}
			state = PIN_NAME;			
		}
		else if (state == PIN_NAME) {
			bus_msb = -1;
			bus_lsb = -1;

			if (t.str == ")"){
				

				evl_wires::const_iterator it = wires.find(pin_name);
				if (it->second >= 2) {
					bus_msb = it->second-1;
					bus_lsb = 0;
				}
				evl_pin pins;
				pins.lsb = bus_lsb;
				pins.msb = bus_msb;
				pins.pin_name = pin_name;
				
				components.back().comp_pins.push_back(pins);
							
				state = PINS_DONE;
			}
			else if (t.str == ","){
				evl_wires::const_iterator it = wires.find(pin_name);
				if (it->second >= 2) {
					bus_msb = it->second-1;
					bus_lsb = 0;
				}
				
				evl_pin pins;			
				pins.lsb = bus_lsb;
				pins.msb = bus_msb;
				pins.pin_name = pin_name;
				
				components.back().comp_pins.push_back(pins);
				
				state = PINS;
			}
			else if (t.str == "[") {
				state = BUS;
			}
			else { 
				std::cerr << "Need ',' or ')' or '[' but found '" << t.str << "' on line " << t.line_no <<std::endl;
				return false;
			}
		}
		else if (state == BUS) {
			if(t.type == evl_token::NUMBER) {
				bus_msb = atoi(t.str.c_str());
			}
			else {
				std::cerr << "Need 'number' but found '" << t.str << "' on line " << t.line_no << std::endl;
				return false;
			}
			state = BUS_MSB;
		}
		else if (state == BUS_MSB) {
			if (t.str == "]") {
				evl_wires::const_iterator it = wires.find(pin_name);
				int found_wire_msb = it->second-1;
				
				if (bus_msb > found_wire_msb){
					std::cerr << "Bus MSB of value: " << bus_msb << " must be greater than or equal to the wire bus msb of value: " << found_wire_msb << std::endl;
					return false;
				}
				if (bus_msb < 0) {
					std::cerr << "Bus MSB of value: " << bus_msb << " must be greater than 0." << std::cout;
				}
				bus_lsb = bus_msb;
				state = BUS_DONE;
			}
			else if (t.str == ":") {
				state = BUS_COLON;
			}
			else {
				std::cerr << "Need ']' or ':' but found '" << t.str << "' on line " << t.line_no <<std::endl;
				return false;
			}
		}
		else if (state == BUS_COLON) {
			evl_wires::const_iterator it = wires.find(pin_name);
			int found_wire_msb = it->second-1;

			if (t.type == evl_token::NUMBER) {
				bus_lsb = atoi(t.str.c_str());
			}
			else {
				std::cerr << "Need 'number' but found '" << t.str << "' on line " << t.line_no << std::endl;
				return false;
			}
			if (bus_msb < bus_lsb) {
				std::cerr << "Bus msb: " << bus_msb << " can not be less than Bus lsb " << bus_lsb << std::endl;
				return false;
			}
			if (bus_msb > found_wire_msb) {
				std::cerr << "Bus msb is: " << bus_msb << ". Needs to less than or equal to  wire bus msb: " << found_wire_msb << std::endl;
				return false;
			}
			if (bus_lsb < 0) {
				std::cerr << "Bus lsb is: " << bus_lsb << ". Needs to be greater than 0" << std::endl;
				return false;
			}
			
			state = BUS_LSB;
		}
		else if (state == BUS_LSB) {
			if (!(t.str == "]")) {
				std::cerr << "Need ']' but found '" << t.str << "' on line " << t.line_no << std::endl;
				return false;
			}
			state = BUS_DONE;
		}
		else if (state == BUS_DONE) {
			if (t.str == ")") {
				evl_pin pins;
				pins.lsb = bus_lsb;
				pins.msb = bus_msb;
				pins.pin_name = pin_name;

				components.back().comp_pins.push_back(pins);
				state = PINS_DONE;
			}
			else if (t.str == ",") {
				
				evl_pin pins;			
				pins.lsb = bus_lsb;
				pins.msb = bus_msb;
				pins.pin_name = pin_name;
				
				components.back().comp_pins.push_back(pins);
				
				state = PINS;
			}
		}

		else if (state == PINS_DONE) {
			if (t.str == ";") {
				state = DONE;
			}
			else {
				std::cerr << "Need ';' but found '" << t.str << "' on line " << t.line_no << std::endl;
				return false;
			}
		}
		else {
			assert(false); //never should get here
		}
	}
	if (!s.tokens.empty() || (state != DONE)) {
		std::cerr << "something wrong with the statement in Comp" << std::endl;
		return false;
	}

	return true;
}