WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Bundle.scala 3.23 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1
2
package uvm

Kunshan Wang's avatar
Kunshan Wang committed
3
import uvm.types._
Kunshan Wang's avatar
Kunshan Wang committed
4
import uvm.ssavariables._
Kunshan Wang's avatar
Kunshan Wang committed
5
import scala.collection.mutable.HashMap
Kunshan Wang's avatar
Kunshan Wang committed
6

Kunshan Wang's avatar
Kunshan Wang committed
7
abstract class Bundle {
Kunshan Wang's avatar
Kunshan Wang committed
8
9
10
  /*
   * There is a hierarchy of namespaces. A subnode is a subset of the parent.
   * 
Kunshan Wang's avatar
Kunshan Wang committed
11
   * + allNs                // All globally Identified entities
12
13
14
15
16
17
18
19
   *   + typeNs             // All types
   *   + funcSigNs          // All function signatures
   *   + funcVerNs          // All function versions
   *   + varNs              // All variables, global or local
   *     + globalVarNs      // Global variables
   *       + constantNs     // Constants
   *       + globalCellNs   // Global cells
   *       + funcNs         // Functions
20
   *       + expFuncNs      // Exposed functions
Kunshan Wang's avatar
Kunshan Wang committed
21
   * 
Kunshan Wang's avatar
Kunshan Wang committed
22
23
24
   * These namespaces are local, i.e. they cannot be directly looked up from a bundle:
   * + bbNs                 // Basic blocks (per function version)
   * + localVarNs           // Local variables (per basic block)
Kunshan Wang's avatar
Kunshan Wang committed
25
   */
26

Kunshan Wang's avatar
Kunshan Wang committed
27
  val allNs = new NestedNamespace[Identified](None)
28

Kunshan Wang's avatar
Kunshan Wang committed
29
30
31
32
  val typeNs = allNs.makeSubSpace[Type]()
  val funcSigNs = allNs.makeSubSpace[FuncSig]()
  val funcVerNs = allNs.makeSubSpace[FuncVer]()
  val varNs = allNs.makeSubSpace[SSAVariable]()
Kunshan Wang's avatar
Kunshan Wang committed
33

Kunshan Wang's avatar
Kunshan Wang committed
34
35
36
37
38
  val globalVarNs = varNs.makeSubSpace[GlobalVariable]()
  val constantNs = globalVarNs.makeSubSpace[Constant]()
  val globalCellNs = globalVarNs.makeSubSpace[GlobalCell]()
  val funcNs = globalVarNs.makeSubSpace[Function]()
  val expFuncNs = globalVarNs.makeSubSpace[ExposedFunc]()
Kunshan Wang's avatar
Kunshan Wang committed
39
}
40

Kunshan Wang's avatar
Kunshan Wang committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * This kind of bundle is generated when parsing a .UIR file.
 * <p>
 * In this kind of bundle, a Function does not have a FuncVer as its version.
 * The funcNs only contains new functions declared in this bundle, not existing
 * functions declared previously. When this bundle is merged with the global bundle,
 * both funcNs and funcVerNs are simply merged, and new FuncVer objects become the
 * newest version of the Function, whether the Function is newly declared or not.
 */
class TrantientBundle extends Bundle {
  /**
   * All functions (declared here or previously) that are defined in this bundle.
   * <p>
   * Mainly for debugging purpose.
   */
  //val defFuncNs = new SimpleNamespace[Function]
}

/**
 * This kind of bundle holds the global state. Functions and versions are fully merged.
 */
class GlobalBundle extends Bundle {
Kunshan Wang's avatar
Kunshan Wang committed
63
64
  private def simpleMerge[T <: Identified](oldNs: Namespace[T], newNs: Namespace[T]) {
    for (cand <- newNs.all) {
Kunshan Wang's avatar
Kunshan Wang committed
65
66
67
68
69
70
71
      try {
        oldNs.add(cand)
      } catch {
        case e: NameConflictException =>
          throw new IllegalRedefinitionException(
            "Redefinition of type, function signature, constant or" +
              " global cell is not allowed", e);
Kunshan Wang's avatar
Kunshan Wang committed
72
73
74
      }
    }
  }
75

Kunshan Wang's avatar
Kunshan Wang committed
76
77
78
79
80
81
82
  private def redefineFunctions(newNs: Namespace[FuncVer]) {
    for (fv <- newNs.all) {
      fv.func.versions = fv :: fv.func.versions
    }
  }

  def merge(newBundle: TrantientBundle) {
Kunshan Wang's avatar
Kunshan Wang committed
83
    // Only merge leaves
Kunshan Wang's avatar
Kunshan Wang committed
84
85
    simpleMerge(typeNs, newBundle.typeNs)
    simpleMerge(funcSigNs, newBundle.funcSigNs)
86
    simpleMerge(funcVerNs, newBundle.funcVerNs)
Kunshan Wang's avatar
Kunshan Wang committed
87
88
    simpleMerge(constantNs, newBundle.constantNs)
    simpleMerge(globalCellNs, newBundle.globalCellNs)
Kunshan Wang's avatar
Kunshan Wang committed
89
    simpleMerge(funcNs, newBundle.funcNs)
90
    simpleMerge(expFuncNs, newBundle.expFuncNs)
Kunshan Wang's avatar
Kunshan Wang committed
91
92

    redefineFunctions(newBundle.funcVerNs)
Kunshan Wang's avatar
Kunshan Wang committed
93
  }
Kunshan Wang's avatar
Kunshan Wang committed
94
95

}