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.95 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

Kunshan Wang's avatar
Kunshan Wang committed
6
class Bundle {
Kunshan Wang's avatar
Kunshan Wang committed
7
8
9
  /*
   * There is a hierarchy of namespaces. A subnode is a subset of the parent.
   * 
10
11
12
13
14
15
16
17
18
   * + allNs                // All Identified entities
   *   + 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
19
   *       + expFuncNs      // Exposed functions
20
21
   *     + localVarNs       // Local variables (per function version)
   *   + bbNs               // Basic blocks (per function version)
Kunshan Wang's avatar
Kunshan Wang committed
22
23
   * 
   * TODO: Should there be a global "basic block ns for all function versions"?
Kunshan Wang's avatar
Kunshan Wang committed
24
   */
25

26
  val allNs = new SimpleNamespace[Identified]()
27

Kunshan Wang's avatar
Kunshan Wang committed
28
29
  val typeNs = new SimpleNamespace[Type]()
  val funcSigNs = new SimpleNamespace[FuncSig]()
Kunshan Wang's avatar
Kunshan Wang committed
30
31
32
33
  val funcVerNs = new SimpleNamespace[FuncVer]()

  val varNs = new SimpleNamespace[SSAVariable]()
  val globalVarNs = new SimpleNamespace[GlobalVariable]()
Kunshan Wang's avatar
Kunshan Wang committed
34
35
  val constantNs = new SimpleNamespace[Constant]()
  val globalCellNs = new SimpleNamespace[GlobalCell]()
Kunshan Wang's avatar
Kunshan Wang committed
36
  val funcNs = new SimpleNamespace[Function]()
37
  val expFuncNs = new SimpleNamespace[ExposedFunc]()
38
39
40
41
42
43
44
45
46
47
48
49
50
51

  /**
   * Add an identified entity to its appropriate global namespaces.
   */
  def add(obj: Identified): Unit = {
    allNs.add(obj)
    if (obj.isInstanceOf[Type]) typeNs.add(obj.asInstanceOf[Type])
    if (obj.isInstanceOf[FuncSig]) funcSigNs.add(obj.asInstanceOf[FuncSig])
    if (obj.isInstanceOf[FuncVer]) funcVerNs.add(obj.asInstanceOf[FuncVer])
    if (obj.isInstanceOf[SSAVariable]) varNs.add(obj.asInstanceOf[SSAVariable])
    if (obj.isInstanceOf[GlobalVariable]) globalVarNs.add(obj.asInstanceOf[GlobalVariable])
    if (obj.isInstanceOf[Constant]) constantNs.add(obj.asInstanceOf[Constant])
    if (obj.isInstanceOf[GlobalCell]) globalCellNs.add(obj.asInstanceOf[GlobalCell])
    if (obj.isInstanceOf[Function]) funcNs.add(obj.asInstanceOf[Function])
52
    if (obj.isInstanceOf[ExposedFunc]) expFuncNs.add(obj.asInstanceOf[ExposedFunc])
53
54
  }

Kunshan Wang's avatar
Kunshan Wang committed
55
56
  private def simpleMerge[T <: Identified](oldNs: Namespace[T], newNs: Namespace[T]) {
    for (cand <- newNs.all) {
Kunshan Wang's avatar
Kunshan Wang committed
57
58
59
60
61
62
63
64
65
66
      if (!cand.isInstanceOf[Function] || oldNs.get(cand.id) == None) {
        // Function merging happens separately. Only add a function if it does not redefine an old one.
        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
67
68
69
      }
    }
  }
Kunshan Wang's avatar
Kunshan Wang committed
70

Kunshan Wang's avatar
Kunshan Wang committed
71
72
73
74
  private def mergeFunc(oldNs: Namespace[Function], newNs: Namespace[Function]) {
    for (cand <- newNs.all) {
      val id = cand.id
      oldNs.get(id) match {
75
        case None         => oldNs.add(cand)
76
77
78
79
80
81
82
83
84
85
86
87
88
        case Some(oldObj) =>
          oldObj.versions = cand.versions.head :: oldObj.versions
          cand.versions.head.func = oldObj
      }
    }
  }

  private def fixExpFuncs(oldNs: Namespace[Function], newNs: Namespace[ExposedFunc]) {
    for (expFunc <- newNs.all) {
      val funcID = expFunc.func.id
      oldNs.get(funcID) match {
        case None          =>
        case Some(oldFunc) => expFunc.func = oldFunc
Kunshan Wang's avatar
Kunshan Wang committed
89
90
91
      }
    }
  }
92

Kunshan Wang's avatar
Kunshan Wang committed
93
  def merge(newBundle: Bundle) {
94
    simpleMerge(allNs, newBundle.allNs)
Kunshan Wang's avatar
Kunshan Wang committed
95
96
    simpleMerge(typeNs, newBundle.typeNs)
    simpleMerge(funcSigNs, newBundle.funcSigNs)
97
98
99
    simpleMerge(funcVerNs, newBundle.funcVerNs)
    simpleMerge(varNs, newBundle.varNs)
    simpleMerge(globalVarNs, newBundle.globalVarNs)
Kunshan Wang's avatar
Kunshan Wang committed
100
101
    simpleMerge(constantNs, newBundle.constantNs)
    simpleMerge(globalCellNs, newBundle.globalCellNs)
Kunshan Wang's avatar
Kunshan Wang committed
102
    mergeFunc(funcNs, newBundle.funcNs)
103
104
    simpleMerge(expFuncNs, newBundle.expFuncNs)
    fixExpFuncs(funcNs, newBundle.expFuncNs)
Kunshan Wang's avatar
Kunshan Wang committed
105
  }
Kunshan Wang's avatar
Kunshan Wang committed
106
}