Bijective Internal Name Uniquing

FIR has a flat namespace. No two objects may have the same name at the module level. (These would be functions, globals, etc.) This necessitates some sort of encoding scheme to unique symbols from the front-end into FIR.

Another requirement is to be able to reverse these unique names and recover the associated symbol in the symbol table.

Fortran is case insensitive, which allows the compiler to convert the user’s identifiers to all lower case. Such a universal conversion implies that all upper case letters are available for use in uniquing.

Prefix _Q

All uniqued names have the prefix sequence _Q to indicate the name has been uniqued. (Q is chosen because it is a low frequency letter in English.)

Scope Building

Symbols can be scoped by the module, submodule, or procedure that contains that symbol. After the _Q sigil, names are constructed from outermost to innermost scope as

  • Module name prefixed with M
  • Submodule name prefixed with S
  • Procedure name prefixed with F

Given:

    submodule (mod:s1mod) s2mod
      ...
      subroutine sub
        ...
      contains
        function fun

The uniqued name of fun becomes:

    _QMmodSs1modSs2modFsubPfun

Common blocks

  • A common block name will be prefixed with B

Given:

   common /variables/ i, j

The uniqued name of variables becomes:

    _QBvariables

Given:

   common i, j

The uniqued name in case of blank common block becomes:

    _QB

Module scope global data

  • A global data entity is prefixed with E
  • A global entity that is constant (parameter) will be prefixed with EC

Given:

    module mod
      integer :: intvar
      real, parameter :: pi = 3.14
    end module

The uniqued name of intvar becomes:

    _QMmodEintvar

The uniqued name of pi becomes:

    _QMmodECpi

Procedures/Subprograms

  • A procedure/subprogram is prefixed with P

Given:

    subroutine sub

The uniqued name of sub becomes:

    _QPsub

Compiler generated names

Compiler generated names do not have to be mapped back to Fortran. These names will be prefixed with _QQ and followed by a unique compiler generated identifier. There is, of course, no mapping back to a symbol derived from the input source in this case as no such symbol exists.