コード例 #1
0
        public void Import(string fileName)
        {
            int lineHeader = 0;

            Sample2 sample2Layout = new Sample2();

            ImportFile = new ImportFile(sample2Layout);
            if (ImportFile.PrepareFile(fileName))
            {
                Lines.Clear();

                while (ImportFile.ReadLine() && !ImportFile.ReadFailure)
                {
                    Lines.Append(ImportFile.Line + Environment.NewLine);

                    //The Sample2 line Identifier is encountered in column 1
                    //Delimited layout should always mark the column identifier
                    ImportFile.SetIdentificadorCorrente(ImportFile.CurrentLine["Col_1"].ToString());

                    switch ((Sample2.RecordType) int.Parse(ImportFile.CurrentIdentifier))
                    {
                    case Sample2.RecordType.Header:

                        lineHeader = ImportFile.CurrentLineNumber;
                        sample2Layout.HeaderRows.Add(new Sample2.HeaderRow(ImportFile.CurrentLine));
                        sample2Layout.HeaderRows.Last().LineNumber = ImportFile.CurrentLineNumber;
                        break;

                    case Sample2.RecordType.Detail:

                        sample2Layout.DetailRows.Add(new Sample2.DetailRow(ImportFile.CurrentLine));
                        sample2Layout.DetailRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        sample2Layout.DetailRows.Last().ParentLineNumber = lineHeader;
                        break;

                    case Sample2.RecordType.Trailer:
                        sample2Layout.TrailerRows.Add(new Sample2.TrailerRow(ImportFile.CurrentLine));
                        sample2Layout.TrailerRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        sample2Layout.TrailerRows.Last().ParentLineNumber = lineHeader;
                        break;
                    }

                    if (this.ImportOnlyFirstLine)
                    {
                        break;
                    }
                }

                if (ImportFile.Error)
                {
                    AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
                }
            }
            else
            {
                AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
            }
        }
コード例 #2
0
        public void Import(string fileName)
        {
            int lineHeader = 0;

            Sample1 sample1Layout = new Sample1();

            ImportFile = new ImportFile(sample1Layout);
            if (ImportFile.PrepareFile(fileName))
            {
                Lines.Clear();

                while (ImportFile.ReadLine() && !ImportFile.ReadFailure)
                {
                    Lines.Append(ImportFile.Line + Environment.NewLine);

                    switch ((Sample1.RecordType) int.Parse(ImportFile.CurrentIdentifier))
                    {
                    case Sample1.RecordType.Header:

                        lineHeader = ImportFile.CurrentLineNumber;
                        sample1Layout.HeaderRows.Add(new Sample1.HeaderRow(ImportFile.CurrentLine));
                        sample1Layout.HeaderRows.Last().LineNumber = ImportFile.CurrentLineNumber;
                        break;

                    case Sample1.RecordType.Detail:

                        sample1Layout.DetailRows.Add(new Sample1.DetailRow(ImportFile.CurrentLine));
                        sample1Layout.DetailRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        sample1Layout.DetailRows.Last().ParentLineNumber = lineHeader;
                        break;

                    case Sample1.RecordType.Trailer:
                        sample1Layout.TrailerRows.Add(new Sample1.TrailerRow(ImportFile.CurrentLine));
                        sample1Layout.TrailerRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        sample1Layout.TrailerRows.Last().ParentLineNumber = lineHeader;
                        break;
                    }

                    if (this.ImportOnlyFirstLine)
                    {
                        break;
                    }
                }

                if (ImportFile.Error)
                {
                    AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
                }
            }
            else
            {
                AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
            }
        }
コード例 #3
0
        private void CreateEncoding(dynamic node)
        {
            bool first = true;
            bool cond  = false;

            foreach (var entry in node.OpcodeEncoding)
            {
                string end     = entry.End;
                string comment = entry.Comment;

                if (first)
                {
                    first = false;
                }
                else
                {
                    Lines.AppendLine();
                }

                if (!String.IsNullOrEmpty(comment))
                {
                    Lines.Append("\t\t\t // ");
                    Lines.AppendLine(comment);
                }

                var condition = DecodeExperimentalCondition(entry.Condition) ?? string.Empty;
                var encoding  = DecodeExperimentalEncoding(entry.Encoding, node.OpcodeEncodingAppend);

                encoding = encoding.Replace("\t", string.Empty);

                if (!String.IsNullOrEmpty(condition))
                {
                    cond = true;
                    EmitCondition(condition, encoding, true, 0);
                }
                else
                {
                    EmitBits(encoding, 0);
                }
            }

            if (cond)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\t\tthrow new Compiler.Common.Exceptions.CompilerException(\"Invalid Opcode\");");
            }
        }
コード例 #4
0
        private void EmitCondition(string condition, string encoding, bool end, int index = 0)
        {
            var tabs = "\t\t\t\t\t\t\t\t\t\t".Substring(0, index + 3);

            Lines.Append(tabs);

            Lines.AppendLine("if (" + condition + ")");

            Lines.Append(tabs);
            Lines.AppendLine("{");

            EmitBits(encoding, index + 1);

            if (end)
            {
                Lines.Append(tabs);
                Lines.AppendLine("\treturn;");
            }

            Lines.Append(tabs);
            Lines.AppendLine("}");
        }
コード例 #5
0
        private void EmitBits(string bits, int index = 0)
        {
            var steps = bits.Split('|');
            var tabs  = "\t\t\t\t\t\t\t\t\t\t".Substring(0, index + 3);

            foreach (var s in steps)
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }

                if (s.StartsWith("["))                 // ignore these
                {
                    continue;
                }

                if (s.StartsWith("0x") | s.StartsWith("x"))
                {
                    // hex
                    string hex = s.StartsWith("x") ? s.Substring(1) : s.Substring(2);

                    Lines.Append(tabs);

                    switch (hex.Length)
                    {
                    case 1:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0x" + hex + ");");
                        break;

                    case 2:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendByte(0x" + hex + ");");
                        break;

                    case 3:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendByte(0x" + hex.Substring(0, 2) + ");");
                        Lines.Append(tabs);
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0x" + hex.Substring(1) + ");");
                        break;

                    case 4:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendShort(0x" + hex + ");");
                        break;

                    case 5:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendShort(0x" + hex.Substring(0, 4) + ");");
                        Lines.Append(tabs);
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0x" + hex.Substring(5) + ");");
                        break;

                    case 8:
                        Lines.AppendLine("emitter.OpcodeEncoder.Append32Bits(0x" + hex + ");");
                        break;

                    default: throw new Exception("ERROR!");
                    }
                }
                else if (s.StartsWith("0b") | s.StartsWith("b") | s.StartsWith("0") | s.StartsWith("1"))
                {
                    // binary
                    string binary = s;

                    if (binary.StartsWith("0b"))
                    {
                        binary = s.Substring(2);
                    }

                    if (binary.StartsWith("b"))
                    {
                        binary = s.Substring(1);
                    }

                    Lines.Append(tabs);

                    switch (binary.Length)
                    {
                    case 1:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendBit(0b" + binary + ");");
                        break;

                    case 2:
                        Lines.AppendLine("emitter.OpcodeEncoder.Append2Bits(0b" + binary + ");");
                        break;

                    case 3:
                        Lines.AppendLine("emitter.OpcodeEncoder.Append3Bits(0b" + binary + ");");
                        break;

                    case 4:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0b" + binary + ");");
                        break;

                    case 5:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0b" + binary.Substring(0, 4) + ");");
                        Lines.Append(tabs);
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendBit(0b" + binary.Substring(4) + ");");
                        break;

                    case 6:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0b" + binary.Substring(0, 4) + ");");
                        Lines.Append(tabs);
                        Lines.AppendLine("emitter.OpcodeEncoder.Append2Bits(0b" + binary.Substring(4) + ");");
                        break;

                    case 7:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0b" + binary.Substring(0, 4) + ");");
                        Lines.Append(tabs);
                        Lines.AppendLine("emitter.OpcodeEncoder.Append3Bits(0b" + binary.Substring(4) + ");");
                        break;

                    case 8:
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0b" + binary.Substring(0, 4) + ");");
                        Lines.Append(tabs);
                        Lines.AppendLine("emitter.OpcodeEncoder.AppendNibble(0b" + binary.Substring(4) + ");");
                        break;

                    default: throw new Exception("ERROR!");
                    }
                }
                else
                {
                    var parts = s.Split(':');

                    var code     = string.Empty;
                    var postcode = string.Empty;

                    GetCodes(parts[0], ref code, ref postcode);

                    var operand  = (parts.Length > 1) ? GetOperand(parts[1]) : string.Empty;
                    var operand2 = (parts.Length > 2) ? GetOperand(parts[2]) : null;

                    Lines.Append(tabs);

                    if (operand2 == null)
                    {
                        Lines.AppendLine("emitter.OpcodeEncoder." + code + "(" + operand + postcode + ");");
                    }
                    else
                    {
                        Lines.AppendLine("emitter.OpcodeEncoder." + code + "(" + operand + postcode + ", " + operand2 + ");");
                    }
                }
            }
        }
コード例 #6
0
        protected override void Body(dynamic node = null)
        {
            int id = Identifiers.GetInstructionID();

            Lines.AppendLine("using Mosa.Compiler.Framework;");

            if (node.ResultType != null || node.ResultType2 != null)
            {
                Lines.AppendLine("using Mosa.Compiler.MosaTypeSystem;");
            }

            Lines.AppendLine();
            Lines.AppendLine("namespace Mosa.Platform." + Platform + ".Instructions");
            Lines.AppendLine("{");
            Lines.AppendLine("\t/// <summary>");
            Lines.Append("\t/// " + node.Name);

            if (!string.IsNullOrWhiteSpace(node.Description))
            {
                Lines.Append(" - " + node.Description);
            }

            Lines.AppendLine();
            Lines.AppendLine("\t/// </summary>");
            Lines.AppendLine("\t/// <seealso cref=\"Mosa.Platform." + Platform + "." + NormalizedPlatform + "Instruction\" />");
            Lines.AppendLine("\tpublic sealed class " + node.Name + " : " + NormalizedPlatform + "Instruction");
            Lines.AppendLine("\t{");
            Lines.AppendLine("\t\tpublic override int ID { get { return " + id.ToString() + "; } }");
            Lines.AppendLine();
            Lines.AppendLine("\t\tinternal " + node.Name + "()");
            Lines.AppendLine("\t\t\t: base(" + node.ResultCount + ", " + node.OperandCount + ")");
            Lines.AppendLine("\t\t{");
            Lines.AppendLine("\t\t}");

            var FlagsUsed      = node.FlagsUsed == null ? string.Empty : node.FlagsUsed.ToUpper();           // tested_f
            var FlagsSet       = node.FlagsSet == null ? string.Empty : node.FlagsSet.ToUpper();             // values_f (upper=set, lower=cleared)
            var FlagsCleared   = node.FlagsCleared == null ? string.Empty : node.FlagsCleared.ToUpper();     // above
            var FlagsModified  = node.FlagsModified == null ? string.Empty : node.FlagsModified.ToUpper();   // modif_f
            var FlagsUndefined = node.FlagsUndefined == null ? string.Empty : node.FlagsUndefined.ToUpper(); // undef_f

            if (node.AlternativeName != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override string AlternativeName { get { return \"" + node.AlternativeName + "\"; } }");
            }

            if (node.FlowControl != null && node.FlowControl != "Next")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override FlowControl FlowControl { get { return FlowControl." + node.FlowControl + "; } }");
            }

            if (node.ResultType != null && node.ResultType != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType { get { return BuiltInType." + node.ResultType + "; } }");
            }

            if (node.ResultType2 != null && node.ResultType2 != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType2 { get { return BuiltInType." + node.ResultType2 + "; } }");
            }

            if (node.IgnoreDuringCodeGeneration != null && node.IgnoreDuringCodeGeneration == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreDuringCodeGeneration { get { return true; } }");
            }

            if (node.IgnoreInstructionBasicBlockTargets != null && node.IgnoreInstructionBasicBlockTargets == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreInstructionBasicBlockTargets { get { return true; } }");
            }

            if (node.VariableOperands != null && node.VariableOperands == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool VariableOperands { get { return true; } }");
            }

            if (node.Commutative != null && node.Commutative == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCommutative { get { return true; } }");
            }

            if (node.MemoryWrite != null && node.MemoryWrite == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryWrite { get { return true; } }");
            }

            if (node.MemoryRead != null && node.MemoryRead == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryRead { get { return true; } }");
            }

            if (node.IOOperation != null && node.IOOperation == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsIOOperation { get { return true; } }");
            }

            if (node.UnspecifiedSideEffect != null && node.UnspecifiedSideEffect == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool HasUnspecifiedSideEffect { get { return true; } }");
            }

            if (node.ThreeTwoAddressConversion != null && node.ThreeTwoAddressConversion == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool ThreeTwoAddressConversion { get { return true; } }");
            }

            if (FlagsUsed.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUsed { get { return true; } }");
            }

            if (FlagsSet.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagSet { get { return true; } }");
            }

            if (FlagsCleared.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagCleared { get { return true; } }");
            }

            if (FlagsModified.Contains("Z") || FlagsSet.Contains("Z") || FlagsCleared.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagModified { get { return true; } }");
            }

            if (FlagsUndefined.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUnchanged { get { return true; } }");
            }

            if (FlagsUndefined.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUndefined { get { return true; } }");
            }

            if (FlagsUsed.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUsed { get { return true; } }");
            }

            if (FlagsSet.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagSet { get { return true; } }");
            }

            if (FlagsCleared.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagCleared { get { return true; } }");
            }

            if (FlagsModified.Contains("C") || FlagsSet.Contains("C") || FlagsCleared.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagModified { get { return true; } }");
            }

            if (FlagsUndefined.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUnchanged { get { return true; } }");
            }

            if (FlagsUndefined.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUndefined { get { return true; } }");
            }

            if (FlagsUsed.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUsed { get { return true; } }");
            }

            if (FlagsSet.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagSet { get { return true; } }");
            }

            if (FlagsCleared.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagCleared { get { return true; } }");
            }

            if (FlagsModified.Contains("S") || FlagsSet.Contains("S") || FlagsCleared.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagModified { get { return true; } }");
            }

            if (FlagsUndefined.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUnchanged { get { return true; } }");
            }

            if (FlagsUndefined.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUndefined { get { return true; } }");
            }

            if (FlagsUsed.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUsed { get { return true; } }");
            }

            if (FlagsSet.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagSet { get { return true; } }");
            }

            if (FlagsCleared.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagCleared { get { return true; } }");
            }

            if (FlagsModified.Contains("O") || FlagsSet.Contains("O") || FlagsCleared.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagModified { get { return true; } }");
            }

            if (FlagsUndefined.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUnchanged { get { return true; } }");
            }

            if (FlagsUndefined.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUndefined { get { return true; } }");
            }

            if (FlagsUsed.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUsed { get { return true; } }");
            }

            if (FlagsSet.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagSet { get { return true; } }");
            }

            if (FlagsCleared.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagCleared { get { return true; } }");
            }

            if (FlagsModified.Contains("P") || FlagsSet.Contains("P") || FlagsCleared.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagModified { get { return true; } }");
            }

            if (FlagsUndefined.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUnchanged { get { return true; } }");
            }

            if (FlagsUndefined.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUndefined { get { return true; } }");
            }

            if (node.LogicalOpposite != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BaseInstruction GetOpposite()");
                Lines.AppendLine("\t\t{");
                Lines.AppendLine("\t\t\treturn " + node.FamilyName + "." + node.LogicalOpposite + ";");
                Lines.AppendLine("\t\t}");
            }

            if (node.StaticEmitMethod != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override void Emit(InstructionNode node, BaseCodeEmitter emitter)");
                Lines.AppendLine("\t\t{");

                if (node.VariableOperands == null || node.VariableOperands == "false")
                {
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.ResultCount == DefaultResultCount);");
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.OperandCount == DefaultOperandCount);");
                    Lines.AppendLine();
                }

                Lines.AppendLine("\t\t\t" + node.StaticEmitMethod.Replace("%", node.Name) + "(node, emitter);");
                Lines.AppendLine("\t\t}");
            }

            if (node.OpcodeEncoding != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override void Emit(InstructionNode node, BaseCodeEmitter emitter)");
                Lines.AppendLine("\t\t{");
                if (node.VariableOperands == null || node.VariableOperands == "false")
                {
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.ResultCount == " + node.ResultCount + ");");
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.OperandCount == " + node.OperandCount + ");");

                    if (node.ThreeTwoAddressConversion != null && node.ThreeTwoAddressConversion == "true")
                    {
                        Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.Result.IsCPURegister);");
                        Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.Operand1.IsCPURegister);");
                        Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.Result.Register == node.Operand1.Register);");
                    }
                    Lines.AppendLine();
                }

                CreateEncoding(node);

                Lines.AppendLine("\t\t}");
            }

            Lines.AppendLine("\t}");
            Lines.AppendLine("}");
        }
コード例 #7
0
        public void Import(string fileName)
        {
            int lineHeader    = 0;
            int linePagamento = 0;
            int lineSOC       = 0;

            Amex amexLayout = new Amex();

            ImportFile = new ImportFile(amexLayout);
            if (ImportFile.PrepareFile(fileName))
            {
                Lines.Clear();

                while (ImportFile.ReadLine() && !ImportFile.ReadFailure)
                {
                    Lines.Append(ImportFile.Line + Environment.NewLine);

                    //The Amex line Identifier is encountered in column 6
                    //Delimited layout should always mark the column identifier
                    ImportFile.SetIdentificadorCorrente(ImportFile.CurrentLine["Col_6"].ToString());

                    switch ((Amex.RecordType) int.Parse(ImportFile.CurrentIdentifier))
                    {
                    case Amex.RecordType.Header:

                        lineHeader = ImportFile.CurrentLineNumber;
                        amexLayout.HeaderRows.Add(new Amex.HeaderRow(ImportFile.CurrentLine));
                        amexLayout.HeaderRows.Last().LineNumber = ImportFile.CurrentLineNumber;
                        break;

                    case Amex.RecordType.Pagamento:

                        linePagamento = ImportFile.CurrentLineNumber;
                        amexLayout.PagamentoRows.Add(new Amex.PagamentoRow(ImportFile.CurrentLine));
                        amexLayout.PagamentoRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.PagamentoRows.Last().ParentLineNumber = lineHeader;
                        break;

                    case Amex.RecordType.SOC:

                        lineSOC = ImportFile.CurrentLineNumber;
                        amexLayout.SOCRows.Add(new Amex.SOCRow(ImportFile.CurrentLine));
                        amexLayout.SOCRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.SOCRows.Last().ParentLineNumber = linePagamento;
                        break;

                    case Amex.RecordType.ROC:
                        amexLayout.ROCRows.Add(new Amex.ROCRow(ImportFile.CurrentLine));
                        amexLayout.ROCRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.ROCRows.Last().ParentLineNumber = lineSOC;
                        break;

                    case Amex.RecordType.Ajustes:
                        amexLayout.AjustesRows.Add(new Amex.AjustesRow(ImportFile.CurrentLine));
                        amexLayout.AjustesRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.AjustesRows.Last().ParentLineNumber = linePagamento;
                        break;

                    case Amex.RecordType.Trailer:
                        amexLayout.TrailerRows.Add(new Amex.TrailerRow(ImportFile.CurrentLine));
                        amexLayout.TrailerRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        amexLayout.TrailerRows.Last().ParentLineNumber = lineHeader;
                        break;
                    }

                    if (this.ImportOnlyFirstLine)
                    {
                        break;
                    }
                }

                if (ImportFile.Error)
                {
                    AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
                }
            }
            else
            {
                AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
            }
        }
コード例 #8
0
        protected override void Body(dynamic node = null)
        {
            int id = Identifiers.GetInstructionID();

            string bytes    = EncodeOpcodeBytes(node);
            string legacy   = EncodeLegacyOpcode(node);
            string reg      = EncodeLegacyOpecodeRegField(node);
            string operands = EncodeOperandsOrder(node);

            Lines.AppendLine("using Mosa.Compiler.Framework;");

            if (node.ResultType != null || node.ResultType2 != null)
            {
                Lines.AppendLine("using Mosa.Compiler.MosaTypeSystem;");
            }

            Lines.AppendLine();
            Lines.AppendLine("namespace Mosa.Platform.x86.Instructions");
            Lines.AppendLine("{");
            Lines.AppendLine("\t/// <summary>");
            Lines.Append("\t/// " + node.Name);

            if (!string.IsNullOrWhiteSpace(node.Description))
            {
                Lines.Append(" - " + node.Description);
            }

            Lines.AppendLine();
            Lines.AppendLine("\t/// </summary>");
            Lines.AppendLine("\t/// <seealso cref=\"Mosa.Platform.x86.X86Instruction\" />");
            Lines.AppendLine("\tpublic sealed class " + node.Name + " : X86Instruction");
            Lines.AppendLine("\t{");
            Lines.AppendLine("\t\tpublic override int ID { get { return " + id.ToString() + "; } }");
            Lines.AppendLine();
            Lines.AppendLine("\t\tinternal " + node.Name + "()");
            Lines.AppendLine("\t\t\t: base(" + node.ResultCount + ", " + node.OperandCount + ")");
            Lines.AppendLine("\t\t{");
            Lines.AppendLine("\t\t}");

            if (node.AlternativeName != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override string AlternativeName { get { return \"" + node.AlternativeName + "\"; } }");
            }

            if (node.X86EmitBytes != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic static readonly byte[] opcode = new byte[] { " + bytes + " };");
            }

            if (node.X86LegacyOpcode != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic static readonly LegacyOpCode LegacyOpcode = new LegacyOpCode(new byte[] { " + legacy + " }" + reg + ");");
            }

            if (node.FlowControl != null && node.FlowControl != "Next")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override FlowControl FlowControl { get { return FlowControl." + node.FlowControl + "; } }");
            }

            if (node.ResultType != null && node.ResultType != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType { get { return BuiltInType." + node.ResultType + "; } }");
            }

            if (node.ResultType2 != null && node.ResultType2 != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType2 { get { return BuiltInType." + node.ResultType2 + "; } }");
            }

            if (node.IgnoreDuringCodeGeneration != null && node.IgnoreDuringCodeGeneration == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreDuringCodeGeneration { get { return true; } }");
            }

            if (node.IgnoreInstructionBasicBlockTargets != null && node.IgnoreInstructionBasicBlockTargets == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreInstructionBasicBlockTargets { get { return true; } }");
            }

            if (node.VariableOperands != null && node.VariableOperands == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool VariableOperands { get { return true; } }");
            }

            if (node.Commutative != null && node.Commutative == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCommutative { get { return true; } }");
            }

            if (node.MemoryWrite != null && node.MemoryWrite == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryWrite { get { return true; } }");
            }

            if (node.MemoryRead != null && node.MemoryRead == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryRead { get { return true; } }");
            }

            if (node.IOOperation != null && node.IOOperation == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsIOOperation { get { return true; } }");
            }

            if (node.UnspecifiedSideEffect != null && node.UnspecifiedSideEffect == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool HasUnspecifiedSideEffect { get { return true; } }");
            }

            if (node.X86ThreeTwoAddressConversion != null && node.X86ThreeTwoAddressConversion == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool ThreeTwoAddressConversion { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("Z") || node.FlagsSet.Contains("Z") || node.FlagsCleared.Contains("Z")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUndefined { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("C") || node.FlagsSet.Contains("C") || node.FlagsCleared.Contains("C")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUndefined { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("S") || node.FlagsSet.Contains("S") || node.FlagsCleared.Contains("S")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUndefined { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("O") || node.FlagsSet.Contains("O") || node.FlagsCleared.Contains("O")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUndefined { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("P") || node.FlagsSet.Contains("P") || node.FlagsCleared.Contains("P")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUndefined { get { return true; } }");
            }

            if (node.LogicalOpposite != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BaseInstruction GetOpposite()");
                Lines.AppendLine("\t\t{");
                Lines.AppendLine("\t\t\treturn " + node.FamilyName + "." + node.LogicalOpposite + ";");
                Lines.AppendLine("\t\t}");
            }

            if (node.X86EmitBytes != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override void Emit(InstructionNode node, BaseCodeEmitter emitter)");
                Lines.AppendLine("\t\t{");

                if (node.VariableOperands == null || node.VariableOperands == "false")
                {
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.ResultCount == " + node.ResultCount + ");");
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.OperandCount == " + node.OperandCount + ");");

                    if (node.X86EmitRelativeBranchTarget != null || node.X86EmitRelativeBranchTarget == "true")
                    {
                        Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.BranchTargets.Count >= 1);");
                        Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.BranchTargets[0] != null);");
                    }
                    Lines.AppendLine();
                }

                Lines.AppendLine("\t\t\temitter.Write(opcode);");

                if (node.X86EmitRelativeBranchTarget != null || node.X86EmitRelativeBranchTarget == "true")
                {
                    Lines.AppendLine("\t\t\t(emitter as X86CodeEmitter).EmitRelativeBranchTarget(node.BranchTargets[0].Label);");
                }

                Lines.AppendLine("\t\t}");
            }

            if (node.StaticEmitMethod != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override void Emit(InstructionNode node, BaseCodeEmitter emitter)");
                Lines.AppendLine("\t\t{");

                if (node.VariableOperands == null || node.VariableOperands == "false")
                {
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.ResultCount == DefaultResultCount);");
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.OperandCount == DefaultOperandCount);");
                    Lines.AppendLine();
                }

                Lines.AppendLine("\t\t\t" + node.StaticEmitMethod.Replace("%", node.Name) + "(node, emitter);");
                Lines.AppendLine("\t\t}");
            }

            if (node.X86LegacyOpcodeOperandOrder != null && node.X86LegacyOpcode != null && node.StaticEmitMethod == null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tinternal override void EmitLegacy(InstructionNode node, X86CodeEmitter emitter)");
                Lines.AppendLine("\t\t{");
                if (node.VariableOperands == null || node.VariableOperands == "false")
                {
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.ResultCount == " + node.ResultCount + ");");
                    Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.OperandCount == " + node.OperandCount + ");");

                    if (node.X86ThreeTwoAddressConversion == null || node.X86ThreeTwoAddressConversion == "true")
                    {
                        Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.Result.IsCPURegister);");
                        Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.Operand1.IsCPURegister);");
                        Lines.AppendLine("\t\t\tSystem.Diagnostics.Debug.Assert(node.Result.Register == node.Operand1.Register);");
                    }
                    Lines.AppendLine();
                }

                if (operands == null)
                {
                    Lines.AppendLine("\t\t\temitter.Emit(LegacyOpcode);");
                }
                else
                {
                    Lines.AppendLine("\t\t\temitter.Emit(LegacyOpcode, " + operands + ");");
                }
                Lines.AppendLine("\t\t}");
            }

            Lines.AppendLine("\t}");
            Lines.AppendLine("}");
        }
コード例 #9
0
        public void Import(string fileName)
        {
            int lineHeader   = 0;
            int lineCapaLote = 0;

            Hipercard hipercardLayout = new Hipercard();

            this.ImportFile = new ImportFile(hipercardLayout);
            if (ImportFile.PrepareFile(fileName))
            {
                Lines.Clear();

                while ((ImportFile.ReadLine() && !ImportFile.ReadFailure))
                {
                    Lines.Append(ImportFile.Line + Environment.NewLine);

                    switch ((Hipercard.RecordType) int.Parse(ImportFile.CurrentIdentifier))
                    {
                    case Hipercard.RecordType.Header:

                        lineHeader = ImportFile.CurrentLineNumber;
                        hipercardLayout.HeaderRows.Add(new Hipercard.HeaderRow(ImportFile.CurrentLine));
                        hipercardLayout.HeaderRows.Last().LineNumber = ImportFile.CurrentLineNumber;
                        break;

                    case Hipercard.RecordType.CapaLote:

                        lineCapaLote = ImportFile.CurrentLineNumber;
                        hipercardLayout.CapaLoteRows.Add(new Hipercard.CapaLoteRow(ImportFile.CurrentLine));
                        hipercardLayout.CapaLoteRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        hipercardLayout.CapaLoteRows.Last().ParentLineNumber = lineHeader;

                        break;

                    case Hipercard.RecordType.MovimentoVenda:

                        hipercardLayout.MovVendaRows.Add(new Hipercard.MovimentoVendaRow(ImportFile.CurrentLine));
                        hipercardLayout.MovVendaRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        hipercardLayout.MovVendaRows.Last().ParentLineNumber = lineCapaLote;

                        break;

                    case Hipercard.RecordType.PrevisaoPagamento:

                        hipercardLayout.PrevPagtoRows.Add(new Hipercard.PrevisaoPagamentoRow(ImportFile.CurrentLine));
                        hipercardLayout.PrevPagtoRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        hipercardLayout.PrevPagtoRows.Last().ParentLineNumber = lineCapaLote;

                        break;

                    case Hipercard.RecordType.Desagendamento:

                        hipercardLayout.DesagendaRows.Add(new Hipercard.DesagendamentoRow(ImportFile.CurrentLine));
                        hipercardLayout.DesagendaRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        hipercardLayout.DesagendaRows.Last().ParentLineNumber = lineCapaLote;

                        break;

                    case Hipercard.RecordType.Ajustes:

                        hipercardLayout.AjustesRows.Add(new Hipercard.AjustesRow(ImportFile.CurrentLine));
                        hipercardLayout.AjustesRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        hipercardLayout.AjustesRows.Last().ParentLineNumber = lineCapaLote;

                        break;

                    case Hipercard.RecordType.Tarifas:

                        hipercardLayout.TarifasRows.Add(new Hipercard.TarifasRow(ImportFile.CurrentLine));
                        hipercardLayout.TarifasRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        hipercardLayout.TarifasRows.Last().ParentLineNumber = lineCapaLote;

                        break;

                    case Hipercard.RecordType.Trailer:

                        hipercardLayout.TrailerRows.Add(new Hipercard.TrailerRow(ImportFile.CurrentLine));
                        hipercardLayout.TrailerRows.Last().LineNumber       = ImportFile.CurrentLineNumber;
                        hipercardLayout.TrailerRows.Last().ParentLineNumber = lineHeader;

                        break;
                    }

                    if (this.ImportOnlyFirstLine)
                    {
                        break;
                    }
                }

                if (ImportFile.Error)
                {
                    AddLineError("INTERNAL", ImportFile.ErrorDescription, ImportFile.CurrentLineNumber);
                }
            }
        }
コード例 #10
0
        protected override void Body(dynamic node = null)
        {
            if (node.ResultType != null || node.ResultType2 != null)
            {
                Lines.AppendLine("using Mosa.Compiler.MosaTypeSystem;");
                Lines.AppendLine();
            }

            Lines.AppendLine("namespace Mosa.Compiler.Framework.IR");
            Lines.AppendLine("{");
            Lines.AppendLine("\t/// <summary>");
            Lines.Append($"\t/// {node.Name}");

            if (!string.IsNullOrWhiteSpace(node.Description))
            {
                Lines.Append($" - {node.Description}");
            }
            Lines.AppendLine();

            Lines.AppendLine("\t/// </summary>");
            Lines.AppendLine("\t/// <seealso cref=\"Mosa.Compiler.Framework.IR.BaseIRInstruction\" />");
            Lines.AppendLine($"\tpublic sealed class {node.Name} : BaseIRInstruction");
            Lines.AppendLine("\t{");
            Lines.AppendLine("\t\tpublic " + node.Name + "()");
            Lines.AppendLine($"\t\t\t: base({node.OperandCount}, {node.ResultCount})");
            Lines.AppendLine("\t\t{");
            Lines.AppendLine("\t\t}");

            if (node.FlowControl != null && node.FlowControl != "Next")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override FlowControl FlowControl { get { return FlowControl." + node.FlowControl + "; } }");
            }

            if (node.ResultType != null && node.ResultType != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType { get { return BuiltInType." + node.ResultType + "; } }");
            }

            if (node.ResultType2 != null && node.ResultType2 != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType2 { get { return BuiltInType." + node.ResultType2 + "; } }");
            }

            if (node.IgnoreDuringCodeGeneration != null && node.IgnoreDuringCodeGeneration == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreDuringCodeGeneration { get { return true; } }");
            }

            if (node.IgnoreInstructionBasicBlockTargets != null && node.IgnoreInstructionBasicBlockTargets == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreInstructionBasicBlockTargets { get { return true; } }");
            }

            if (node.VariableOperands != null && node.VariableOperands == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool VariableOperands { get { return true; } }");
            }

            if (node.Commutative != null && node.Commutative == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCommutative { get { return true; } }");
            }

            if (node.MemoryWrite != null && node.MemoryWrite == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryWrite { get { return true; } }");
            }

            if (node.MemoryRead != null && node.MemoryRead == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryRead { get { return true; } }");
            }

            if (node.IOOperation != null && node.IOOperation == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsIOOperation { get { return true; } }");
            }

            if (node.IRUnspecifiedSideEffect != null && node.IRUnspecifiedSideEffect == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool HasIRUnspecifiedSideEffect { get { return true; } }");
            }

            if (node.ParameterLoad != null && node.ParameterLoad == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParameterLoad { get { return true; } }");
            }

            if (node.ParameterStore != null && node.ParameterStore == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParameterStore { get { return true; } }");
            }

            Lines.AppendLine("\t}");
            Lines.AppendLine("}");
        }
コード例 #11
0
        protected override void Body(dynamic node = null)
        {
            int id = Identifiers.GetInstructionID();

            Lines.AppendLine("using Mosa.Compiler.Framework;");

            if (node.ResultType != null || node.ResultType2 != null)
            {
                Lines.AppendLine("using Mosa.Compiler.MosaTypeSystem;");
            }

            if (!string.IsNullOrWhiteSpace(node.ARMv6Opcode))
            {
                Lines.AppendLine("using Mosa.Compiler.Common;");
            }

            Lines.AppendLine();
            Lines.AppendLine("namespace Mosa.Platform.ARMv6.Instructions");
            Lines.AppendLine("{");
            Lines.AppendLine("\t/// <summary>");
            Lines.Append("\t/// " + node.Name);

            if (!string.IsNullOrWhiteSpace(node.Description))
            {
                Lines.Append(" - " + node.Description);
            }

            Lines.AppendLine();
            Lines.AppendLine("\t/// </summary>");
            Lines.AppendLine("\t/// <seealso cref=\"Mosa.Platform.ARMv6.ARMv6Instruction\" />");
            Lines.AppendLine("\tpublic sealed class " + node.Name + " : ARMv6Instruction");
            Lines.AppendLine("\t{");
            Lines.AppendLine("\t\tpublic override int ID { get { return " + id.ToString() + "; } }");
            Lines.AppendLine();
            Lines.AppendLine("\t\tinternal " + node.Name + "()");
            Lines.AppendLine("\t\t\t: base(" + node.ResultCount + ", " + node.OperandCount + ")");
            Lines.AppendLine("\t\t{");
            Lines.AppendLine("\t\t}");

            if (node.AlternativeName != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override string AlternativeName { get { return \"" + node.AlternativeName + "\"; } }");
            }

            if (node.FlowControl != null && node.FlowControl != "Next")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override FlowControl FlowControl { get { return FlowControl." + node.FlowControl + "; } }");
            }

            if (node.ResultType != null && node.ResultType != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType { get { return BuiltInType." + node.ResultType + "; } }");
            }

            if (node.ResultType2 != null && node.ResultType2 != "")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BuiltInType ResultType2 { get { return BuiltInType." + node.ResultType2 + "; } }");
            }

            if (node.IgnoreDuringCodeGeneration != null && node.IgnoreDuringCodeGeneration == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreDuringCodeGeneration { get { return true; } }");
            }

            if (node.IgnoreInstructionBasicBlockTargets != null && node.IgnoreInstructionBasicBlockTargets == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IgnoreInstructionBasicBlockTargets { get { return true; } }");
            }

            if (node.VariableOperands != null && node.VariableOperands == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool VariableOperands { get { return true; } }");
            }

            if (node.Commutative != null && node.Commutative == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCommutative { get { return true; } }");
            }

            if (node.MemoryWrite != null && node.MemoryWrite == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryWrite { get { return true; } }");
            }

            if (node.MemoryRead != null && node.MemoryRead == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsMemoryRead { get { return true; } }");
            }

            if (node.IOOperation != null && node.IOOperation == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsIOOperation { get { return true; } }");
            }

            if (node.UnspecifiedSideEffect != null && node.UnspecifiedSideEffect == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool HasUnspecifiedSideEffect { get { return true; } }");
            }

            if (node.ARMv6ThreeTwoAddressConversion != null && node.ARMv6ThreeTwoAddressConversion == "true")
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool ThreeTwoAddressConversion { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("Z") || node.FlagsSet.Contains("Z") || node.FlagsCleared.Contains("Z")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("Z"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsZeroFlagUndefined { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("C") || node.FlagsSet.Contains("C") || node.FlagsCleared.Contains("C")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("C"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsCarryFlagUndefined { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("S") || node.FlagsSet.Contains("S") || node.FlagsCleared.Contains("S")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("S"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsSignFlagUndefined { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("O") || node.FlagsSet.Contains("O") || node.FlagsCleared.Contains("O")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("O"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsOverflowFlagUndefined { get { return true; } }");
            }

            if (node.FlagsUsed != null && node.FlagsUsed.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUsed { get { return true; } }");
            }

            if (node.FlagsSet != null && node.FlagsSet.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagSet { get { return true; } }");
            }

            if (node.FlagsCleared != null && node.FlagsCleared.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagCleared { get { return true; } }");
            }

            if (node.FlagsModified != null && (node.FlagsModified.Contains("P") || node.FlagsSet.Contains("P") || node.FlagsCleared.Contains("P")))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagModified { get { return true; } }");
            }

            if (node.FlagsUndefined != null && node.FlagsUndefined.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUnchanged { get { return true; } }");
            }

            if (node.FlagsUnchanged != null && node.FlagsUndefined.Contains("P"))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override bool IsParityFlagUndefined { get { return true; } }");
            }

            if (node.LogicalOpposite != null)
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tpublic override BaseInstruction GetOpposite()");
                Lines.AppendLine("\t\t{");
                Lines.AppendLine("\t\t\treturn " + node.FamilyName + "." + node.LogicalOpposite + ";");
                Lines.AppendLine("\t\t}");
            }

            if (!string.IsNullOrWhiteSpace(node.ARMv6Emitter))
            {
                Lines.AppendLine();
                Lines.AppendLine("\t\tprotected override void Emit(InstructionNode node, ARMv6CodeEmitter emitter)");
                Lines.AppendLine("\t\t{");

                if (!string.IsNullOrWhiteSpace(node.ARMv6Opcode))
                {
                    Lines.AppendLine("\t\t\t" + node.ARMv6Emitter + "(node, emitter, Bits." + node.ARMv6Opcode + ");");
                }
                else
                {
                    Lines.AppendLine("\t\t\t" + node.ARMv6Emitter + "(node, emitter);");
                }

                Lines.AppendLine("\t\t}");
            }

            Lines.AppendLine("\t}");
            Lines.AppendLine("}");
        }