public FinallyBlockState(FinallyBlockState outerBlock, int depth, AstCompilerVisitor compiler, Instruction first, Instruction last) { _compiler = compiler; NonException = new Instruction(); AfterExceptionCheck = new Instruction(); FirstInstruction = first; LastInstruction = last; Depth = depth; OuterFinallyBlock = outerBlock; }
public RLRange Exit(AstCompilerVisitor compVisit, AstExpression node, List<RLRange> args) { var reg = GetMonitorRegister(compVisit, node); if (reg != null) { var first = compVisit.Add(node.SourceLocation, RCode.Move_object, reg, args[0].Result); var second = compVisit.Add(node.SourceLocation, RCode.Monitor_exit, reg); return new RLRange(first, second, null); } // default handling return new RLRange(compVisit.Add(node.SourceLocation, RCode.Monitor_exit, args[0].Result), null); }
public RLRange Exit(AstCompilerVisitor compVisit, AstExpression node, List <RLRange> args) { var reg = GetMonitorRegister(compVisit, node); if (reg != null) { var first = compVisit.Add(node.SourceLocation, RCode.Move_object, reg, args[0].Result); var second = compVisit.Add(node.SourceLocation, RCode.Monitor_exit, reg); return(new RLRange(first, second, null)); } // default handling return(new RLRange(compVisit.Add(node.SourceLocation, RCode.Monitor_exit, args[0].Result), null)); }
public Register GetMonitorRegister(AstCompilerVisitor compVisit, AstExpression node) { // this code is still experimental, and possibly does not handle all cases. var operand = node.Arguments[0].Operand; Register reg = null; if (operand is XFieldReference) { if (!_monitorUsage.TryGetValue(operand, out reg)) { reg = compVisit.Frame.AllocateTemp(FrameworkReferences.Object); _monitorUsage.Add(operand, reg); } } return(reg); }
public Register GetMonitorRegister(AstCompilerVisitor compVisit, AstExpression node) { // this code is still experimental, and possibly does not handle all cases. var operand = node.Arguments[0].Operand; Register reg = null; if (operand is XFieldReference) { if (!_monitorUsage.TryGetValue(operand, out reg)) { reg = compVisit.Frame.AllocateTemp(FrameworkReferences.Object); _monitorUsage.Add(operand, reg); } } return reg; }
/// <summary> /// Create a method body for the given method. /// </summary> internal static MethodBody TranslateToRL(AssemblyCompiler compiler, DexTargetPackage targetPackage, MethodSource source, MethodDefinition dmethod, bool generateSetNextInstructionCode, out CompiledMethod compiledMethod) { try { #if DEBUG //Debugger.Launch(); if ((source.Method != null) && (source.Method.Name == "test6")) { //Debugger.Launch(); } #endif // Create Ast var optimizedAst = CreateOptimizedAst(compiler, source, generateSetNextInstructionCode); // Generate RL code var rlBody = new MethodBody(source); var rlGenerator = new AstCompilerVisitor(compiler, source, targetPackage, dmethod, rlBody); optimizedAst.Accept(rlGenerator, null); rlGenerator.Complete(); // Should we add return_void? if (source.ReturnsVoid) { var instructions = rlBody.Instructions; if ((instructions.Count == 0) || (instructions.Last().Code != RCode.Return_void && instructions.Last().Code != RCode.Throw)) { instructions.Add(new RL.Instruction(RCode.Return_void) { SequencePoint = source.GetLastSourceLine() }); } } // Record results compiledMethod = targetPackage.Record(source, rlBody, rlGenerator.Frame); return rlBody; } catch (Exception ex) { // Forward exception with more information var msg = string.Format("Error while compiling {0} in {1}: {2}", source.FullName, source.DeclaringTypeFullName, ex.Message); throw new CompilerException(msg, ex); } }
public FinallyBlockState(FinallyBlockState outerBlock, int depth, AstCompilerVisitor compiler, Instruction first, Instruction last) { _compiler = compiler; NonException = new Instruction(); AfterExceptionCheck = new Instruction(); FirstInstruction = first; LastInstruction = last; Depth = depth; OuterFinallyBlock = outerBlock; }