Example #1
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!");
        }
Example #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!");
        }
Example #3
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!");
        }