示例#1
0
        public void write_blif(string filename)
        {
            StreamWriter outfile = new StreamWriter(filename);

            outfile.WriteLine(".model " + this.name);

            outfile.Write(".inputs");
            for (int i = 0; i < primary_inputs.size(); ++i)
            {
                outfile.Write(" " + node(primary_inputs[i]).name);
            }
            outfile.WriteLine();

            outfile.Write(".outputs");
            for (int i = 0; i < primary_outputs.size(); ++i)
            {
                outfile.Write(" " + node(primary_outputs[i]).name);
            }
            outfile.WriteLine();

            for (int i = 0; i < latches.size(); ++i)
            {
                Gate n = node(latches[i]);
                outfile.WriteLine(".latch " + node(n.fanins[0]).name + " " + n.name + " " + (int)n.latch_default);
            }
            for (int i = 0; i < combs.size(); ++i)
            {
                Gate n = node(combs[i]);
                outfile.Write(".names");
                for (int j = 0; j < n.fanins.size(); ++j)
                {
                    outfile.Write(" " + node(n.fanins[j]).name);
                }
                outfile.WriteLine(" " + n.name);
                if (n.gate_type == EGateType.G_NOT)
                {
                    outfile.WriteLine("0 1");
                }
                else if (n.gate_type == EGateType.G_AND_11)
                {
                    outfile.WriteLine("11 1");
                }
                else if (n.gate_type == EGateType.G_AND_10)
                {
                    outfile.WriteLine("10 1");
                }
                else if (n.gate_type == EGateType.G_AND_01)
                {
                    outfile.WriteLine("01 1");
                }
                else if (n.gate_type == EGateType.G_AND_00)
                {
                    outfile.WriteLine("00 1");
                }
                else if (n.gate_type == EGateType.G_OR_11)
                {
                    outfile.WriteLine("1- 1" + '\n' + "-1 1");
                }
                else if (n.gate_type == EGateType.G_OR_10)
                {
                    outfile.WriteLine("1- 1" + '\n' + "-0 1");
                }
                else if (n.gate_type == EGateType.G_OR_01)
                {
                    outfile.WriteLine("0- 1" + '\n' + "-1 1");
                }
                else if (n.gate_type == EGateType.G_OR_00)
                {
                    outfile.WriteLine("0- 1" + '\n' + "-0 1");
                }
//              else if (n.gate_type == EGateType.G_EQUAL)
//                  outfile.WriteLine ( "11 1" + '\n' + "00 1" );
                else if (n.gate_type == EGateType.G_CONST_1)
                {
                    outfile.WriteLine("1 1" + '\n' + "0 1");
                }
                else if (n.gate_type == EGateType.G_WIRE)
                {
                    outfile.WriteLine("1 1" + '\n' + "0 0");
                }
                else
                {
                    fatal("Unknown gate type");
                }
            }
            outfile.WriteLine(".end");
            outfile.Close();
        }
示例#2
0
        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();
        }