/usr/lib/python2.7/dist-packages/ffc/compiler.py is in python-ffc 1.6.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | """
This is the compiler, acting as the main interface for compilation
of forms and breaking the compilation into several sequential stages.
The output of each stage is the input of the next stage.
Compiler stage 0: Language, parsing
-----------------------------------
Input: Python code or .ufl file
Output: UFL form
This stage consists of parsing and expressing a form in the
UFL form language.
This stage is completely handled by UFL.
Compiler stage 1: Analysis
--------------------------
Input: UFL form
Output: Preprocessed UFL form and FormData (metadata)
This stage preprocesses the UFL form and extracts form metadata.
It may also perform simplifications on the form.
Compiler stage 2: Code representation
-------------------------------------
Input: Preprocessed UFL form and FormData (metadata)
Output: Intermediate Representation (IR)
This stage examines the input and generates all data needed for code
generation. This includes generation of finite element basis
functions, extraction of data for mapping of degrees of freedom and
possible precomputation of integrals.
Most of the complexity of compilation is handled in this stage.
The IR is stored as a dictionary, mapping names of UFC functions to
data needed for generation of the corresponding code.
Compiler stage 3: Optimization
------------------------------
Input: Intermediate Representation (IR)
Output: Optimized Intermediate Representation (OIR)
This stage examines the IR and performs optimizations.
Optimization is currently disabled as a separate stage
but is implemented as part of the code generation for
quadrature representation.
Compiler stage 4: Code generation
---------------------------------
Input: Optimized Intermediate Representation (OIR)
Output: C++ code
This stage examines the OIR and generates the actual C++ code for
the body of each UFC function.
The code is stored as a dictionary, mapping names of UFC functions
to strings containing the C++ code of the body of each function.
Compiler stage 5: Code formatting
---------------------------------
Input: C++ code
Output: C++ code files
This stage examines the generated C++ code and formats it according
to the UFC format, generating as output one or more .h/.cpp files
conforming to the UFC format.
The main interface is defined by the following two functions:
compile_form
compile_element
The compiler stages are implemented by the following functions:
analyze_forms
or
analyze_elements (stage 1)
compute_ir (stage 2)
optimize_ir (stage 3)
generate_code (stage 4)
format_code (stage 5)
"""
# Copyright (C) 2007-2015 Anders Logg
#
# This file is part of FFC.
#
# FFC is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FFC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Kristian B. Oelgaard, 2010.
# Modified by Dag Lindbo, 2008.
# Modified by Garth N. Wells, 2009.
# Modified by Martin Alnaes, 2013-2015
__all__ = ["compile_form", "compile_element"]
# Python modules
from time import time
import os
# FFC modules
from ffc.log import info, info_green, warning
from ffc.parameters import default_parameters
# FFC modules
from ffc.analysis import analyze_forms, analyze_elements
from ffc.representation import compute_ir
from ffc.optimization import optimize_ir
from ffc.codegeneration import generate_code
from ffc.formatting import format_code, write_code
from ffc.wrappers import generate_wrapper_code
def compile_form(forms, object_names=None, prefix="Form", parameters=None):
"""This function generates UFC code for a given UFL form or list
of UFL forms."""
info("Compiling form %s\n" % prefix)
# Reset timing
cpu_time_0 = time()
# Check input arguments
forms = _check_forms(forms)
if not forms:
return
if prefix != os.path.basename(prefix):
prefix = os.path.basename(prefix)
warning("Invalid prefix, modified to {}.".format(prefix))
if object_names is None:
object_names = {}
parameters = _check_parameters(parameters)
# Stage 1: analysis
cpu_time = time()
analysis = analyze_forms(forms, parameters)
_print_timing(1, time() - cpu_time)
# Stage 2: intermediate representation
cpu_time = time()
ir = compute_ir(analysis, parameters)
_print_timing(2, time() - cpu_time)
# Stage 3: optimization
cpu_time = time()
oir = optimize_ir(ir, parameters)
_print_timing(3, time() - cpu_time)
# Stage 4: code generation
cpu_time = time()
code = generate_code(oir, prefix, parameters)
_print_timing(4, time() - cpu_time)
# Stage 4.1: generate wrappers
cpu_time = time()
wrapper_code = generate_wrapper_code(analysis, prefix, object_names, parameters)
_print_timing(4.1, time() - cpu_time)
# Stage 5: format code
cpu_time = time()
code_h, code_c = format_code(code, wrapper_code, prefix, parameters)
write_code(code_h, code_c, prefix, parameters) # FIXME: Don't write to file in this function (issue #72)
_print_timing(5, time() - cpu_time)
info_green("FFC finished in %g seconds.", time() - cpu_time_0)
def compile_element(elements, prefix="Element", parameters=None):
"""This function generates UFC code for a given UFL element or
list of UFL elements."""
info("Compiling element %s\n" % prefix)
# Reset timing
cpu_time_0 = time()
# Check input arguments
elements = _check_elements(elements)
if not elements:
return
parameters = _check_parameters(parameters)
# Stage 1: analysis
cpu_time = time()
analysis = analyze_elements(elements, parameters)
_print_timing(1, time() - cpu_time)
# Stage 2: intermediate representation
cpu_time = time()
ir = compute_ir(analysis, parameters)
_print_timing(2, time() - cpu_time)
# Stage 3: optimization
cpu_time = time()
oir = optimize_ir(ir, parameters)
_print_timing(3, time() - cpu_time)
# Stage 4: code generation
cpu_time = time()
code = generate_code(oir, prefix, parameters)
_print_timing(4, time() - cpu_time)
# Stage 4.1: generate wrappers
cpu_time = time()
object_names = {}
wrapper_code = generate_wrapper_code(analysis, prefix, object_names, parameters)
_print_timing(4.1, time() - cpu_time)
# Stage 5: format code
cpu_time = time()
code_h, code_c = format_code(code, wrapper_code, prefix, parameters)
write_code(code_h, code_c, prefix, parameters) # FIXME: Don't write to file in this function (issue #72)
_print_timing(5, time() - cpu_time)
info_green("FFC finished in %g seconds.", time() - cpu_time_0)
def _check_forms(forms):
"Initial check of forms."
if not isinstance(forms, (list, tuple)):
forms = (forms,)
return forms
def _check_elements(elements):
"Initial check of elements."
if not isinstance(elements, (list, tuple)):
elements = (elements,)
return elements
def _check_parameters(parameters):
"Initial check of parameters."
if parameters is None:
parameters = default_parameters()
if "blas" in parameters:
warning("BLAS mode unavailable (will return in a future version).")
if "quadrature_points" in parameters:
warning("Option 'quadrature_points' has been replaced by 'quadrature_degree'.")
return parameters
def _print_timing(stage, timing):
"Print timing results."
info("Compiler stage %s finished in %g seconds.\n" % (str(stage), timing))
|