From bb52dc5e385a011f928f7a6c8b8497563a31c464 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 19 Jul 2017 19:42:47 +0000 Subject: Add AST checks --- Sil/Syntax.icl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'Sil/Syntax.icl') diff --git a/Sil/Syntax.icl b/Sil/Syntax.icl index 0056618..f78ba83 100644 --- a/Sil/Syntax.icl +++ b/Sil/Syntax.icl @@ -1,8 +1,11 @@ implementation module Sil.Syntax +from StdFunc import o import StdOverloaded import StdString +import StdTuple +import Data.List import Data.Maybe import Text @@ -54,3 +57,27 @@ instance toString Literal where toString (BLit b) = toString b toString (ILit i) = toString i + +instance allStatements Program +where allStatements p = concatMap allStatements p.p_funs + +instance allStatements Function +where allStatements f = allStatements f.f_code + +instance allStatements CodeBlock +where allStatements cb = concatMap allStatements cb.cb_content + +instance allStatements Statement +where + allStatements st=:(Declaration _ _) = [st] + allStatements st=:(Application _) = [st] + allStatements st=:(Return _) = [st] + allStatements st=:(If bs Nothing) = [st:concatMap (allStatements o snd) bs] + allStatements st=:(If bs (Just e)) = [st:allStatements e ++ concatMap (allStatements o snd) bs] + allStatements st=:(While _ cb) = [st:allStatements cb] + allStatements st=:(MachineStm _) = [st] + +typeSize :: Type -> Int +typeSize TVoid = 0 +typeSize TBool = 1 +typeSize TInt = 1 -- cgit v1.2.3