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); }
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)); } }
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); }
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); }
public void Translate(IRInstruction instr, ILTranslator tr) { tr.Instructions.Add(new ILInstruction(ILOpCode.__ENDCALL) { Annotation = instr.Annotation }); }
public void Translate(IRInstruction instr, ILTranslator tr) { tr.PushOperand(instr.Operand1); tr.Instructions.Add(new ILInstruction(ILOpCode.JMP) { Annotation = InstrAnnotation.JUMP }); }
public void Translate(IRInstruction instr, ILTranslator tr) { tr.PushOperand(instr.Operand1); tr.Instructions.Add(new ILInstruction(ILOpCode.LEAVE) { Annotation = instr.Annotation }); }
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))); }
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)); }
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)); }
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 }); }
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); }
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(); }
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); }
public void Translate(IRInstruction instr, ILTranslator tr) => tr.Instructions.Add(new ILInstruction(ILOpCode.NOP));
protected virtual void BuildVMIL() { var translator = new ILTranslator(Runtime); translator.Translate(RootScope); }
public void Translate(IRInstruction instr, ILTranslator tr) { tr.Instructions.Add(new ILInstruction(ILOpCode.__EXIT)); }
public void Translate(IRInstruction instr, ILTranslator tr) => tr.PopOperand(instr.Operand1);
public abstract void ApplyTo(ILTranslator translator);
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; }