Exemplo n.º 1
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.º 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);
            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.º 4
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.º 5
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     tr.Instructions.Add(new ILInstruction(ILOpCode.__ENDCALL)
     {
         Annotation = instr.Annotation
     });
 }
Exemplo n.º 6
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     tr.PushOperand(instr.Operand1);
     tr.Instructions.Add(new ILInstruction(ILOpCode.JMP)
     {
         Annotation = InstrAnnotation.JUMP
     });
 }
Exemplo n.º 7
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     tr.PushOperand(instr.Operand1);
     tr.Instructions.Add(new ILInstruction(ILOpCode.LEAVE)
     {
         Annotation = instr.Annotation
     });
 }
Exemplo n.º 8
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.º 9
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.º 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)
 {
     if (instr.Operand2 != null)
     {
         tr.PushOperand(instr.Operand2);
     }
     tr.PushOperand(instr.Operand1);
     tr.Instructions.Add(new ILInstruction(ILOpCode.TRY)
     {
         Annotation = instr.Annotation
     });
 }
Exemplo n.º 12
0
        public void Should_Translate_Add_Expression()
        {
            var script = "função soma() retorne 2 + 2 fim";

            var bytecode = new Npc().Compilar(script);

            var dm = new ILTranslator(bytecode).Translate();

            var result = dm.Invoke(null, null);

            Assert.AreEqual(4, result);
        }
Exemplo n.º 13
0
        private void CompileHelpers(MethodDef method, ScopeBlock scope)
        {
            var methodCtx = new IRContext(method, method.Body);

            methodCtx.IsRuntime = true;
            var irTransformer = new IRTransformer(scope, methodCtx, rt);

            irTransformer.Transform();

            var ilTranslator  = new ILTranslator(rt);
            var ilTransformer = new ILTransformer(method, scope, rt);

            ilTranslator.Translate(scope);
            ilTransformer.Transform();

            var postTransformer = new ILPostTransformer(method, scope, rt);

            postTransformer.Transform();
        }
Exemplo n.º 14
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.º 15
0
 public void Translate(IRInstruction instr, ILTranslator tr) => tr.Instructions.Add(new ILInstruction(ILOpCode.NOP));
Exemplo n.º 16
0
        protected virtual void BuildVMIL()
        {
            var translator = new ILTranslator(Runtime);

            translator.Translate(RootScope);
        }
Exemplo n.º 17
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     tr.Instructions.Add(new ILInstruction(ILOpCode.__EXIT));
 }
Exemplo n.º 18
0
 public void Translate(IRInstruction instr, ILTranslator tr) => tr.PopOperand(instr.Operand1);
Exemplo n.º 19
0
 public abstract void ApplyTo(ILTranslator translator);
Exemplo n.º 20
0
 public void Translate(IRInstruction instr, ILTranslator tr)
 {
     tr.PushOperand(instr.Operand2);
     tr.PopOperand(instr.Operand1);
 }
 public Blanket Process(ITextProcessor input)
 {
     ILTranslator.Compile(Path.GetFileNameWithoutExtension(_outpFile), true, input.Presentation.ToList());
     //input.SaveToFile(outpFile);
     return null;
 }