Module

A Fortran module or submodule.

Declaration

Syntax

Module(symbol_table symtab, identifier name, identifier? parent_module,
    identifier* dependencies, bool loaded_from_mod, bool intrinsic,
    bool has_submodules, bool host_only_object, identifier? global_init,
    location start_name, location end_name)

Arguments

Argument

Description

symtab

the symbol table of the module, owning everything the module declares.

name

the name of the module.

parent_module

for a submodule, the name of the module it extends; nil for a module.

dependencies

the names of the modules this module uses.

loaded_from_mod

true when the module was read back from a module file rather than compiled from source in this run.

intrinsic

true for a module defined by the language itself (iso_c_binding, iso_fortran_env, ...). The backends do not emit code for it.

has_submodules

true when at least one submodule extends this module. A module procedure declared here may then be defined elsewhere.

host_only_object

true when the module was compiled with separate compilation (its own object file defines its procedures) and without GPU offloading, so that object defines none of the deferring twins (<name>__gpu_deferred) that the gpu_launch_sync pass gives its procedures. A translation unit that uses the module from its module file then calls the procedures themselves. false otherwise, also in the default mode, where the unit with the main program compiles the module's procedures and their twins.

global_init

the name of this module's startup initializer in symtab, or nil. It is an argument-less procedure that runs once before any code can observe the module's variables. See Program.

start_name

the source span of the name in module name.

end_name

the source span of the name in end module name.

Return values

None.

Description

A Module owns the symbols it declares. Code in another program unit never looks a module symbol up through this table directly: it declares an ExternalSymbol in its own scope that points at the symbol here.

When a module is compiled, the full ASR (abi=Source, non-empty procedure bodies) and the interface ASR (abi=LFortranModule, empty bodies) are both written to the module file. loaded_from_mod records which side of that a particular Module came from.

Examples

(Module
  :symtab (SymbolTable
    :id 1
    :symbols {
      "pi" (Variable
        :parent_symtab 1
        :name "pi"
        :dependencies []
        :intent :Local
        :symbolic_value (RealConstant
          :r 3.1415926535897931
          :type (Real
            :kind 8
          )
        )
        :value (RealConstant
          :r 3.1415926535897931
          :type (Real
            :kind 8
          )
        )
        :storage :Parameter
        :type (Real
          :kind 8
        )
        :type_declaration nil
        :abi :Source
        :access :Public
        :presence :Required
        :value_attr false
        :target_attr false
        :contiguous_attr false
        :bindc_name nil
        :is_volatile false
        :is_asynchronous false
        :is_protected false
        :pass_attr :NotMethod
        :self_argument nil
        :codims []
        :common_block nil
      )
    }
  )
  :name "constants"
  :parent_module nil
  :dependencies []
  :loaded_from_mod false
  :intrinsic false
  :has_submodules false
  :host_only_object false
  :global_init nil
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "constants" (Module
        :symtab (SymbolTable
          :id 1
          :symbols {
            "pi" (Variable
              :parent_symtab 1
              :name "pi"
              :dependencies []
              :intent :Local
              :symbolic_value (RealConstant
                :r 3.1415926535897931
                :type (Real
                  :kind 8
                )
              )
              :value (RealConstant
                :r 3.1415926535897931
                :type (Real
                  :kind 8
                )
              )
              :storage :Parameter
              :type (Real
                :kind 8
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_asynchronous false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
              :common_block nil
            )
          }
        )
        :name "constants"
        :parent_module nil
        :dependencies []
        :loaded_from_mod false
        :intrinsic false
        :has_submodules false
        :host_only_object false
        :global_init nil
      )
      "main" (Program
        :symtab (SymbolTable
          :id 2
          :symbols {}
        )
        :name "main"
        :dependencies []
        :body []
        :global_init nil
      )
    }
  )
  :items []
  :global_init nil
)

See Also

Program, Function, ExternalSymbol, Variable