diff options
author | Camil Staps | 2017-07-19 19:42:47 +0000 |
---|---|---|
committer | Camil Staps | 2017-07-19 19:42:47 +0000 |
commit | bb52dc5e385a011f928f7a6c8b8497563a31c464 (patch) | |
tree | e44caeaa5a3cd89d48d9027fe2a4c2c820644d52 /Sil/Syntax.icl | |
parent | Discard unused application results (diff) |
Add AST checks
Diffstat (limited to 'Sil/Syntax.icl')
-rw-r--r-- | Sil/Syntax.icl | 27 |
1 files changed, 27 insertions, 0 deletions
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 |