source: src/Tuples/Explode.cc @ 5f5083e

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 5f5083e was 141b786, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

rework UniqueExpr?, handle UniqueExpr? in FixInit?, fix translation for UniqueExprs?, refactor explode functions and fix AddressExpr? distribution over exploded tuple exprs

  • Property mode set to 100644
File size: 2.8 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// Explode.cc --
8//
9// Author           : Rob Schluntz
10// Created On       : Wed Nov 9 13:12:24 2016
11// Last Modified By : Rob Schluntz
12// Last Modified On : Wed Nov 9 13:20:24 2016
13// Update Count     : 2
14//
15
16#include "Explode.h"
17#include "SynTree/Mutator.h"
18
19namespace Tuples {
20        namespace {
21                struct AddrExploder : public Mutator {
22                        bool foundUniqueExpr = false;
23                        Expression * applyAddr( Expression * expr, bool first = true ) {
24                                if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( expr ) ){
25                                        std::list< Expression * > exprs;
26                                        for ( Expression *& expr : tupleExpr->get_exprs() ) {
27                                                // move & into tuple exprs
28                                                exprs.push_back( applyAddr( expr, false ) );
29                                        }
30                                        // want the top-level expression to be address-taken, but not nested
31                                        // tuple expressions
32                                        if ( first ) {
33                                                return new AddressExpr( new TupleExpr( exprs ) );
34                                        } else {
35                                                return new TupleExpr( exprs );
36                                        }
37                                }
38                                // anything else should be address-taken as normal
39                                return new AddressExpr( expr->clone() );
40                        }
41
42                        virtual Expression * mutate( UniqueExpr * uniqueExpr ) {
43                                // move & into unique expr so that the unique expr has type T* rather than
44                                // type T. In particular, this transformation helps with generating the
45                                // correct code for address-taken member tuple expressions, since the result
46                                // should now be a tuple of addresses rather than the address of a tuple.
47                                // Still, this code is a bit awkward, and could use some improvement.
48                                foundUniqueExpr = true;
49                                UniqueExpr * newUniqueExpr = new UniqueExpr( applyAddr( uniqueExpr->get_expr() ), uniqueExpr->get_id() );
50                                delete uniqueExpr;
51                                UntypedExpr * deref = UntypedExpr::createDeref( Mutator::mutate( newUniqueExpr ) );
52                                return deref;
53                        }
54
55                        virtual Expression * mutate( TupleIndexExpr * tupleExpr ) {
56                                // tuple index expr needs to be rebuilt to ensure that the type of the
57                                // field is consistent with the type of the tuple expr, since the field
58                                // may have changed from type T to T*.
59                                Expression * expr = tupleExpr->get_tuple()->acceptMutator( *this );
60                                tupleExpr->set_tuple( nullptr );
61                                TupleIndexExpr * ret = new TupleIndexExpr( expr, tupleExpr->get_index() );
62                                delete tupleExpr;
63                                return ret;
64                        }
65                };
66        } // namespace
67
68        Expression * distributeAddr( Expression * expr ) {
69                AddrExploder addrExploder;
70                expr = expr->acceptMutator( addrExploder );
71                if ( ! addrExploder.foundUniqueExpr ) {
72                        expr = new AddressExpr( expr );
73                }
74                return expr;
75        }
76} // namespace Tuples
77
78// Local Variables: //
79// tab-width: 4 //
80// mode: c++ //
81// compile-command: "make install" //
82// End: //
Note: See TracBrowser for help on using the repository browser.