private void ProcessConditionalStatement(IConditionalStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } HLLocation locationCondition = ProcessExpression(pStatement.Condition); HLInstructionBlock blockParent = mCurrentBlock; HLInstructionBlock blockTrueStart = CreateBlock(CreateLabel()); mCurrentBlock = blockTrueStart; ProcessStatement(pStatement.TrueBranch); HLInstructionBlock blockTrueEnd = mCurrentBlock; HLInstructionBlock blockFalseStart = CreateBlock(CreateLabel()); mCurrentBlock = blockFalseStart; ProcessStatement(pStatement.FalseBranch); HLInstructionBlock blockFalseEnd = mCurrentBlock; blockParent.EmitBranch(locationCondition, blockTrueStart.StartLabel, blockFalseStart.StartLabel); if (!blockTrueEnd.Terminated || !blockFalseEnd.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); blockTrueEnd.Terminate(mCurrentBlock.StartLabel); blockFalseEnd.Terminate(mCurrentBlock.StartLabel); } }
private void ProcessEmptyStatement(IEmptyStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } }
private HLLocation ProcessConditionalExpression(IConditional pExpression) { HLLocation locationCondition = ProcessExpression(pExpression.Condition); HLInstructionBlock blockParent = mCurrentBlock; HLLocation locationResult = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); HLInstructionBlock blockTrueStart = CreateBlock(CreateLabel()); mCurrentBlock = blockTrueStart; HLLocation locationTrue = ProcessExpression(pExpression.ResultIfTrue); mCurrentBlock.EmitAssignment(locationResult, locationTrue); HLInstructionBlock blockTrueEnd = mCurrentBlock; HLInstructionBlock blockFalseStart = CreateBlock(CreateLabel()); mCurrentBlock = blockFalseStart; HLLocation locationFalse = ProcessExpression(pExpression.ResultIfFalse); mCurrentBlock.EmitAssignment(locationResult, locationFalse); HLInstructionBlock blockFalseEnd = mCurrentBlock; blockParent.EmitBranch(locationCondition, blockTrueStart.StartLabel, blockFalseStart.StartLabel); mCurrentBlock = CreateBlock(CreateLabel()); blockTrueEnd.Terminate(mCurrentBlock.StartLabel); blockFalseEnd.Terminate(mCurrentBlock.StartLabel); return(locationResult); }
public HLInstructionBlock CreateBlock(HLLabel pStartLabel) { HLInstructionBlock block = HLInstructionBlock.Create(this, pStartLabel); mBlocks.Add(block); return(block); }
internal void Process() { if (Definition.IsExternal) { return; } ISourceMethodBody sourceMethodBody = null; if (Definition.Body is ISourceMethodBody) { sourceMethodBody = (ISourceMethodBody)Definition.Body; } else { sourceMethodBody = Decompiler.GetCodeModelFromMetadataModel(HLDomain.Host, Definition.Body, null); } mCurrentBlock = CreateBlock(CreateLabel()); ProcessStatement(sourceMethodBody.Block); mCurrentBlock.Terminate(null); List <string> buf = new List <string>(); foreach (HLInstructionBlock block in mBlocks) { foreach (HLInstruction instruction in block.Instructions) { buf.Add(instruction.ToString()); } } }
public static HLInstructionBlock Create(HLMethod pMethod, HLLabel pStartLabel) { HLInstructionBlock block = new HLInstructionBlock(); block.mMethod = pMethod; block.mStartLabel = pStartLabel; block.EmitLabel(pStartLabel); return block; }
public static HLInstructionBlock Create(HLMethod pMethod, HLLabel pStartLabel) { HLInstructionBlock block = new HLInstructionBlock(); block.mMethod = pMethod; block.mStartLabel = pStartLabel; block.EmitLabel(pStartLabel); return(block); }
private void ProcessExpressionStatement(IExpressionStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } ProcessExpression(pStatement.Expression); }
private void ProcessLabeledStatement(ILabeledStatement pStatement) { HLLabel labelTarget = null; if (!mRemappedLabels.TryGetValue(pStatement.Label.Value, out labelTarget)) { labelTarget = CreateLabel(); mRemappedLabels.Add(pStatement.Label.Value, labelTarget); } mCurrentBlock.Terminate(labelTarget); mCurrentBlock = CreateBlock(labelTarget); ProcessStatement(pStatement.Statement); }
private void ProcessReturnStatement(IReturnStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } HLLocation locationExpression = null; if (pStatement.Expression != null) { locationExpression = ProcessExpression(pStatement.Expression); } mCurrentBlock.EmitReturn(locationExpression); }
private void ProcessSwitchStatement(ISwitchStatement pStatement) { //if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); HLLocation locationCondition = ProcessExpression(pStatement.Expression); HLInstructionBlock blockParent = mCurrentBlock; List <HLInstructionBlock> blocksStarts = new List <HLInstructionBlock>(); List <HLInstructionBlock> blocksEnds = new List <HLInstructionBlock>(); HLInstructionBlock blockDefaultCase = null; List <Tuple <HLLiteralLocation, HLLabel> > cases = new List <Tuple <HLLiteralLocation, HLLabel> >(); foreach (ISwitchCase switchCase in pStatement.Cases) { HLInstructionBlock blockCase = CreateBlock(CreateLabel()); mCurrentBlock = blockCase; blocksStarts.Add(blockCase); if (switchCase.IsDefault) { blockDefaultCase = blockCase; } else { HLLiteralLocation locationCase = (HLLiteralLocation)ProcessCompileTimeConstantExpression(switchCase.Expression); cases.Add(new Tuple <HLLiteralLocation, HLLabel>(locationCase, blockCase.StartLabel)); } foreach (IStatement statementCase in switchCase.Body) { ProcessStatement(statementCase); } blocksEnds.Add(mCurrentBlock); } if (blockDefaultCase == null) { blockDefaultCase = CreateBlock(CreateLabel()); mCurrentBlock = blockDefaultCase; blocksStarts.Add(blockDefaultCase); blocksEnds.Add(blockDefaultCase); } blockParent.EmitSwitch(locationCondition, blockDefaultCase.StartLabel, cases); if (!blocksEnds.TrueForAll(b => b.Terminated)) { mCurrentBlock = CreateBlock(CreateLabel()); blocksEnds.ForEach(b => b.Terminate(mCurrentBlock.StartLabel)); } }
private void ProcessLocalDeclarationStatement(ILocalDeclarationStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } if (pStatement.InitialValue == null) { return; } HLLocation locationLocalVariable = HLLocalLocation.Create(HLDomain.GetLocal(pStatement.LocalVariable)); HLLocation locationInitialValue = ProcessExpression(pStatement.InitialValue); mCurrentBlock.EmitAssignment(locationLocalVariable, locationInitialValue); }
private void ProcessGotoStatement(IGotoStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } HLLabel labelTarget = null; if (!mRemappedLabels.TryGetValue(pStatement.TargetStatement.Label.Value, out labelTarget)) { labelTarget = CreateLabel(); mRemappedLabels.Add(pStatement.TargetStatement.Label.Value, labelTarget); } mCurrentBlock.EmitGoto(labelTarget); }
internal void Process() { if (Definition.IsExternal) return; ISourceMethodBody sourceMethodBody = null; if (Definition.Body is ISourceMethodBody) sourceMethodBody = (ISourceMethodBody)Definition.Body; else sourceMethodBody = Decompiler.GetCodeModelFromMetadataModel(HLDomain.Host, Definition.Body, null); mCurrentBlock = CreateBlock(CreateLabel()); ProcessStatement(sourceMethodBody.Block); mCurrentBlock.Terminate(null); List<string> buf = new List<string>(); foreach (HLInstructionBlock block in mBlocks) foreach (HLInstruction instruction in block.Instructions) buf.Add(instruction.ToString()); }
private void ProcessConditionalStatement(IConditionalStatement pStatement) { if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); HLLocation locationCondition = ProcessExpression(pStatement.Condition); HLInstructionBlock blockParent = mCurrentBlock; HLInstructionBlock blockTrueStart = CreateBlock(CreateLabel()); mCurrentBlock = blockTrueStart; ProcessStatement(pStatement.TrueBranch); HLInstructionBlock blockTrueEnd = mCurrentBlock; HLInstructionBlock blockFalseStart = CreateBlock(CreateLabel()); mCurrentBlock = blockFalseStart; ProcessStatement(pStatement.FalseBranch); HLInstructionBlock blockFalseEnd = mCurrentBlock; blockParent.EmitBranch(locationCondition, blockTrueStart.StartLabel, blockFalseStart.StartLabel); if (!blockTrueEnd.Terminated || !blockFalseEnd.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); blockTrueEnd.Terminate(mCurrentBlock.StartLabel); blockFalseEnd.Terminate(mCurrentBlock.StartLabel); } }
private void ProcessEmptyStatement(IEmptyStatement pStatement) { if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); }
private void ProcessGotoStatement(IGotoStatement pStatement) { if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); HLLabel labelTarget = null; if (!mRemappedLabels.TryGetValue(pStatement.TargetStatement.Label.Value, out labelTarget)) { labelTarget = CreateLabel(); mRemappedLabels.Add(pStatement.TargetStatement.Label.Value, labelTarget); } mCurrentBlock.EmitGoto(labelTarget); }
private void ProcessExpressionStatement(IExpressionStatement pStatement) { if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); ProcessExpression(pStatement.Expression); }
private HLLocation ProcessConditionalExpression(IConditional pExpression) { HLLocation locationCondition = ProcessExpression(pExpression.Condition); HLInstructionBlock blockParent = mCurrentBlock; HLLocation locationResult = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type))); HLInstructionBlock blockTrueStart = CreateBlock(CreateLabel()); mCurrentBlock = blockTrueStart; HLLocation locationTrue = ProcessExpression(pExpression.ResultIfTrue); mCurrentBlock.EmitAssignment(locationResult, locationTrue); HLInstructionBlock blockTrueEnd = mCurrentBlock; HLInstructionBlock blockFalseStart = CreateBlock(CreateLabel()); mCurrentBlock = blockFalseStart; HLLocation locationFalse = ProcessExpression(pExpression.ResultIfFalse); mCurrentBlock.EmitAssignment(locationResult, locationFalse); HLInstructionBlock blockFalseEnd = mCurrentBlock; blockParent.EmitBranch(locationCondition, blockTrueStart.StartLabel, blockFalseStart.StartLabel); mCurrentBlock = CreateBlock(CreateLabel()); blockTrueEnd.Terminate(mCurrentBlock.StartLabel); blockFalseEnd.Terminate(mCurrentBlock.StartLabel); return locationResult; }
private void ProcessSwitchStatement(ISwitchStatement pStatement) { //if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); HLLocation locationCondition = ProcessExpression(pStatement.Expression); HLInstructionBlock blockParent = mCurrentBlock; List<HLInstructionBlock> blocksStarts = new List<HLInstructionBlock>(); List<HLInstructionBlock> blocksEnds = new List<HLInstructionBlock>(); HLInstructionBlock blockDefaultCase = null; List<Tuple<HLLiteralLocation, HLLabel>> cases = new List<Tuple<HLLiteralLocation, HLLabel>>(); foreach (ISwitchCase switchCase in pStatement.Cases) { HLInstructionBlock blockCase = CreateBlock(CreateLabel()); mCurrentBlock = blockCase; blocksStarts.Add(blockCase); if (switchCase.IsDefault) blockDefaultCase = blockCase; else { HLLiteralLocation locationCase = (HLLiteralLocation)ProcessCompileTimeConstantExpression(switchCase.Expression); cases.Add(new Tuple<HLLiteralLocation, HLLabel>(locationCase, blockCase.StartLabel)); } foreach (IStatement statementCase in switchCase.Body) ProcessStatement(statementCase); blocksEnds.Add(mCurrentBlock); } if (blockDefaultCase == null) { blockDefaultCase = CreateBlock(CreateLabel()); mCurrentBlock = blockDefaultCase; blocksStarts.Add(blockDefaultCase); blocksEnds.Add(blockDefaultCase); } blockParent.EmitSwitch(locationCondition, blockDefaultCase.StartLabel, cases); if (!blocksEnds.TrueForAll(b => b.Terminated)) { mCurrentBlock = CreateBlock(CreateLabel()); blocksEnds.ForEach(b => b.Terminate(mCurrentBlock.StartLabel)); } }
private void ProcessReturnStatement(IReturnStatement pStatement) { if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); HLLocation locationExpression = null; if (pStatement.Expression != null) locationExpression = ProcessExpression(pStatement.Expression); mCurrentBlock.EmitReturn(locationExpression); }
private void ProcessLocalDeclarationStatement(ILocalDeclarationStatement pStatement) { if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); if (pStatement.InitialValue == null) return; HLLocation locationLocalVariable = HLLocalLocation.Create(HLDomain.GetLocal(pStatement.LocalVariable)); HLLocation locationInitialValue = ProcessExpression(pStatement.InitialValue); mCurrentBlock.EmitAssignment(locationLocalVariable, locationInitialValue); }