Exemplo n.º 1
0
        public void Translate(IRInstruction instr, ILTranslator tr)
        {
            tr.PushOperand(instr.Operand1);
            tr.PushOperand(instr.Operand2);
            var type = TypeInference.InferBinaryOp(instr.Operand1.Type, instr.Operand2.Type);

            switch (type)
            {
            case ASTType.I4:
                tr.Instructions.Add(new ILInstruction(ILOpCode.REM_DWORD));
                break;

            case ASTType.I8:
            case ASTType.Ptr:
                tr.Instructions.Add(new ILInstruction(ILOpCode.REM_QWORD));
                break;

            case ASTType.R4:
                tr.Instructions.Add(new ILInstruction(ILOpCode.REM_R32));
                break;

            case ASTType.R8:
                tr.Instructions.Add(new ILInstruction(ILOpCode.REM_R64));
                break;

            default:
                throw new NotSupportedException();
            }
            tr.PopOperand(instr.Operand1);
        }
Exemplo n.º 2
0
        public void Translate(IRInstruction instr, ILTranslator tr)
        {
            tr.PushOperand(instr.Operand1);
            tr.PushOperand(instr.Operand2);

            if (instr.Operand1.Type == ASTType.O || instr.Operand2.Type == ASTType.O)
            {
                tr.Instructions.Add(new ILInstruction(ILOpCode.CMP));
            }

            else if (instr.Operand1.Type == ASTType.I8 || instr.Operand2.Type == ASTType.I8 ||
                     instr.Operand1.Type == ASTType.Ptr || instr.Operand2.Type == ASTType.Ptr)
            {
                tr.Instructions.Add(new ILInstruction(ILOpCode.CMP_QWORD));
            }

            else if (instr.Operand1.Type == ASTType.R8 || instr.Operand2.Type == ASTType.R8)
            {
                tr.Instructions.Add(new ILInstruction(ILOpCode.CMP_R64));
            }

            else if (instr.Operand1.Type == ASTType.R4 || instr.Operand2.Type == ASTType.R4)
            {
                tr.Instructions.Add(new ILInstruction(ILOpCode.CMP_R32));
            }

            else
            {
                tr.Instructions.Add(new ILInstruction(ILOpCode.CMP_DWORD));
            }
        }
Exemplo n.º 3
0
        public void Translate(IRInstruction instr, ILTranslator tr)
        {
            tr.PushOperand(instr.Operand2);
            tr.PushOperand(instr.Operand1);
            var rawType = ((PointerInfo)instr.Annotation).PointerType.ToTypeSig();

            tr.Instructions.Add(new ILInstruction(TranslationHelpers.GetSIND(instr.Operand2.Type, rawType)));
        }
Exemplo n.º 4
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     tr.PushOperand(instr.Operand2);
     tr.PushOperand(instr.Operand1);
     tr.Instructions.Add(new ILInstruction(ILOpCode.JNZ)
     {
         Annotation = InstrAnnotation.JUMP
     });
 }
Exemplo n.º 5
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     if (instr.Operand2 != null)
     {
         tr.PushOperand(instr.Operand2);
     }
     tr.PushOperand(instr.Operand1);
     tr.Instructions.Add(new ILInstruction(ILOpCode.VCALL));
 }
Exemplo n.º 6
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     if (instr.Operand2 != null)
     {
         tr.PushOperand(instr.Operand2);
     }
     tr.PushOperand(instr.Operand1);
     tr.Instructions.Add(new ILInstruction(ILOpCode.TRY)
     {
         Annotation = instr.Annotation
     });
 }
Exemplo n.º 7
0
        public void Translate(IRInstruction instr, ILTranslator tr)
        {
            tr.PushOperand(instr.Operand2);
            switch (instr.Operand2.Type)
            {
            case ASTType.R4:
                Debug.Assert(instr.Operand1.Type == ASTType.R8);
                tr.Instructions.Add(new ILInstruction(ILOpCode.FCONV_R32_R64));
                break;

            case ASTType.R8:
                Debug.Assert(instr.Operand1.Type == ASTType.R4);
                tr.Instructions.Add(new ILInstruction(ILOpCode.FCONV_R64_R32));
                break;

            default:
                Debug.Assert(instr.Operand2.Type == ASTType.I8);
                switch (instr.Operand1.Type)
                {
                case ASTType.R4:
                    tr.Instructions.Add(new ILInstruction(ILOpCode.FCONV_R32));
                    break;

                case ASTType.R8:
                    tr.Instructions.Add(new ILInstruction(ILOpCode.FCONV_R64));
                    break;

                default:
                    throw new NotSupportedException();
                }
                break;
            }
            tr.PopOperand(instr.Operand1);
        }
Exemplo n.º 8
0
        public void Translate(IRInstruction instr, ILTranslator tr)
        {
            tr.PushOperand(instr.Operand2);
            switch (instr.Operand1.Type)
            {
            case ASTType.I4:
                if (instr.Operand1 is IRVariable)
                {
                    var rawType = ((IRVariable)instr.Operand1).RawType.ElementType;
                    if (rawType == ElementType.I2)
                    {
                        tr.Instructions.Add(new ILInstruction(ILOpCode.SX_WORD));
                    }
                }
                tr.Instructions.Add(new ILInstruction(ILOpCode.SX_BYTE));
                break;

            case ASTType.I8:
                tr.Instructions.Add(new ILInstruction(ILOpCode.SX_DWORD));
                break;

            default:
                throw new NotSupportedException();
            }
            tr.PopOperand(instr.Operand1);
        }
Exemplo n.º 9
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     tr.PushOperand(instr.Operand1);
     tr.Instructions.Add(new ILInstruction(ILOpCode.LEAVE)
     {
         Annotation = instr.Annotation
     });
 }
Exemplo n.º 10
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     if (instr.Operand1 != null)
     {
         tr.PushOperand(instr.Operand1);
         tr.Instructions.Add(new ILInstruction(ILOpCode.POP, ILRegister.R0));
     }
     tr.Instructions.Add(new ILInstruction(ILOpCode.RET));
 }
Exemplo n.º 11
0
        public void Translate(IRInstruction instr, ILTranslator tr)
        {
            tr.PushOperand(instr.Operand2);
            tr.PushOperand(instr.Operand1);

            ILInstruction lastInstr = tr.Instructions[tr.Instructions.Count - 1];

            Debug.Assert(lastInstr.OpCode == ILOpCode.PUSHI_DWORD && lastInstr.Operand is ILJumpTable);

            var switchInstr = new ILInstruction(ILOpCode.SWT)
            {
                Annotation = InstrAnnotation.JUMP
            };

            tr.Instructions.Add(switchInstr);

            var jmpTable = (ILJumpTable)lastInstr.Operand;

            jmpTable.Chunk.runtime = tr.Runtime;
            jmpTable.RelativeBase  = switchInstr;
            tr.Runtime.AddChunk(jmpTable.Chunk);
        }
Exemplo n.º 12
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     tr.PushOperand(instr.Operand2);
     tr.PopOperand(instr.Operand1);
 }
Exemplo n.º 13
0
 public void Translate(IRInstruction instr, ILTranslator tr) => tr.PushOperand(instr.Operand1);