Esempio n. 1
0
 private Instruction(string mnemonic, OperandKind operandKind, byte opCode, byte length)
 {
     Mnemonic = mnemonic;
     OperandKind = operandKind;
     OpCode = opCode;
     Length = length;
 }
Esempio n. 2
0
        public CompositeTemplate(OperandKind operandKind)
        {
            _operandKind = operandKind;
            var bases = new List <Property>();
            var visitedPropertyNames = new HashSet <string>();

            foreach (var type in operandKind.bases ?? EmptyReadOnlyList <string> .Instance)
            {
                string name = type;
                if (!visitedPropertyNames.Add(name))
                {
                    for (int i = 2; ; i++)
                    {
                        name = type + i;
                        if (visitedPropertyNames.Add(name))
                        {
                            break;
                        }
                    }
                }
                var property = new Property()
                {
                    Type = Utils.GetTypeName(type),
                    Base = type,
                    Name = name
                };
                bases.Add(property);
            }

            this.bases = bases;
        }
Esempio n. 3
0
        public static bool IsConstant(this OperandKind kind)
        {
            const int mask = (1 << (int)OperandKind.Int8)
                             | (1 << (int)OperandKind.Int32) | (1 << (int)OperandKind.Int64)
                             | (1 << (int)OperandKind.Float32) | (1 << (int)OperandKind.Float64);

            return(((1 << (int)kind) & mask) != 0);
        }
Esempio n. 4
0
        public static bool IsMetadataToken(this OperandKind kind)
        {
            const int mask = (1 << (int)OperandKind.FieldToken)
                             | (1 << (int)OperandKind.MethodToken) | (1 << (int)OperandKind.SignatureToken)
                             | (1 << (int)OperandKind.StringToken) | (1 << (int)OperandKind.Token)
                             | (1 << (int)OperandKind.TypeToken);

            return(((1 << (int)kind) & mask) != 0);
        }
Esempio n. 5
0
        public Operand With(OperandKind kind, OperandType type = OperandType.None, ulong value = 0)
        {
            Kind = kind;
            Type = type;
            Value = value;

            Assignments.Clear();
            Uses.Clear();
            return this;
        }
Esempio n. 6
0
 private SpirvOperandDescription GetOperandDescription(OperandKind operandKind)
 {
     return(new SpirvOperandDescription()
     {
         Name = operandKind.kind,
         Category = GetOperandCategory(operandKind.category),
         Kind = GetKind(operandKind.kind),
         Bases = operandKind.bases,
         Doc = operandKind.doc,
         Enumerants = operandKind.enumerants
     });
 }
Esempio n. 7
0
 /// <summary>
 /// Gets the size in bytes of an opcode operand of a given kind when encoded in an instruction stream.
 /// </summary>
 /// <param name="kind">The operand kind.</param>
 /// <returns>
 /// The size of the operand in bytes,
 /// or <c>null</c> if it is variable-sized (<see cref="OperandKind.JumpTable"/>).
 /// </returns>
 public static int?GetSizeInBytes(this OperandKind kind)
 {
     if ((int)kind < enumerantsPerField)
     {
         int shift = (int)kind * bitsPerEnumerant;
         return((int)(sizes1 >> shift) & lowEnumerantMask);
     }
     else
     {
         int shift = ((int)kind - enumerantsPerField) * bitsPerEnumerant;
         return(kind == OperandKind.JumpTable ? (int?)null : ((int)(sizes2 >> shift) & lowEnumerantMask));
     }
 }
Esempio n. 8
0
        public Operand With(OperandKind kind, OperandType type = OperandType.None, ulong value = 0, bool disableCF = false, int?index = null)
        {
            Kind = kind;
            Type = type;

            Value = value;

            DisableCF = disableCF;
            PtcIndex  = index;

            Assignments.Clear();
            Uses.Clear();

            return(this);
        }
Esempio n. 9
0
 private static void InitializeEnumerant(OperandKind kind, DataType type)
 {
     if ((int)kind < enumerantsPerField)
     {
         int shift = (int)kind * bitsPerEnumerant;
         dataTypes1 = (ulong)type << shift;
         sizes1     = (ulong)type.GetSizeInBytes() << shift;
     }
     else
     {
         int shift = ((int)kind - enumerantsPerField) * bitsPerEnumerant;
         dataTypes2 = (ulong)type << shift;
         sizes2     = (ulong)type.GetSizeInBytes() << shift;
     }
 }
Esempio n. 10
0
 public static DataType?GetDataType(this OperandKind kind)
 {
     if ((int)kind < enumerantsPerField)
     {
         int shift = (int)kind * bitsPerEnumerant;
         return(kind == OperandKind.None
                                 ? (DataType?)null
                                 : (DataType)((int)(dataTypes1 >> shift) & lowEnumerantMask));
     }
     else
     {
         int shift = ((int)kind - enumerantsPerField) * bitsPerEnumerant;
         return(kind == OperandKind.JumpTable
                                 ? (DataType?)null
                                 : (DataType)((int)(dataTypes2 >> shift) & lowEnumerantMask));
     }
 }
Esempio n. 11
0
        public Operand With(
            OperandKind kind,
            OperandType type = OperandType.None,
            ulong value      = 0,
            Symbol symbol    = default)
        {
            Kind = kind;
            Type = type;

            Value = value;

            Symbol = symbol;

            Assignments.Clear();
            Uses.Clear();

            return(this);
        }
Esempio n. 12
0
 private static string GetKey(string mnemonic, OperandKind operandKind)
 {
     return mnemonic + operandKind;
 }
Esempio n. 13
0
 public EnumTemplate(OperandKind operandKind)
 {
     _operandKind = operandKind;
 }
Esempio n. 14
0
 public IdTemplate(OperandKind operandKind)
 {
     _operandKind = operandKind;
 }
Esempio n. 15
0
 private static bool IsLocalOrRegister(OperandKind kind)
 {
     return(kind == OperandKind.LocalVariable ||
            kind == OperandKind.Register);
 }
Esempio n. 16
0
        public override void EndNode(ParserContext context)
        {
            expressionResolver.EndNode(context);

            switch (context.NodeKind)
            {
                case SyntaxNodeKind.Label:
                    labelName = context.Span.Text;
                    break;

                case SyntaxNodeKind.MacroName:
                    currentMacroName = context.Span.Text;
                    break;

                case SyntaxNodeKind.Macro:
                    currentMacro = new Macro(currentMacroName);
                    break;

                case SyntaxNodeKind.DirectiveName:
                    directiveName = context.Span.Text;
                    if (labelName != null && directiveName != "=")
                    {
                        AddLabel(new Label(labelName, currentChunkStartAddress + opcodes.Count));
                        labelName = null;
                    }
                    break;

                case SyntaxNodeKind.Directive:
                    ProcessDriective();
                    break;

                case SyntaxNodeKind.Instruction:
                    ProcessInstruction();
                    break;

                case SyntaxNodeKind.ImpliedOperand:
                    operandKind = OperandKind.Implied;
                    break;

                case SyntaxNodeKind.AbsoluteOperand:
                    ProcessAbsoluteOperand();
                    break;

                case SyntaxNodeKind.ImmediateOperand:
                    operandValue = (byte) expressionResolver.Evaluate();
                    operandKind = OperandKind.Immediate;
                    break;

                case SyntaxNodeKind.IndirectOperand:
                    ProcessIndirectOperand();
                    break;

                case SyntaxNodeKind.OperandIndexer:
                    ProcessOperandIndexer(context.Span.Text);
                    break;

                case SyntaxNodeKind.Mnemonic:
                    mnemonic = context.Span.Text;
                    break;

                case SyntaxNodeKind.DirectiveOperands:
                    directiveOperands.Enqueue(expressionResolver.Evaluate());
                    break;

                case SyntaxNodeKind.Literal:
                    foreach (var b in AtasciiEncoding.Instance.GetBytes(context.Span.Text))
                    {
                        directiveOperands.Enqueue(b);
                    }
                    break;

                case SyntaxNodeKind.Line:
                    if (labelName != null)
                    {
                        AddLabel(new Label(labelName, currentChunkStartAddress + opcodes.Count));
                        labelName = null;
                    }
                    break;

            }
        }
Esempio n. 17
0
 // .Ctor
 private Operand(OperandKind kind, object value)
 {
     Kind  = kind;
     Value = value;
 }
Esempio n. 18
0
 public FlagTemplate(OperandKind enumeration)
 {
     _enumeration = enumeration;
 }
Esempio n. 19
0
        public static bool IsBranchTarget(this OperandKind kind)
        {
            const int mask = (1 << (int)OperandKind.BranchTarget8) | (1 << (int)OperandKind.BranchTarget32);

            return(((1 << (int)kind) & mask) != 0);
        }
Esempio n. 20
0
 public LiteralTemplate(OperandKind operandKind)
 {
     _operandKind = operandKind;
 }
Esempio n. 21
0
        public static bool IsVariableIndex(this OperandKind kind)
        {
            const int mask = (1 << (int)OperandKind.VariableIndex8) | (1 << (int)OperandKind.VariableIndex16);

            return(((1 << (int)kind) & mask) != 0);
        }
Esempio n. 22
0
 public static Instruction Find(string mnemonic, OperandKind operandKind)
 {
     return SupportedInstructions[GetKey(mnemonic, operandKind)];
 }
Esempio n. 23
0
 public static bool TryFind(string mnemonic, OperandKind operandKind, out Instruction instruction)
 {
     return SupportedInstructions.TryGetValue(GetKey(mnemonic, operandKind), out instruction);
 }
Esempio n. 24
0
 private void ProcessIndirectOperand()
 {
     operandValue = expressionResolver.Evaluate();
     if (indexer.HasValue)
     {
         switch (indexer.Value)
         {
             case IndexerKind.X:
                 operandKind = OperandKind.IndirectX;
                 break;
             case IndexerKind.Y:
                 operandKind = OperandKind.IndirectY;
                 break;
         }
     }
     else
     {
         operandKind = OperandKind.Indirect;
     }
 }
Esempio n. 25
0
 public Operand(OperandKind kind, OperandType type = OperandType.None)
     : this()
 {
     Kind = kind;
     Type = type;
 }
Esempio n. 26
0
 private void ProcessAbsoluteOperand()
 {
     operandValue = expressionResolver.Evaluate();
     if (indexer.HasValue)
     {
         switch (indexer.Value)
         {
             case IndexerKind.X:
                 operandKind = OperandKind.AbsoluteX;
                 break;
             case IndexerKind.Y:
                 operandKind = OperandKind.AbsoluteY;
                 break;
         }
     }
     else
     {
         operandKind = OperandKind.Absolute;
     }
 }
Esempio n. 27
0
            private static Operand Make(OperandKind kind, OperandType type, ulong value, Symbol symbol = default)
            {
                Debug.Assert(kind != OperandKind.None);

                Data *data = null;

                // If constant or register, then try to look up in the intern table before allocating.
                if (kind == OperandKind.Constant || kind == OperandKind.Register)
                {
                    uint hash = (uint)HashCode.Combine(kind, type, value);

                    // Look in the next InternTableProbeLength slots for a match.
                    for (uint i = 0; i < InternTableProbeLength; i++)
                    {
                        Operand interned = new();
                        interned._data = &InternTable[(hash + i) % InternTableSize];

                        // If slot matches the allocation request then return that slot.
                        if (interned.Kind == kind && interned.Type == type && interned.Value == value && interned.Symbol == symbol)
                        {
                            return(interned);
                        }
                        // Otherwise if the slot is not occupied, we store in that slot.
                        else if (interned.Kind == OperandKind.None)
                        {
                            data = interned._data;

                            break;
                        }
                    }
                }

                // If we could not get a slot from the intern table, we allocate somewhere else and store there.
                if (data == null)
                {
                    data = Allocators.Operands.Allocate <Data>();
                }

                *data = default;

                Operand result = new();

                result._data = data;
                result.Value = value;
                result.Kind  = kind;
                result.Type  = type;

                if (kind != OperandKind.Memory)
                {
                    result.Symbol = symbol;
                }

                // If local variable, then the use and def list is initialized with default sizes.
                if (kind == OperandKind.LocalVariable)
                {
                    New(ref result._data->Assignments, ref result._data->AssignmentsCount, ref result._data->AssignmentsCapacity, 1);
                    New(ref result._data->Uses, ref result._data->UsesCount, ref result._data->UsesCapacity, 4);
                }

                return(result);
            }
Esempio n. 28
0
 public Operand(OperandKind kind, ushort value)
 {
     this.Kind  = kind;
     this.Value = value;
 }