Gate create_latch(string latch_in, string latch_out, ELatchDefault deft) { Gate n; if ((n = find_node_by_name(latch_out)) == null) { n = new_node(latch_out); } //int id = n.index; sharp_assert(n.fanin_names.empty()); n.fanin_names.push_back(latch_in); n.latch_default = deft; n.set_LATCH(); return(n); }
public void read_blif(string filename) { StreamReader input = null; ObjVector lines = new ObjVector(128); try { input = new StreamReader(filename); } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); fatal(); } while (true) { string line = get_multiple_line(input); if (line == null) { break; } lines.push_back(line); if (line == ".end") { break; } } for (int i = 0; i < lines.size(); ++i) { string line = (string)lines[i]; string [] temp_tokens = line.Split(new char[] { ' ', '\t' }); int total_tokens = 0; foreach (string str in temp_tokens) { if (str != String.Empty) { ++total_tokens; } } if (total_tokens == 0) { continue; } string [] tokens = new string[total_tokens]; foreach (string str in temp_tokens) { if (str != String.Empty) { tokens[tokens.Length - total_tokens] = str; --total_tokens; } } string first_token = tokens[0]; if (first_token == ".model") { this.name = tokens[1]; } else if (first_token == ".inputs") { for (int k = 1; k < tokens.Length; ++k) { create_pi(tokens[k]); } } else if (first_token == ".outputs") { for (int k = 1; k < tokens.Length; ++k) { create_po(tokens[k]); } } else if (first_token == ".latch") { sharp_assert(tokens.Length == 3 || tokens.Length == 4); ELatchDefault dft_v = ELatchDefault.LATCH_X; if (tokens.Length == 4) { string last_token = tokens[3]; sharp_assert(last_token.Length == 1); dft_v = (ELatchDefault)Int32.Parse(last_token); } create_latch(tokens[1], tokens[2], dft_v); } else if (first_token == ".names") { string [] inputs = new string [tokens.Length - 2]; sharp_assert(inputs.Length == 1 || inputs.Length == 2); string name = tokens[tokens.Length - 1]; for (int k = 1; k < tokens.Length - 1; ++k) { inputs[k - 1] = tokens[k]; } Gate node = create_comb(name, inputs); if ((string)lines[i + 1] == "1 1" && (string)lines[i + 2] == "0 1") { node.gate_type = EGateType.G_CONST_1; i += 2; } else if ((string)lines[i + 1] == "1 1") { warning("A gate is a wire, sweep first "); node.gate_type = EGateType.G_WIRE; ++i; } else if ((string)lines[i + 1] == "0 1") { node.gate_type = EGateType.G_NOT; ++i; } else if ((string)lines[i + 1] == "11 1") { node.gate_type = EGateType.G_AND_11; ++i; } else if ((string)lines[i + 1] == "10 1") { node.gate_type = EGateType.G_AND_10; ++i; } else if ((string)lines[i + 1] == "01 1") { node.gate_type = EGateType.G_AND_01; ++i; } else if ((string)lines[i + 1] == "00 1") { node.gate_type = EGateType.G_AND_00; ++i; } else if ((string)lines[i + 1] == "0- 1" && (string)lines[i + 2] == "-0 1") { node.gate_type = EGateType.G_OR_00; i += 2; } else if ((string)lines[i + 1] == "0- 1" && (string)lines[i + 2] == "-1 1") { node.gate_type = EGateType.G_OR_01; i += 2; } else if ((string)lines[i + 1] == "1- 1" && (string)lines[i + 2] == "-0 1") { node.gate_type = EGateType.G_OR_10; i += 2; } else if ((string)lines[i + 1] == "1- 1" && (string)lines[i + 2] == "-1 1") { node.gate_type = EGateType.G_OR_11; i += 2; } else { fatal("Don't know gate type for " + line); } sharp_assert(((string)lines[i + 1])[0] == '.'); } else if (first_token == ".end") { break; } else if (first_token == ".wire_load_slope") { warning("Warning: Ignoring " + first_token); } else if (first_token[0] == '.') { fatal(first_token + ": Unable to handle this keyword"); } } finalize_construct_network(); }