github.com/pankona/gometalinter@v2.0.11+incompatible/_linters/src/golang.org/x/tools/go/ssa/doc.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package ssa defines a representation of the elements of Go programs
     6  // (packages, types, functions, variables and constants) using a
     7  // static single-assignment (SSA) form intermediate representation
     8  // (IR) for the bodies of functions.
     9  //
    10  // THIS INTERFACE IS EXPERIMENTAL AND IS LIKELY TO CHANGE.
    11  //
    12  // For an introduction to SSA form, see
    13  // http://en.wikipedia.org/wiki/Static_single_assignment_form.
    14  // This page provides a broader reading list:
    15  // http://www.dcs.gla.ac.uk/~jsinger/ssa.html.
    16  //
    17  // The level of abstraction of the SSA form is intentionally close to
    18  // the source language to facilitate construction of source analysis
    19  // tools.  It is not intended for machine code generation.
    20  //
    21  // All looping, branching and switching constructs are replaced with
    22  // unstructured control flow.  Higher-level control flow constructs
    23  // such as multi-way branch can be reconstructed as needed; see
    24  // ssautil.Switches() for an example.
    25  //
    26  // To construct an SSA-form program, call ssautil.CreateProgram on a
    27  // loader.Program, a set of type-checked packages created from
    28  // parsed Go source files.  The resulting ssa.Program contains all the
    29  // packages and their members, but SSA code is not created for
    30  // function bodies until a subsequent call to (*Package).Build.
    31  //
    32  // The builder initially builds a naive SSA form in which all local
    33  // variables are addresses of stack locations with explicit loads and
    34  // stores.  Registerisation of eligible locals and φ-node insertion
    35  // using dominance and dataflow are then performed as a second pass
    36  // called "lifting" to improve the accuracy and performance of
    37  // subsequent analyses; this pass can be skipped by setting the
    38  // NaiveForm builder flag.
    39  //
    40  // The primary interfaces of this package are:
    41  //
    42  //    - Member: a named member of a Go package.
    43  //    - Value: an expression that yields a value.
    44  //    - Instruction: a statement that consumes values and performs computation.
    45  //    - Node: a Value or Instruction (emphasizing its membership in the SSA value graph)
    46  //
    47  // A computation that yields a result implements both the Value and
    48  // Instruction interfaces.  The following table shows for each
    49  // concrete type which of these interfaces it implements.
    50  //
    51  //                      Value?          Instruction?    Member?
    52  //   *Alloc             ✔               ✔
    53  //   *BinOp             ✔               ✔
    54  //   *Builtin           ✔
    55  //   *Call              ✔               ✔
    56  //   *ChangeInterface   ✔               ✔
    57  //   *ChangeType        ✔               ✔
    58  //   *Const             ✔
    59  //   *Convert           ✔               ✔
    60  //   *DebugRef                          ✔
    61  //   *Defer                             ✔
    62  //   *Extract           ✔               ✔
    63  //   *Field             ✔               ✔
    64  //   *FieldAddr         ✔               ✔
    65  //   *FreeVar           ✔
    66  //   *Function          ✔                               ✔ (func)
    67  //   *Global            ✔                               ✔ (var)
    68  //   *Go                                ✔
    69  //   *If                                ✔
    70  //   *Index             ✔               ✔
    71  //   *IndexAddr         ✔               ✔
    72  //   *Jump                              ✔
    73  //   *Lookup            ✔               ✔
    74  //   *MakeChan          ✔               ✔
    75  //   *MakeClosure       ✔               ✔
    76  //   *MakeInterface     ✔               ✔
    77  //   *MakeMap           ✔               ✔
    78  //   *MakeSlice         ✔               ✔
    79  //   *MapUpdate                         ✔
    80  //   *NamedConst                                        ✔ (const)
    81  //   *Next              ✔               ✔
    82  //   *Panic                             ✔
    83  //   *Parameter         ✔
    84  //   *Phi               ✔               ✔
    85  //   *Range             ✔               ✔
    86  //   *Return                            ✔
    87  //   *RunDefers                         ✔
    88  //   *Select            ✔               ✔
    89  //   *Send                              ✔
    90  //   *Slice             ✔               ✔
    91  //   *Store                             ✔
    92  //   *Type                                              ✔ (type)
    93  //   *TypeAssert        ✔               ✔
    94  //   *UnOp              ✔               ✔
    95  //
    96  // Other key types in this package include: Program, Package, Function
    97  // and BasicBlock.
    98  //
    99  // The program representation constructed by this package is fully
   100  // resolved internally, i.e. it does not rely on the names of Values,
   101  // Packages, Functions, Types or BasicBlocks for the correct
   102  // interpretation of the program.  Only the identities of objects and
   103  // the topology of the SSA and type graphs are semantically
   104  // significant.  (There is one exception: Ids, used to identify field
   105  // and method names, contain strings.)  Avoidance of name-based
   106  // operations simplifies the implementation of subsequent passes and
   107  // can make them very efficient.  Many objects are nonetheless named
   108  // to aid in debugging, but it is not essential that the names be
   109  // either accurate or unambiguous.  The public API exposes a number of
   110  // name-based maps for client convenience.
   111  //
   112  // The ssa/ssautil package provides various utilities that depend only
   113  // on the public API of this package.
   114  //
   115  // TODO(adonovan): Consider the exceptional control-flow implications
   116  // of defer and recover().
   117  //
   118  // TODO(adonovan): write a how-to document for all the various cases
   119  // of trying to determine corresponding elements across the four
   120  // domains of source locations, ast.Nodes, types.Objects,
   121  // ssa.Values/Instructions.
   122  //
   123  package ssa // import "golang.org/x/tools/go/ssa"