bool group_tokens_into_statements(evl_statements &statements, evl_tokens &tokens) { for (; !tokens.empty();) { // generate one statement per iteration evl_token token = tokens.front(); 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); } //ASSIGN statement else if (token.str == "assign"){ evl_statement assign; assign.type = evl_statement::ASSIGN; if (!move_tokens_to_statement(assign.tokens, tokens)) return false; statements.push_back(assign); } 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; }
//Re-order statements so order is MODULE,WIRES,COMPONENTS,ENDMODULE,...repeat bool reorder_statements_list (evl_statements::const_iterator m_itr, evl_statements &statements){ m_itr = statements.begin(); for(evl_statements::const_iterator it = statements.begin(); it != statements.end(); ++it) { if (it->type == evl_statement::WIRE) { statements.insert(++m_itr,*it); m_itr--; it = statements.erase(it); //--it; } } 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; }
void display_statements(std::ostream &out, const evl_statements &statements) { int count = 1; for (evl_statements::const_iterator iter = statements.begin(); iter != statements.end(); ++iter) { if (iter->type == evl_statement::MODULE) { out << "STATEMENT " << count << " MODULE, " << iter->tokens.size() << " tokens" << std::endl; } else if (iter->type == evl_statement::WIRE) { out << "STATEMENT " << count << " WIRE, " << iter->tokens.size() << " tokens" << std::endl; } else if (iter->type == evl_statement::COMPONENT) { out << "STATEMENT " << count << " COMPONENT, " << iter->tokens.size() << " tokens" << std::endl; } else if (iter->type == evl_statement::ENDMODULE) { out << "STATEMENT " << count << " ENDMODULE" << std::endl; } else { out << "ERROR" << std::endl; } count++; } }