Exemplo n.º 1
0
        public static VCD_Variable Parse(string[] Words)
        {
            VCD_Variable var = new VCD_Variable();

            // var.var_type
            switch (Words[1].ToLower())
            {
            case "event": var.var_type = VCDVariableType.Event; break;

            case "integer": var.var_type = VCDVariableType.Integer; break;

            case "parameter": var.var_type = VCDVariableType.Parameter; break;

            case "real": var.var_type = VCDVariableType.Real; break;

            case "reg": var.var_type = VCDVariableType.Reg; break;

            case "supply0": var.var_type = VCDVariableType.Supply0; break;

            case "supply1": var.var_type = VCDVariableType.Supply1; break;

            case "time": var.var_type = VCDVariableType.Time; break;

            case "tri": var.var_type = VCDVariableType.Tri; break;

            case "triand": var.var_type = VCDVariableType.Triand; break;

            case "trior": var.var_type = VCDVariableType.Trior; break;

            case "trireg": var.var_type = VCDVariableType.Trireg; break;

            case "tri0": var.var_type = VCDVariableType.Tri0; break;

            case "tri1": var.var_type = VCDVariableType.Tri1; break;

            case "wand": var.var_type = VCDVariableType.Wand; break;

            case "wire": var.var_type = VCDVariableType.Wire; break;

            case "wor": var.var_type = VCDVariableType.Wor; break;
            }

            var.size       = uint.Parse(Words[2]);
            var.identifier = Words[3];

            //Если встераем сложное имя переменной с учетом ее размерности
            if ((var.size != 1))
            {
                if (Words[4].Contains(":"))
                {
                    string[] temp = Words[4].Split(new char[] { ' ', '[', ']', ':' });
                    var.reference = temp[0];
                    bool parse_res = int.TryParse(temp[1], out var.startIndex);
                    parse_res = int.TryParse(temp[2], out var.endIndex);
                }
                else
                {
                    var.reference  = Words[4];
                    var.endIndex   = (int)var.size - 1;
                    var.startIndex = 0;
                }
            }
            else
            {
                var.reference = Words[4];
            }

            switch (var.VariableType)
            {
            case VCD_Variable.VCDVariableType.Integer:
                var.base_variable  = TypeCreator.CreateSignal(var.Reference, VHDL.builtin.Standard.INTEGER);
                var.appendFunction = VCDConvertor.Append_Integer_VALUE;
                break;

            case VCD_Variable.VCDVariableType.Real:
                var.base_variable  = TypeCreator.CreateSignal(var.Reference, VHDL.builtin.Standard.REAL);
                var.appendFunction = VCDConvertor.Append_Real_VALUE;
                break;

            case VCD_Variable.VCDVariableType.Time:
                break;

            case VCD_Variable.VCDVariableType.Event:
            case VCD_Variable.VCDVariableType.Parameter:
            case VCD_Variable.VCDVariableType.Reg:
            case VCD_Variable.VCDVariableType.Supply0:
            case VCD_Variable.VCDVariableType.Supply1:
            case VCD_Variable.VCDVariableType.Tri:
            case VCD_Variable.VCDVariableType.Tri0:
            case VCD_Variable.VCDVariableType.Tri1:
            case VCD_Variable.VCDVariableType.Triand:
            case VCD_Variable.VCDVariableType.Trior:
            case VCD_Variable.VCDVariableType.Trireg:
            case VCD_Variable.VCDVariableType.Wand:
            case VCD_Variable.VCDVariableType.Wire:
            case VCD_Variable.VCDVariableType.Wor:
            {
                if (var.Size == 1)
                {
                    var.base_variable  = TypeCreator.CreateSignal(var.Reference, VHDL.builtin.StdLogic1164.STD_ULOGIC);
                    var.appendFunction = VCDConvertor.Append_STD_ULOGIC_VALUE;
                }
                else
                {
                    ResolvedDiscreteRange        range     = ResolvedDiscreteRange.FormIntegerIndexes(var.StartIndex, var.EndIndex);
                    VHDL.type.ISubtypeIndication arrayType = VHDL.builtin.StdLogic1164.Create_STD_ULOGIC_VECTOR(new Range(range.From, (range.RangeDirection == RangeDirection.To)?Range.RangeDirection.TO:Range.RangeDirection.DOWNTO, range.To));
                    var.base_variable  = TypeCreator.CreateSignal(var.Reference, arrayType);
                    var.appendFunction = VCDConvertor.Append_STD_ULOGIC_VECTOR_VALUE;
                }
            }
            break;
            }

            return(var);
        }