From a69b85acbf5f81a1a684156e152e68aa2ae40e99 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 28 Jul 2017 11:05:15 +0200 Subject: Optimise: remove unreachacble ABC-code --- Sil/Compile.icl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Sil/Compile.icl') diff --git a/Sil/Compile.icl b/Sil/Compile.icl index 81196bf..e342a66 100644 --- a/Sil/Compile.icl +++ b/Sil/Compile.icl @@ -47,6 +47,8 @@ where opt ['ABC'.PushI i:'ABC'.Update_b 0 l:'ABC'.Pop_b n:ss] | l == n = ['ABC'.Pop_b n:'ABC'.PushI i:opt ss] opt ['ABC'.Pop_a i:'ABC'.Pop_a j:ss] = opt ['ABC'.Pop_a (i+j):ss] opt ['ABC'.Pop_b i:'ABC'.Pop_b j:ss] = opt ['ABC'.Pop_b (i+j):ss] + opt ['ABC'.Rtn:ss] = ['ABC'.Rtn:opt $ skipUntilEntryPoint ss] + opt ['ABC'.Jmp l:ss] = ['ABC'.Jmp l:opt $ skipUntilEntryPoint ss] opt [s:ss] = [s:opt ss] opt [] = [] @@ -58,6 +60,14 @@ where isUseful ('ABC'.Comment _) = False isUseful _ = True + skipUntilEntryPoint :: 'ABC'.Assembler -> 'ABC'.Assembler + skipUntilEntryPoint ss + | all (\t -> t =: ('ABC'.Annotation _)) before = ss + | otherwise = skipUntilEntryPoint $ tl ss + where + (before,after) = span (not o (\t -> t =: ('ABC'.Label _))) ss + skipUntilEntryPoint [] = [] + :: Address = AAddr Int | BAddr Int -- cgit v1.2.3