OMCompiler/Compiler/FrontEnd/BackendInterface.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package BackendInterface | ||
| 37 | " file: BackendInterface.mo | ||
| 38 | package: BackendInterface | ||
| 39 | description: Interface functions used to separate frontend and backend." | ||
| 40 | |||
| 41 | public import Absyn; | ||
| 42 | |||
| 43 | protected | ||
| 44 | import Global; | ||
| 45 | |||
| 46 | public | ||
| 47 | |||
| 48 | uniontype BackendInterfaceFunctions | ||
| 49 | record BACKEND_INTERFACE_FUNCTIONS | ||
| 50 | partialNoRewriteRulesFrontEnd noRewriteRulesFrontEnd; | ||
| 51 | partialRewriteFrontEnd rewriteFrontEnd; | ||
| 52 | partialAppendLibrary appendLibrary; | ||
| 53 | partialInitInstHashTable initInstHashTable; | ||
| 54 | end BACKEND_INTERFACE_FUNCTIONS; | ||
| 55 | end BackendInterfaceFunctions; | ||
| 56 | |||
| 57 | public function initializeBackendInterface | ||
| 58 | input BackendInterfaceFunctions inFunctions; | ||
| 59 | algorithm | ||
| 60 | 2677 | setGlobalRoot(Global.backendInterface, inFunctions); | |
| 61 | end initializeBackendInterface; | ||
| 62 | |||
| 63 | public function initializeWithoutBackend | ||
| 64 | "A table for a host that has no backend: no rewrite rules, no library | ||
| 65 | loading, and nothing to prepare for the old instantiation, which such a host | ||
| 66 | never runs. AbsynToSCode.translateAbsyn2SCode reaches initInstHashTable | ||
| 67 | through this table, so anything that translates a program at all has to | ||
| 68 | install one; the compiler does it from BackendInterfaceImplementation and a | ||
| 69 | frontend-only tool -- the documentation generator -- from here, which is why | ||
| 70 | this lives beside the table rather than in the frontend." | ||
| 71 | algorithm | ||
| 72 | ✗ | initializeBackendInterface(BACKEND_INTERFACE_FUNCTIONS( | |
| 73 | noBackendRewriteRules, keepExpression, noBackendLibrary, doNothing)); | ||
| 74 | end initializeWithoutBackend; | ||
| 75 | |||
| 76 | protected function noBackendRewriteRules | ||
| 77 | output Boolean noRules = true; | ||
| 78 | end noBackendRewriteRules; | ||
| 79 | |||
| 80 | protected function keepExpression | ||
| 81 | input Absyn.Exp inExp; | ||
| 82 | output Absyn.Exp outExp = inExp; | ||
| 83 | output Boolean isChanged = false; | ||
| 84 | end keepExpression; | ||
| 85 | |||
| 86 | protected function noBackendLibrary | ||
| 87 | input Absyn.Path modelName; | ||
| 88 | input String modelicaPath; | ||
| 89 | output Absyn.Program program = Absyn.Program.PROGRAM({}, Absyn.Within.TOP()); | ||
| 90 | output Boolean success = false; | ||
| 91 | end noBackendLibrary; | ||
| 92 | |||
| 93 | protected function doNothing | ||
| 94 | end doNothing; | ||
| 95 | |||
| 96 | public | ||
| 97 | |||
| 98 | function noRewriteRulesFrontEnd | ||
| 99 | output Boolean noRules; | ||
| 100 | protected | ||
| 101 | BackendInterfaceFunctions functions; | ||
| 102 | partialNoRewriteRulesFrontEnd func; | ||
| 103 | algorithm | ||
| 104 | 2357736 | functions := getGlobalRoot(Global.backendInterface); | |
| 105 | 2357736 | func := functions.noRewriteRulesFrontEnd; | |
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2357736 times.
|
2357736 | noRules := func(); |
| 107 | end noRewriteRulesFrontEnd; | ||
| 108 | |||
| 109 | function rewriteFrontEnd | ||
| 110 | input Absyn.Exp inExp; | ||
| 111 | output Absyn.Exp outExp; | ||
| 112 | output Boolean isChanged; | ||
| 113 | protected | ||
| 114 | BackendInterfaceFunctions functions; | ||
| 115 | partialRewriteFrontEnd func; | ||
| 116 | algorithm | ||
| 117 | ✗ | functions := getGlobalRoot(Global.backendInterface); | |
| 118 | ✗ | func := functions.rewriteFrontEnd; | |
| 119 | ✗ | (outExp,isChanged) := func(inExp); | |
| 120 | end rewriteFrontEnd; | ||
| 121 | |||
| 122 | function appendLibrary | ||
| 123 | input Absyn.Path modelName; | ||
| 124 | input String modelicaPath; | ||
| 125 | output Absyn.Program program; | ||
| 126 | output Boolean success; | ||
| 127 | protected | ||
| 128 | BackendInterfaceFunctions functions; | ||
| 129 | partialAppendLibrary func; | ||
| 130 | algorithm | ||
| 131 | 403 | functions := getGlobalRoot(Global.backendInterface); | |
| 132 | 403 | func := functions.appendLibrary; | |
| 133 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 403 times.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
|
403 | (program, success) := func(modelName, modelicaPath); |
| 134 | end appendLibrary; | ||
| 135 | |||
| 136 | function initInstHashTable | ||
| 137 | protected | ||
| 138 | BackendInterfaceFunctions functions; | ||
| 139 | partialInitInstHashTable func; | ||
| 140 | algorithm | ||
| 141 | 7729 | functions := getGlobalRoot(Global.backendInterface); | |
| 142 | 7729 | func := functions.initInstHashTable; | |
| 143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7729 times.
|
7729 | func(); |
| 144 | end initInstHashTable; | ||
| 145 | |||
| 146 | partial function partialNoRewriteRulesFrontEnd | ||
| 147 | output Boolean noRules; | ||
| 148 | end partialNoRewriteRulesFrontEnd; | ||
| 149 | |||
| 150 | partial function partialRewriteFrontEnd | ||
| 151 | input Absyn.Exp inExp; | ||
| 152 | output Absyn.Exp outExp; | ||
| 153 | output Boolean isChanged; | ||
| 154 | end partialRewriteFrontEnd; | ||
| 155 | |||
| 156 | partial function partialAppendLibrary | ||
| 157 | input Absyn.Path modelName; | ||
| 158 | input String modelicaPath; | ||
| 159 | output Absyn.Program program; | ||
| 160 | output Boolean success; | ||
| 161 | end partialAppendLibrary; | ||
| 162 | |||
| 163 | partial function partialInitInstHashTable | ||
| 164 | end partialInitInstHashTable; | ||
| 165 | |||
| 166 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 167 | end BackendInterface; | ||
| 168 |