173
|
1 ## Bijective Internal Name Uniquing
|
|
2
|
|
3 FIR has a flat namespace. No two objects may have the same name at
|
|
4 the module level. (These would be functions, globals, etc.)
|
|
5 This necessitates some sort of encoding scheme to unique
|
|
6 symbols from the front-end into FIR.
|
|
7
|
|
8 Another requirement is
|
|
9 to be able to reverse these unique names and recover the associated
|
|
10 symbol in the symbol table.
|
|
11
|
|
12 Fortran is case insensitive, which allows the compiler to convert the
|
|
13 user's identifiers to all lower case. Such a universal conversion implies
|
|
14 that all upper case letters are available for use in uniquing.
|
|
15
|
|
16 ### Prefix `_Q`
|
|
17
|
|
18 All uniqued names have the prefix sequence `_Q` to indicate the name has
|
|
19 been uniqued. (Q is chosen because it is a
|
|
20 [low frequency letter](http://pi.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html)
|
|
21 in English.)
|
|
22
|
|
23 ### Scope Building
|
|
24
|
|
25 Symbols can be scoped by the module, submodule, or procedure that contains
|
|
26 that symbol. After the `_Q` sigil, names are constructed from outermost to
|
|
27 innermost scope as
|
|
28
|
|
29 * Module name prefixed with `M`
|
|
30 * Submodule name prefixed with `S`
|
|
31 * Procedure name prefixed with `F`
|
|
32
|
|
33 Given:
|
|
34 ```
|
|
35 submodule (mod:s1mod) s2mod
|
|
36 ...
|
|
37 subroutine sub
|
|
38 ...
|
|
39 contains
|
|
40 function fun
|
|
41 ```
|
|
42
|
|
43 The uniqued name of `fun` becomes:
|
|
44 ```
|
|
45 _QMmodSs1modSs2modFsubPfun
|
|
46 ```
|
|
47
|
|
48 ### Common blocks
|
|
49
|
|
50 * A common block name will be prefixed with `B`
|
|
51
|
|
52 Given:
|
|
53 ```
|
|
54 common /variables/ i, j
|
|
55 ```
|
|
56
|
|
57 The uniqued name of `variables` becomes:
|
|
58 ```
|
|
59 _QBvariables
|
|
60 ```
|
|
61
|
|
62 Given:
|
|
63 ```
|
|
64 common i, j
|
|
65 ```
|
|
66
|
|
67 The uniqued name in case of `blank common block` becomes:
|
|
68 ```
|
|
69 _QB
|
|
70 ```
|
|
71
|
|
72 ### Module scope global data
|
|
73
|
|
74 * A global data entity is prefixed with `E`
|
|
75 * A global entity that is constant (parameter) will be prefixed with `EC`
|
|
76
|
|
77 Given:
|
|
78 ```
|
|
79 module mod
|
|
80 integer :: intvar
|
|
81 real, parameter :: pi = 3.14
|
|
82 end module
|
|
83 ```
|
|
84
|
|
85 The uniqued name of `intvar` becomes:
|
|
86 ```
|
|
87 _QMmodEintvar
|
|
88 ```
|
|
89
|
|
90 The uniqued name of `pi` becomes:
|
|
91 ```
|
|
92 _QMmodECpi
|
|
93 ```
|
|
94
|
|
95 ### Procedures/Subprograms
|
|
96
|
|
97 * A procedure/subprogram is prefixed with `P`
|
|
98
|
|
99 Given:
|
|
100 ```
|
|
101 subroutine sub
|
|
102 ```
|
|
103 The uniqued name of `sub` becomes:
|
|
104 ```
|
|
105 _QPsub
|
|
106 ```
|
|
107
|
|
108 ### Derived types and related
|
|
109
|
|
110 * A derived type is prefixed with `T`
|
|
111 * If a derived type has KIND parameters, they are listed in a consistent
|
|
112 canonical order where each takes the form `Ki` and where _i_ is the
|
|
113 compile-time constant value. (All type parameters are integer.) If _i_
|
|
114 is a negative value, the prefix `KN` will be used and _i_ will reflect
|
|
115 the magnitude of the value.
|
|
116
|
|
117 Given:
|
|
118 ```
|
|
119 module mymodule
|
|
120 type mytype
|
|
121 integer :: member
|
|
122 end type
|
|
123 ...
|
|
124 ```
|
|
125 The uniqued name of `mytype` becomes:
|
|
126 ```
|
|
127 _QMmymoduleTmytype
|
|
128 ```
|
|
129
|
|
130 Given:
|
|
131 ```
|
|
132 type yourtype(k1,k2)
|
|
133 integer, kind :: k1, k2
|
|
134 real :: mem1
|
|
135 complex :: mem2
|
|
136 end type
|
|
137 ```
|
|
138
|
|
139 The uniqued name of `yourtype` where `k1=4` and `k2=-6` (at compile-time):
|
|
140 ```
|
|
141 _QTyourtypeK4KN6
|
|
142 ```
|
|
143
|
|
144 * A derived type dispatch table is prefixed with `D`. The dispatch table
|
|
145 for `type t` would be `_QDTt`
|
|
146 * A type descriptor instance is prefixed with `C`. Intrinsic types can
|
|
147 be encoded with their names and kinds. The type descriptor for the
|
|
148 type `yourtype` above would be `_QCTyourtypeK4KN6`. The type
|
|
149 descriptor for `REAL(4)` would be `_QCrealK4`.
|
|
150
|
|
151 ### Compiler generated names
|
|
152
|
|
153 Compiler generated names do not have to be mapped back to Fortran. These
|
|
154 names will be prefixed with `_QQ` and followed by a unique compiler
|
|
155 generated identifier. There is, of course, no mapping back to a symbol
|
|
156 derived from the input source in this case as no such symbol exists.
|