[b910d15] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[11df881] | 7 | // Tuples.cc -- A collection of tuple operations. |
---|
[b910d15] | 8 | // |
---|
| 9 | // Author : Andrew Beach |
---|
| 10 | // Created On : Mon Jun 17 14:41:00 2019 |
---|
| 11 | // Last Modified By : Andrew Beach |
---|
[9939dc3] | 12 | // Last Modified On : Mon May 16 16:15:00 2022 |
---|
| 13 | // Update Count : 2 |
---|
[b910d15] | 14 | // |
---|
| 15 | |
---|
| 16 | #include "Tuples.h" |
---|
| 17 | |
---|
| 18 | #include "AST/Pass.hpp" |
---|
[e01eb4a] | 19 | #include "AST/Inspect.hpp" |
---|
[b910d15] | 20 | #include "AST/LinkageSpec.hpp" |
---|
| 21 | #include "InitTweak/InitTweak.h" |
---|
| 22 | |
---|
| 23 | namespace Tuples { |
---|
| 24 | |
---|
| 25 | namespace { |
---|
[9939dc3] | 26 | |
---|
[e580aa5] | 27 | /// Determines if impurity (read: side-effects) may exist in a piece of code. |
---|
| 28 | /// Currently gives a very crude approximation, wherein almost any function |
---|
| 29 | /// call expression means the code may be impure. |
---|
| 30 | struct ImpurityDetector : public ast::WithShortCircuiting { |
---|
| 31 | bool result = false; |
---|
[b910d15] | 32 | |
---|
[e580aa5] | 33 | void previsit( ast::ApplicationExpr const * appExpr ) { |
---|
| 34 | if ( ast::DeclWithType const * function = ast::getFunction( appExpr ) ) { |
---|
| 35 | if ( function->linkage == ast::Linkage::Intrinsic |
---|
| 36 | && ( function->name == "*?" || function->name == "?[?]" ) ) { |
---|
| 37 | return; |
---|
[b910d15] | 38 | } |
---|
| 39 | } |
---|
[e580aa5] | 40 | result = true; visit_children = false; |
---|
| 41 | } |
---|
| 42 | void previsit( ast::UntypedExpr const * ) { |
---|
| 43 | result = true; visit_children = false; |
---|
| 44 | } |
---|
| 45 | }; |
---|
| 46 | |
---|
| 47 | struct ImpurityDetectorIgnoreUnique : public ImpurityDetector { |
---|
| 48 | using ImpurityDetector::previsit; |
---|
| 49 | void previsit( ast::UniqueExpr const * ) { |
---|
| 50 | visit_children = false; |
---|
| 51 | } |
---|
| 52 | }; |
---|
[9939dc3] | 53 | |
---|
[b910d15] | 54 | } // namespace |
---|
| 55 | |
---|
[bc92bee] | 56 | bool maybeImpure( const ast::Expr * expr ) { |
---|
[9939dc3] | 57 | return ast::Pass<ImpurityDetector>::read( expr ); |
---|
[bc92bee] | 58 | } |
---|
| 59 | |
---|
[b910d15] | 60 | bool maybeImpureIgnoreUnique( const ast::Expr * expr ) { |
---|
[9939dc3] | 61 | return ast::Pass<ImpurityDetectorIgnoreUnique>::read( expr ); |
---|
| 62 | } |
---|
| 63 | |
---|
[b910d15] | 64 | } // namespace Tuples |
---|
| 65 | |
---|
| 66 | // Local Variables: // |
---|
| 67 | // tab-width: 4 // |
---|
| 68 | // mode: c++ // |
---|
| 69 | // compile-command: "make install" // |
---|
| 70 | // End: // |
---|