Example #1
0
 public ThrowStatement(
     Location location,
     InstructionId exceptionThrowerInstruction)
     : base(location)
 {
     ExceptionThrowerInstruction = exceptionThrowerInstruction;
 }
Example #2
0
 internal void Emit(InstructionId instructionId, Operand o0, Operand o1, Operand o2)
 {
     o0 = o0 ?? Operand.Invalid;
     o1 = o1 ?? Operand.Invalid;
     o2 = o2 ?? Operand.Invalid;
     _codeBuffer.Emit(instructionId, o0, o1, o2, Operand.Invalid, _instructionOptions);
 }
Example #3
0
 public ExceptionStatement(
     Location location,
     InstructionId parentExceptionThrowerInstruction)
     : base(location)
 {
     ParentExceptionThrowerInstruction = parentExceptionThrowerInstruction;
 }
 public Instruction(InstructionId instructionId, char firstRegister)
 {
     InstructionId  = instructionId;
     FirstRegister  = firstRegister;
     SecondRegister = null;
     FirstConstant  = null;
     SecondConstant = null;
 }
 public Instruction(InstructionId instructionId,
                    long firstConstant, long secondConstant)
 {
     InstructionId  = instructionId;
     FirstRegister  = null;
     SecondRegister = null;
     FirstConstant  = firstConstant;
     SecondConstant = secondConstant;
 }
Example #6
0
 public FinallyStatement(
     Location location,
     InstructionId bodyStart,
     InstructionId finallyBlockStart)
     : base(location)
 {
     BodyStart         = new Continuation(bodyStart);
     FinallyBlockStart = new Continuation(finallyBlockStart);
 }
 public Instruction(InstructionId instructionId,
                    long firstConstant,
                    char secondRegister)
 {
     InstructionId  = instructionId;
     FirstRegister  = null;
     SecondRegister = secondRegister;
     FirstConstant  = firstConstant;
     SecondConstant = null;
 }
Example #8
0
 public CatchStatement(
     Location location,
     InstructionId exceptionThrowerInstruction,
     InstructionId bodyBlockStart,
     InstructionId catchBlockStart)
     : base(location)
 {
     ExceptionThrowerInstruction = exceptionThrowerInstruction;
     BodyBlockStart  = new Continuation(bodyBlockStart);
     CatchBlockStart = new Continuation(catchBlockStart);
 }
Example #9
0
        private void CreateInstructionNode(InstructionId instructionId, Operand[] operands)
        {
            var options = _assembler.GetInstructionOptionsAndReset();

            if (instructionId.IsJump())
            {
                LabelNode     target = null;
                JumpNode      next   = null;
                CodeNodeFlags flags  = 0;
                if (!options.IsSet(InstructionOptions.Unfollow))
                {
                    if (operands[0].IsLabel())
                    {
                        target = _assembler.GetLabelData(operands[0].Id).ContextData;
                    }
                    else
                    {
                        options |= InstructionOptions.Unfollow;
                    }
                }
                flags |= instructionId == InstructionId.Jmp ? CodeNodeFlags.Jmp | CodeNodeFlags.Taken : CodeNodeFlags.Jcc;

                if (target != null)
                {
                    next = target.From;
                }

                // The 'jmp' is always taken, conditional jump can contain hint, we detect it.
                if (instructionId == InstructionId.Jmp)
                {
                    flags |= CodeNodeFlags.Taken;
                }
                else if (options.IsSet(InstructionOptions.Taken))
                {
                    flags |= CodeNodeFlags.Taken;
                }

                var node = new JumpNode(instructionId, options, operands);
                node.Flags |= flags;
                node.Target = target;
                if (target != null)
                {
                    node.NextJump = next;
                    target.From   = node;
                    target.ReferenceCount++;
                }
                AddNode(node);
                return;
            }
            var inst = new InstructionNode(instructionId, options, operands);

            AddNode(inst);
        }
Example #10
0
        private static void PrepareSingleVariableInstruction(InstructionId instId, VariableAttributes va)
        {
            switch (instId)
            {
            // - andn     reg, reg ; Set all bits in reg to 0.
            // - xor/pxor reg, reg ; Set all bits in reg to 0.
            // - sub/psub reg, reg ; Set all bits in reg to 0.
            // - pcmpgt   reg, reg ; Set all bits in reg to 0.
            // - pcmpeq   reg, reg ; Set all bits in reg to 1.
            case InstructionId.Pandn:
            case InstructionId.Xor:
            case InstructionId.Xorpd:
            case InstructionId.Xorps:
            case InstructionId.Pxor:
            case InstructionId.Sub:
            case InstructionId.Psubb:
            case InstructionId.Psubw:
            case InstructionId.Psubd:
            case InstructionId.Psubq:
            case InstructionId.Psubsb:
            case InstructionId.Psubsw:
            case InstructionId.Psubusb:
            case InstructionId.Psubusw:
            case InstructionId.Pcmpeqb:
            case InstructionId.Pcmpeqw:
            case InstructionId.Pcmpeqd:
            case InstructionId.Pcmpeqq:
            case InstructionId.Pcmpgtb:
            case InstructionId.Pcmpgtw:
            case InstructionId.Pcmpgtd:
            case InstructionId.Pcmpgtq:
                va.Flags &= ~VariableFlags.RReg;
                break;

            // - and      reg, reg ; Nop.
            // - or       reg, reg ; Nop.
            // - xchg     reg, reg ; Nop.
            case InstructionId.And:
            case InstructionId.Andpd:
            case InstructionId.Andps:
            case InstructionId.Pand:
            case InstructionId.Or:
            case InstructionId.Orpd:
            case InstructionId.Orps:
            case InstructionId.Por:
            case InstructionId.Xchg:
                va.Flags &= ~VariableFlags.WReg;
                break;
            }
        }
Example #11
0
 public InstructionNode(InstructionId instructionId, InstructionOptions instructionOptions, Operand[] operands)
     : base(CodeNodeType.Instruction)
 {
     InstructionId      = instructionId;
     InstructionOptions = instructionOptions;
     Operands           = operands;
     MemoryOperandIndex = Constants.InvalidValue;
     for (var i = 0; i < operands.Length; i++)
     {
         if (!operands[i].IsMemory())
         {
             continue;
         }
         MemoryOperandIndex = i;
         break;
     }
     Flags |= CodeNodeFlags.Removable;
 }
        public (IInstruction Instruction, int AdditionalBytes) Read(byte[] data, int start = 0, int?length = null)
        {
            length = RangeUtils.Calculate(data.Length, start, length);

            if (length < 0)
            {
                throw new ArgumentException();
            }
            else if (length < 2)
            {
                return(null, 2 - length.Value);
            }
            else
            {
                InstructionId id = GetInstructionId(data, start);
                if (instructions.TryGetValue(id, out InstructionReader reader))
                {
                    return(reader.Read(data, start, length));
                }

                throw new InvalidOperationException($"No reader registered for {id}.");
            }
        }
Example #13
0
 internal void Emit(InstructionId instructionId, Operand o0, Operand o1, Operand o2, Operand o3, Operand o4)
 {
     CreateInstructionNode(instructionId, new[] { o0, o1, o2, o3, o4 });
 }
Example #14
0
 internal void Emit(InstructionId instructionId, Operand o0, Operand o1, Operand o2, ulong o3)
 {
     CreateInstructionNode(instructionId, new[] { o0, o1, o2, new Immediate(o3), });
 }
Example #15
0
 internal void Emit(InstructionId instructionId, Operand o0, Operand o1, long o2)
 {
     CreateInstructionNode(instructionId, new[] { o0, o1, new Immediate(o2), });
 }
Example #16
0
 internal void Emit(InstructionId instructionId, Operand o0, Operand o1)
 {
     CreateInstructionNode(instructionId, new[] { o0, o1 });
 }
Example #17
0
 internal void Emit(InstructionId instructionId, Operand o0, ulong o1)
 {
     CreateInstructionNode(instructionId, new[] { o0, new Immediate(o1) });
 }
Example #18
0
 internal void Emit(InstructionId instructionId, ulong o0)
 {
     CreateInstructionNode(instructionId, new Operand[] { new Immediate(o0) });
 }
Example #19
0
 internal void Emit(InstructionId instructionId, Operand o0, Operand o1, Operand o2, Operand o3, InstructionOptions options)
 {
     _instructionOptions = options;
     Emit(instructionId, o0, o1, o2, o3);
 }
Example #20
0
 internal void Emit(InstructionId instructionId)
 {
     _codeBuffer.Emit(instructionId, Operand.Invalid, Operand.Invalid, Operand.Invalid, Operand.Invalid, _instructionOptions);
 }
Example #21
0
 internal void Emit(InstructionId instructionId, Operand o0)
 {
     o0 = o0 ?? Operand.Invalid;
     _codeBuffer.Emit(instructionId, o0, Operand.Invalid, Operand.Invalid, Operand.Invalid, _instructionOptions);
 }
        public static string GetDescription(this InstructionId instructionId)
        {
            var fi = instructionId.GetType().GetField(instructionId.ToString());

            return(fi.GetCustomAttributes(typeof(DescriptionAttribute), false) is DescriptionAttribute[] attributes && attributes.Length > 0 ? attributes[0].Description : null);
        }
Example #23
0
 internal void Emit(InstructionId instructionId)
 {
     CreateInstructionNode(instructionId, new Operand[0]);
 }
Example #24
0
 public JumpNode(InstructionId instructionId, InstructionOptions instructionOptions, Operand[] operands)
     : base(instructionId, instructionOptions, operands)
 {
 }
 public override string ToString()
 {
     return(InstructionId.GetDescription() + " " +
            (FirstRegister ?? FirstConstant.Value) + " " +
            (FirstRegister.HasValue ? (FirstConstant ?? SecondRegister.Value) : (SecondRegister ?? SecondConstant.Value)));
 }