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 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); } }