source: src/Tuples/Tuples.cc @ 8f2f185

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 8f2f185 was 7ff3e522, checked in by Andrew Beach <ajbeach@…>, 4 years ago

{pass_t Pass::pass; => core_t Pass::core;} To avoid confusion about which pass we are talking about.

  • Property mode set to 100644
File size: 2.0 KB
Line 
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
12// Last Modified On : Tue Jun 18  9:31:00 2019
13// Update Count     : 1
14//
15
16#include "Tuples.h"
17
18#include "AST/Pass.hpp"
19#include "AST/LinkageSpec.hpp"
20#include "InitTweak/InitTweak.h"
21
22namespace Tuples {
23
24namespace {
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                        }
38                        maybeImpure = true; visit_children = false;
39                }
40                void previsit( ast::UntypedExpr const * ) {
41                        maybeImpure = true; visit_children = false;
42                }
43        };
44        struct ImpurityDetectorIgnoreUnique : public ImpurityDetector {
45                using ImpurityDetector::previsit;
46                void previsit( ast::UniqueExpr const * ) {
47                        visit_children = false;
48                }
49        };
50
51        template<typename Detector>
52        bool detectImpurity( const ast::Expr * expr ) {
53                ast::Pass<Detector> detector;
54                expr->accept( detector );
55                return detector.core.maybeImpure;
56        }
57} // namespace
58
59bool maybeImpure( const ast::Expr * expr ) {
60        return detectImpurity<ImpurityDetector>( expr );
61}
62
63bool maybeImpureIgnoreUnique( const ast::Expr * expr ) {
64        return detectImpurity<ImpurityDetectorIgnoreUnique>( expr );
65}
66
67} // namespace Tuples
68
69// Local Variables: //
70// tab-width: 4 //
71// mode: c++ //
72// compile-command: "make install" //
73// End: //
Note: See TracBrowser for help on using the repository browser.