public bool NextDefaultValue(out RawDefaultValue defaultValue)
        {
            if (RawDefaultValues.Count == 0)
            {
                defaultValue = null;
                return(false);
            }

            defaultValue = RawDefaultValues.Dequeue();
            return(true);
        }
Beispiel #2
0
        public override void WriteText(Cosmos.Assembler.Assembler aAssembler, TextWriter aOutput)
        {
            if (RawAsm != null)
            {
                aOutput.WriteLine(RawAsm);
                return;
            }

            if (RawDefaultValue != null)
            {
                if (RawDefaultValue.Length == 0)
                {
                    aOutput.Write(Name);
                    aOutput.Write(":");
                    return;
                }
                if ((from item in RawDefaultValue
                     group item by item
                     into i
                     select i).Count() > 1 || RawDefaultValue.Length < 250)
                {
                    if (IsGlobal)
                    {
                        aOutput.Write("global ");
                        aOutput.WriteLine(Name);
                    }
                    aOutput.Write(Name);
                    aOutput.Write(" db ");
                    for (int i = 0; i < (RawDefaultValue.Length - 1); i++)
                    {
                        aOutput.Write(RawDefaultValue[i]);
                        aOutput.Write(", ");
                    }
                    aOutput.Write(RawDefaultValue.Last());
                }
                else
                {
                    //aOutputWriter.WriteLine("TIMES 0x50000 db 0");
                    aOutput.Write("global ");
                    aOutput.WriteLine(Name);
                    aOutput.Write(Name);
                    aOutput.Write(": TIMES ");
                    aOutput.Write(RawDefaultValue.Length);
                    aOutput.Write(" db ");
                    aOutput.Write(RawDefaultValue[0]);
                }
                return;
            }
            if (UntypedDefaultValue != null)
            {
                StringBuilder xSB = new StringBuilder();
                if (IsGlobal)
                {
                    aOutput.Write("global ");
                    aOutput.WriteLine(Name);
                }
                aOutput.Write(Name);
                aOutput.Write(" dd ");
                Func <object, string> xGetTextForItem = delegate(object aItem) {
                    var xElementRef = aItem as Cosmos.Assembler.ElementReference;
                    if (xElementRef == null)
                    {
                        return((aItem ?? 0).ToString());
                    }
                    else
                    {
                        if (xElementRef.Offset == 0)
                        {
                            return(xElementRef.Name);
                        }
                        return(xElementRef.Name + " + " + xElementRef.Offset);
                    }
                };
                for (int i = 0; i < (UntypedDefaultValue.Length - 1); i++)
                {
                    aOutput.Write(xGetTextForItem(UntypedDefaultValue[i]));
                    aOutput.Write(", ");
                }
                aOutput.Write(xGetTextForItem(UntypedDefaultValue.Last()));
                return;
            }
            throw new Exception("Situation unsupported!");
        }
        public JSONGraphFileReader(string json)
        {
            RawNodes         = new Queue <RawNode>();
            RawEdges         = new Queue <RawEdge>();
            RawDefaultValues = new Queue <RawDefaultValue>();

            // Load graph
            ParsedJSON = (Dictionary <string, object>)fastJSON.JSON.Parse(json);
            Nodes      = (Dictionary <string, object>)ParsedJSON["processes"];
            Edges      = (List <object>)ParsedJSON["connections"];

            foreach (string componentName in Nodes.Keys)
            {
                Details = (Dictionary <string, object>)Nodes[componentName];

                RawNode node = new RawNode()
                {
                    Name = componentName,
                    QualifiedComponentName = Details["component"] as string,
                };
                RawNodes.Enqueue(node);

                if (Details.ContainsKey("metadata"))
                {
                    metadata = (Dictionary <string, object>)Details["metadata"];

                    if (metadata.ContainsKey("x") && metadata.ContainsKey("y"))
                    {
                        float x = 0, y = 0;

                        object X = metadata["x"];
                        switch (X.GetType().Name)
                        {
                        case "Double":
                            x = (float)(double)X;
                            break;

                        case "Int64":
                            x = (float)(Int64)X;
                            break;

                        default:
                            throw new Exception("Uknown number type found: " + X.GetType().Name);
                        }

                        object Y = metadata["y"];
                        switch (Y.GetType().Name)
                        {
                        case "Double":
                            y = (float)(double)Y;
                            break;

                        case "Int64":
                            y = (float)(Int64)Y;
                            break;

                        default:
                            throw new Exception("Uknown number type found: " + Y.GetType().Name);
                        }

                        node.metadataPosition = new Vector3(x, y);
                    }
                }
            }

            for (int i = 0; i < Edges.Count; i++)
            {
                Details = (Dictionary <string, object>)Edges[i];

                tgt = (Dictionary <string, object>)Details["tgt"];
                if (Details.ContainsKey("src"))
                {
                    Dictionary <string, object> src = (Dictionary <string, object>)Details["src"];

                    RawEdge edge = new RawEdge()
                    {
                        srcProcess = src["process"] as string,
                        srcPort    = src["port"] as string,
                        tgtProcess = tgt["process"] as string,
                        tgtPort    = tgt["port"] as string,
                    };

                    RawEdges.Enqueue(edge);
                }
                else if (Details.ContainsKey("data"))
                {
                    RawDefaultValue defaultValue = new RawDefaultValue()
                    {
                        Data       = Details["data"],
                        tgtProcess = tgt["process"] as string,
                        tgtPort    = tgt["port"] as string,
                    };

                    RawDefaultValues.Enqueue(defaultValue);
                }
            }
        }
Beispiel #4
0
        public override void WriteText(Assembler aAssembler, TextWriter aOutput)
        {
            if (RawAsm != null)
            {
                aOutput.WriteLine(RawAsm);
                return;
            }

            if (RawDefaultValue != null)
            {
                if (RawDefaultValue.Length == 0)
                {
                    aOutput.Write(Name);
                    aOutput.Write(":");
                    return;
                }
                if (RawDefaultValue.Length < 250 ||
                    (from item in RawDefaultValue
                     group item by item
                     into i
                     select i).Count() > 1)
                {
                    if (IsGlobal)
                    {
                        aOutput.Write("\tglobal ");
                        aOutput.WriteLine(Name);

                        if (AdditionalNames != null && AdditionalNames.Count() > 0)
                        {
                            foreach (var xName in AdditionalNames)
                            {
                                aOutput.Write("\tglobal");
                                aOutput.WriteLine(xName);
                            }
                        }
                    }

                    aOutput.WriteLine(Name + ":");

                    if (AdditionalNames != null && AdditionalNames.Count() > 0)
                    {
                        foreach (var xName in AdditionalNames)
                        {
                            aOutput.WriteLine("\t" + xName + ":");
                        }
                    }

                    aOutput.Write("\t  db ");
                    for (int i = 0; i < (RawDefaultValue.Length - 1); i++)
                    {
                        aOutput.Write(RawDefaultValue[i]);
                        aOutput.Write(", ");
                    }
                    aOutput.Write(RawDefaultValue.Last());
                }
                else
                {
                    if (IsGlobal)
                    {
                        aOutput.Write("global ");
                        aOutput.WriteLine(Name);

                        if (AdditionalNames != null && AdditionalNames.Count() > 0)
                        {
                            foreach (var xName in AdditionalNames)
                            {
                                aOutput.Write("\tglobal");
                                aOutput.WriteLine(xName);
                            }
                        }
                    }

                    if (AdditionalNames != null && AdditionalNames.Count() > 0)
                    {
                        aOutput.WriteLine(Name + ":");
                        foreach (var xName in AdditionalNames)
                        {
                            aOutput.WriteLine("\t" + xName + ":");
                        }
                    }
                    else
                    {
                        aOutput.Write(Name + ":");
                    }

                    aOutput.Write("\t  TIMES ");
                    aOutput.Write(RawDefaultValue.Length);
                    aOutput.Write(" db ");
                    aOutput.Write(RawDefaultValue[0]);
                }
                return;
            }
            if (UntypedDefaultValue != null)
            {
                if (IsGlobal)
                {
                    aOutput.Write("global ");
                    aOutput.WriteLine(Name);
                }
                aOutput.Write(Name);

                aOutput.Write(" " + GetStringFromType(UntypedDefaultValue[0].GetType()) + " ");

                Func <object, string> xGetTextForItem = delegate(object aItem)
                {
                    if (!(aItem is ElementReference xElementRef))
                    {
                        return((aItem ?? 0).ToString());
                    }

                    if (xElementRef.Offset == 0)
                    {
                        return(xElementRef.Name);
                    }
                    return(xElementRef.Name + " + " + xElementRef.Offset);
                };
                for (int i = 0; i < (UntypedDefaultValue.Length - 1); i++)
                {
                    aOutput.Write(xGetTextForItem(UntypedDefaultValue[i]));
                    aOutput.Write(", ");
                }
                aOutput.Write(xGetTextForItem(UntypedDefaultValue.Last()));
                return;
            }

            if (StringValue != null)
            {
                if (Type != null)
                {
                    aOutput.Write(Name);
                    aOutput.Write(" ");
                    aOutput.Write(GetStringFromType(Type));
                    aOutput.Write(" ");
                    aOutput.Write(StringValue);
                }
                else if (Size != null)
                {
                    aOutput.Write(Name);
                    aOutput.Write(" ");
                    aOutput.Write(Size);
                    aOutput.Write(" ");
                    aOutput.Write(StringValue);
                }
                else
                {
                    aOutput.Write(Name);
                    aOutput.Write(" ");
                    aOutput.Write(StringValue);
                }
                return;
            }

            throw new Exception("Situation unsupported!");
        }
Beispiel #5
0
        public override void WriteText(AsmContext ec, AssemblyWriter aOutput)
        {
            if (RawAsm != null)
            {
                aOutput.WriteLine(RawAsm);
                return;
            }
            if (Labels != null)
            {
                aOutput.Write(Name);
                foreach (string lb in Labels)
                {
                    aOutput.WriteLine(" dw " + lb);
                }

                aOutput.WriteLine();
                return;
            }
            if (ReferenceName != null)
            {
                aOutput.Write(Name);
                aOutput.Write(" dw " + ReferenceName);
                aOutput.WriteLine();
                return;
            }
            if (FloatValue.HasValue)
            {
                aOutput.Write(Name);
                aOutput.Write(" dd " + FloatValue.ToString().Replace(",", "."));
                aOutput.WriteLine();
                return;
            }
            if (StrVal != null)
            {
                if (IsGlobal)
                {
                    aOutput.Write("global ");
                    aOutput.WriteLine(Name);
                }
                if (string.IsNullOrEmpty(StrVal))
                {
                    aOutput.Write(Name);
                    aOutput.Write(" times 256 db 0");
                    return;
                }
                aOutput.Write(Name);
                aOutput.Write(" db ");


                //foreach (char c in StrVal)
                //{
                //    if (c == '\r' || c == '\n')
                //    {
                //        if (!string.IsNullOrEmpty(last))
                //              strdecl+= "\"" + last + "\", ";
                //        strdecl += b[i].ToString();
                //        strdecl += ",";
                //        last = "";
                //    }
                //    else last += c + "";
                //    i++;
                //}
                //if (!string.IsNullOrEmpty(last))
                //    strdecl += "\"" + last + "\"";
                //else strdecl = strdecl.Remove(strdecl.Length - 1, 1);
                if (!verbatim)
                {
                    StringHelper.WriteNormalizedString(StrVal, aOutput);
                }
                else
                {
                    aOutput.Write("\"" + StringHelper.StringFromVerbatimLiteral(StrVal) + "\"");
                }

                if (!StrConst)
                {
                    aOutput.WriteLine();
                    aOutput.Write("\t\t  times " + (255 - StrVal.Length).ToString() + " db 0");
                }
                else
                {
                    aOutput.Write(",0");
                }
                return;
            }

            if (RawDefaultValue != null)
            {
                if (RawDefaultValue.Length == 0)
                {
                    aOutput.Write(Name);
                    aOutput.Write(":");
                    return;
                }
                if ((from item in RawDefaultValue
                     group item by item
                     into i
                     select i).Count() > 1 || RawDefaultValue.Length < 10)
                {
                    if (IsGlobal)
                    {
                        aOutput.Write("global ");
                        aOutput.WriteLine(Name);
                    }
                    aOutput.Write(Name);
                    aOutput.Write(" db ");


                    for (int i = 0; i < (RawDefaultValue.Length - 1); i++)
                    {
                        aOutput.Write(RawDefaultValue[i]);
                        aOutput.Write(", ");
                    }
                    aOutput.Write(RawDefaultValue.Last());
                }
                else
                {
                    //aOutputWriter.WriteLine("TIMES 0x50000 db 0");
                    if (IsGlobal)
                    {
                        aOutput.Write("global ");
                        aOutput.WriteLine(Name);
                    }
                    aOutput.Write(Name);
                    aOutput.Write(": TIMES ");
                    aOutput.Write(RawDefaultValue.Length);
                    aOutput.Write(" db ");
                    aOutput.Write(RawDefaultValue[0]);
                }
                return;
            }
            if (UntypedDefaultValue != null)
            {
                StringBuilder xSB = new StringBuilder();
                if (IsGlobal)
                {
                    aOutput.Write("global ");
                    aOutput.WriteLine(Name);
                }
                aOutput.Write(Name);
                aOutput.Write(" dw ");
                Func <object, string> xGetTextForItem = delegate(object aItem) {
                    var xElementRef = aItem as ElementReference;
                    if (xElementRef == null)
                    {
                        return((aItem ?? 0).ToString());
                    }
                    else
                    {
                        if (xElementRef.Offset == 0)
                        {
                            return(xElementRef.Name);
                        }
                        return(xElementRef.Name + " + " + xElementRef.Offset);
                    }
                };
                for (int i = 0; i < (UntypedDefaultValue.Length - 1); i++)
                {
                    aOutput.Write(xGetTextForItem(UntypedDefaultValue[i]));
                    aOutput.Write(", ");
                }
                aOutput.Write(xGetTextForItem(UntypedDefaultValue.Last()));
                return;
            }

            throw new Exception("Situation unsupported!");
        }