diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/go/gofrontend/dataflow.h | |
download | cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.bz2 cbb-gcc-4.6.4-15d2061ac0796199866debe9ac87130894b0cdd3.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/go/gofrontend/dataflow.h')
-rw-r--r-- | gcc/go/gofrontend/dataflow.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/dataflow.h b/gcc/go/gofrontend/dataflow.h new file mode 100644 index 000000000..a75c8e661 --- /dev/null +++ b/gcc/go/gofrontend/dataflow.h @@ -0,0 +1,91 @@ +// dataflow.h -- Go frontend dataflow. -*- C++ -*- + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#ifndef GO_DATAFLOW_H +#define GO_DATAFLOW_H + +class Expression; +class Named_object; +class Statement; + +// Dataflow information about the Go program. + +class Dataflow +{ + public: + // A variable definition. + struct Def + { + // The statement where the variable is defined. + Statement* statement; + // The value to which the variable is set. This may be NULL. + Expression* val; + // Whether this is an initialization of the variable. + bool is_init; + }; + + // A variable reference. + struct Ref + { + // The statement where the variable is referenced. + Statement* statement; + }; + + // A list of defs. + typedef std::vector<Def> Defs; + + // A list of refs. + typedef std::vector<Ref> Refs; + + Dataflow(); + + // Initialize the dataflow information. + void + initialize(Gogo*); + + // Add a definition of a variable. STATEMENT assigns a value to + // VAR. VAL is the value if it is known, NULL otherwise. + void + add_def(Named_object* var, Expression* val, Statement* statement, + bool is_init); + + // Add a reference to a variable. VAR is the variable, and + // STATEMENT is the statement which refers to it. + void + add_ref(Named_object* var, Statement* statement); + + // Return the definitions of VAR--the places where it is set. + const Defs* + find_defs(Named_object* var) const; + + // Return the references to VAR--the places where it is used. + const Refs* + find_refs(Named_object* var) const; + + private: + // Order variables in the map. + struct Compare_vars + { + bool + operator()(const Named_object*, const Named_object*) const; + }; + + // Map from variables to a list of defs of the variable. We use a + // map rather than a hash table because the order in which we + // process variables may affect the resulting code. + typedef std::map<Named_object*, Defs*, Compare_vars> Defmap; + + // Map from variables to a list of refs to the vairable. + typedef std::map<Named_object*, Refs*, Compare_vars> Refmap; + + // Variable defs. + Defmap defs_; + // Variable refs; + Refmap refs_; +}; + + +#endif // !defined(GO_DATAFLOW_H) |