[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 | //
|
---|
| 7 | // Tuples.h --
|
---|
| 8 | //
|
---|
| 9 | // Author : Andrew Beach
|
---|
| 10 | // Created On : Mon Jun 17 14:41:00 2019
|
---|
| 11 | // Last Modified By : Andrew Beach
|
---|
[bc92bee] | 12 | // Last Modified On : Tue Jun 18 9:31:00 2019
|
---|
| 13 | // Update Count : 1
|
---|
[b910d15] | 14 | //
|
---|
| 15 |
|
---|
| 16 | #include "Tuples.h"
|
---|
| 17 |
|
---|
| 18 | #include "AST/Pass.hpp"
|
---|
| 19 | #include "AST/LinkageSpec.hpp"
|
---|
| 20 | #include "InitTweak/InitTweak.h"
|
---|
| 21 |
|
---|
| 22 | namespace Tuples {
|
---|
| 23 |
|
---|
| 24 | namespace {
|
---|
| 25 | /// Determines if impurity (read: side-effects) may exist in a piece of code. Currently gives
|
---|
| 26 | /// a very crude approximation, wherein any function call expression means the code may be
|
---|
| 27 | /// impure.
|
---|
| 28 | struct ImpurityDetector : public ast::WithShortCircuiting {
|
---|
| 29 | bool maybeImpure = false;
|
---|
| 30 |
|
---|
| 31 | void previsit( ast::ApplicationExpr const * appExpr ) {
|
---|
| 32 | if ( ast::DeclWithType const * function = InitTweak::getFunction( appExpr ) ) {
|
---|
| 33 | if ( function->linkage == ast::Linkage::Intrinsic
|
---|
| 34 | && ( function->name == "*?" || function->name == "?[?]" ) ) {
|
---|
| 35 | return;
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
[bc92bee] | 38 | maybeImpure = true; visit_children = false;
|
---|
[b910d15] | 39 | }
|
---|
| 40 | void previsit( ast::UntypedExpr const * ) {
|
---|
| 41 | maybeImpure = true; visit_children = false;
|
---|
| 42 | }
|
---|
[bc92bee] | 43 | };
|
---|
| 44 | struct ImpurityDetectorIgnoreUnique : public ImpurityDetector {
|
---|
[b910d15] | 45 | void previsit( ast::UniqueExpr const * ) {
|
---|
[bc92bee] | 46 | visit_children = false;
|
---|
[b910d15] | 47 | }
|
---|
| 48 | };
|
---|
| 49 |
|
---|
[bc92bee] | 50 | template<typename Detector>
|
---|
| 51 | bool detectImpurity( const ast::Expr * expr ) {
|
---|
| 52 | ast::Pass<Detector> detector;
|
---|
[b910d15] | 53 | expr->accept( detector );
|
---|
| 54 | return detector.pass.maybeImpure;
|
---|
| 55 | }
|
---|
| 56 | } // namespace
|
---|
| 57 |
|
---|
[bc92bee] | 58 | bool maybeImpure( const ast::Expr * expr ) {
|
---|
| 59 | return detectImpurity<ImpurityDetector>( expr );
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[b910d15] | 62 | bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
|
---|
[bc92bee] | 63 | return detectImpurity<ImpurityDetectorIgnoreUnique>( expr );
|
---|
[b910d15] | 64 | }
|
---|
| 65 |
|
---|
| 66 | } // namespace Tuples
|
---|
| 67 |
|
---|
| 68 | // Local Variables: //
|
---|
| 69 | // tab-width: 4 //
|
---|
| 70 | // mode: c++ //
|
---|
| 71 | // compile-command: "make install" //
|
---|
| 72 | // End: //
|
---|