bool group_tokens_into_statements(evl_statements &statements, evl_tokens &tokens) { assert(statements.empty()); for(; !tokens.empty();) { //generates one statement per iteration evl_token token = tokens.front(); if (token.type != evl_token::NAME) { std::cerr << "Need a NAME token but found '" << token.str << "' on line" << token.line_no << std::endl; return false; } if (token.str == "module") { //MODULE statement evl_statement module; module.type = evl_statement::MODULE; if(!move_tokens_to_statement(module.tokens, tokens)){ return false; } statements.push_back(module); } else if (token.str == "endmodule") { //ENDMODULE statement evl_statement endmodule; endmodule.type = evl_statement::ENDMODULE; endmodule.tokens.push_back(token); tokens.erase(tokens.begin()); statements.push_back(endmodule); } else if (token.str == "wire") { //WIRE statement evl_statement wire; wire.type = evl_statement::WIRE; if(!move_tokens_to_statement(wire.tokens, tokens)){ return false; } statements.push_back(wire); } else { //COMPONENT statement evl_statement component; component.type = evl_statement::COMPONENT; if(!move_tokens_to_statement(component.tokens, tokens)){ return false; } statements.push_back(component); } } return true; }
bool process_all_statements(evl_statements &statements, evl_module &module, evl_wires &wires, evl_components &components, evl_endmodule &endmodule) { for (; !statements.empty(); statements.pop_front()) { if ((statements.front().type) == (evl_statement::MODULE)) { if (!process_module_statement(module, statements.front())) { std::cerr << "Wrong MODULE statement when store in Object" << std::endl; return false; } } else if ((statements.front().type) == (evl_statement::WIRE)) { if (!process_wire_statement(wires, statements.front())) { std::cerr << "Wrong WIRE statement when store in Object" << std::endl; return false; } } else if ((statements.front().type) == (evl_statement::COMPONENT)) { if (!process_component_statement(components, statements.front())) { std::cerr << "Wrong COMPONENTS statement when store in Object" << std::endl; return false; } } else if ((statements.front().type) == (evl_statement::ENDMODULE)) { if (!process_endmodule_statement(endmodule, statements.front())) { std::cerr << "Wrong ENDMODULE statement when store in Object" << std::endl; return false; } } else { std::cerr << "Wrong Statmement Type" << std::endl; return false; } } return true; }
bool group_tokens_into_statements(evl_statements &statements, evl_tokens &tokens) { assert(statements.empty()); for(; !tokens.empty();) { //generates one statement per iteration evl_token token = tokens.front(); if (token.type != evl_token::NAME) { std::cerr << "Need a NAME token but found '" << token.str << "' on line" << token.line_no << std::endl; return false; } if ((token.str == "INPUT") || (token.str == "OUTPUT") || (token.str == "AND") || (token.str == "NAND") || (token.str == "OR") || (token.str == "NOR") || (token.str == "DFF") || (token.str == "NOT")) { evl_statement component; component.type = evl_statement::COMPONENT; if(!move_comp_to_statement(component.tokens, tokens)) { return false; } //INPUT and OUTPUT are both components and wires; if ((token.str == "INPUT") || (token.str == "OUTPUT")) { evl_statement wire; wire.type = evl_statement::WIRE; wire.tokens = component.tokens; statements.push_back(wire); } statements.push_back(component); } else { evl_statement wire; wire.type = evl_statement::WIRE; if(!move_wire_to_statement(wire.tokens, tokens)) { return false; } statements.push_back(wire); } } return true; }