Changeset 11581
- Timestamp:
- Sep 13, 2018 3:27:45 PM (15 months ago)
- Location:
- trunk/Compiler
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/ModelicaCBackEnd/src/jastadd/CCodeGen/CCodeGenExpressions.jrag
r11560 r11581 701 701 702 702 syn String FAccess.toString_C(CodePrinter.ExecuteCodePrinter p) { 703 return myFV().genUse_C(p, asFAccess().getFArraySubscripts(), myFV().funcArrayType(isAssignUse())); 704 } 705 706 syn String FAccessFull.toString_C(CodePrinter.ExecuteCodePrinter p) { 707 if (getNumFAccessPart() < 2) { 708 return super.toString_C(p); 709 } 710 703 711 String type = myFV().funcArrayType(isAssignUse()); 704 if (myFV().inRecord() && inFunction()) { 705 return asFAccess().genRecordUse_C(p, asFAccess().myOutermostFV(), type); 706 } else { 707 return myFV().genUse_C(p, asFAccess().getFArraySubscripts(), type); 708 } 712 FAccessPart part = getFAccessPart(0); 713 FArraySubscripts fas = part.hasFArraySubscripts() ? part.getFArraySubscripts() : null; 714 String res = myOutermostFV().genUse_C(p, fas, C_ARRAY_RECORD); 715 for (int i = 1, n = getNumFAccessPart(); i < n; i++) { 716 part = getFAccessPart(i); 717 res = res + "->" + part.getName(); 718 if (part.hasFArraySubscripts()) { 719 String curType = (n - i > 1 ? C_ARRAY_RECORD : type); 720 res = part.getFArraySubscripts().genFunctionArrayUse_C(p.codePrinter(), res, curType); 721 } 722 } 723 return res; 709 724 } 710 725 … … 734 749 public void FArraySubscripts.prettyPrint_C(CodePrinter p, CodeStream str, String indent) { 735 750 getFSubscripts().prettyPrintWithSep(p, str, "", ", "); 736 }737 738 /**739 * Helper, generates an record variable use740 */741 public String FAccess.genRecordUse_C(CodePrinter.ExecuteCodePrinter p, FAbstractVariable fv, String type) {742 throw new UnsupportedOperationException();743 }744 745 /**746 * Helper, generates an record variable use747 */748 @Override749 public String FAccessFull.genRecordUse_C(CodePrinter.ExecuteCodePrinter p, FAbstractVariable fv, String type) {750 FAccessPart part = getFAccessPart(0);751 FArraySubscripts fas = part.hasFArraySubscripts() ? part.getFArraySubscripts() : null;752 String res = fv.genUse_C(p, fas, C_ARRAY_RECORD);753 for (int i = 1, n = getNumFAccessPart(); i < n; i++) {754 part = getFAccessPart(i);755 res = res + "->" + part.getName();756 if (part.hasFArraySubscripts()) {757 String curType = (n - i > 1 ? C_ARRAY_RECORD : type);758 res = part.getFArraySubscripts().genFunctionArrayUse_C(p.codePrinter(), res, curType);759 }760 }761 return res;762 751 } 763 752 -
trunk/Compiler/ModelicaCBackEnd/test/modelica/CCodeGenGlobalsTests.mo
r11578 r11581 2193 2193 ")}))); 2194 2194 end GlobalConstantRef2; 2195 2196 model GlobalConstantRef3 2197 2198 constant R1[1] r = {R1(2)}; 2199 record R1 2200 parameter Real x; 2201 end R1; 2202 function f 2203 input Integer i; 2204 output Real y = 1 + r[i].x; 2205 algorithm 2206 end f; 2207 2208 Real y = f(integer(time)); 2209 2210 annotation(__JModelica(UnitTesting(tests={ 2211 CCodeGenTestCase( 2212 name="GlobalConstantRef3", 2213 description="", 2214 template=" 2215 $C_global_temps$ 2216 $C_set_globals_start$ 2217 $C_functions$ 2218 $C_ode_derivatives$ 2219 ", 2220 generatedCode=" 2221 R1_0_ra* CCodeGenGlobalsTests_GlobalVariables_GlobalConstantRef3_r; 2222 2223 R1_0_ra* jmi_global_tmp_1(jmi_t* jmi) { 2224 JMI_DYNAMIC_INIT() 2225 JMI_ARR(DYNA, R1_0_r, R1_0_ra, tmp_1, 1, 1) 2226 JMI_GLOBALS_INIT() 2227 JMI_ARRAY_INIT_1(DYNA, R1_0_r, R1_0_ra, tmp_1, 1, 1, 1) 2228 jmi_array_rec_1(tmp_1, 1)->x = AD_WRAP_LITERAL(2); 2229 JMI_GLOBALS_FREE() 2230 JMI_DYNAMIC_FREE() 2231 return tmp_1; 2232 } 2233 2234 int jmi_set_globals_start_0(jmi_t* jmi) { 2235 int ef = 0; 2236 JMI_DYNAMIC_INIT() 2237 JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantRef3_r) = jmi_global_tmp_1(jmi); 2238 JMI_DYNAMIC_FREE() 2239 return ef; 2240 } 2241 2242 int jmi_set_globals_start_0(jmi_t* jmi); 2243 2244 int jmi_set_globals_start(jmi_t* jmi) { 2245 int ef = 0; 2246 JMI_DYNAMIC_INIT() 2247 ef |= jmi_set_globals_start_0(jmi); 2248 JMI_DYNAMIC_FREE() 2249 return ef; 2250 } 2251 2252 2253 2254 int model_ode_derivatives_base(jmi_t* jmi) { 2255 int ef = 0; 2256 JMI_DYNAMIC_INIT() 2257 if (jmi->atInitial || jmi->atEvent) { 2258 _sw(0) = jmi_turn_switch_time(jmi, _time - (pre_temp_1_2), _sw(0), JMI_REL_LT); 2259 } 2260 if (jmi->atInitial || jmi->atEvent) { 2261 _sw(1) = jmi_turn_switch_time(jmi, _time - (pre_temp_1_2 + AD_WRAP_LITERAL(1)), _sw(1), JMI_REL_GEQ); 2262 } 2263 _temp_1_2 = COND_EXP_EQ(LOG_EXP_OR(LOG_EXP_OR(_sw(0), _sw(1)), _atInitial), JMI_TRUE, floor(_time), pre_temp_1_2); 2264 pre_temp_1_2 = _temp_1_2; 2265 _y_1 = 1 + jmi_array_rec_1(JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantRef3_r), _temp_1_2)->x; 2266 JMI_DYNAMIC_FREE() 2267 return ef; 2268 } 2269 ")}))); 2270 end GlobalConstantRef3; 2195 2271 2196 2272 model GlobalConstantExternalObject1 -
trunk/Compiler/ModelicaMiddleEnd/src/jastadd/optimizations/InlineFunctions.jrag
r11578 r11581 1553 1553 @Override 1554 1554 public FExp FGlobalAccessExp.replaceReferences(AbstractFunctionInliner fi) { 1555 FExp res = dynamicFExp(treeCopy()); 1556 for (ASTNode n : res) { 1557 n.replaceReferences(fi); 1558 } 1559 return res; 1555 replaceReferencesInSubscripts(fi); 1556 return this; 1560 1557 } 1561 1558 -
trunk/Compiler/ModelicaMiddleEnd/test/modelica/FunctionInlining.mo
r11578 r11581 5070 5070 end GlobalConst2; 5071 5071 5072 model GlobalConst3 5073 constant R1[1] r = {R1(2)}; 5074 record R1 5075 parameter Real x; 5076 end R1; 5077 function f 5078 input Integer i; 5079 output Real y = 1 + r[i].x; 5080 algorithm 5081 end f; 5082 5083 Real y = f(integer(time)); 5084 5085 annotation(__JModelica(UnitTesting(tests={ 5086 TransformCanonicalTestCase( 5087 name="GlobalConst3", 5088 description="Inlining global constant", 5089 variability_propagation=false, 5090 flatModel=" 5091 fclass FunctionInlining.GlobalConst3 5092 constant Real r[1].x = 2; 5093 Real y; 5094 discrete Integer temp_1; 5095 package constant 5096 constant FunctionInlining.GlobalConst3.R1 FunctionInlining.GlobalConst3.r[1] = {FunctionInlining.GlobalConst3.R1(2)}; 5097 initial equation 5098 pre(temp_1) = 0; 5099 equation 5100 y = 1 + global(FunctionInlining.GlobalConst3.r[temp_1].x); 5101 temp_1 = if time < pre(temp_1) or time >= pre(temp_1) + 1 or initial() then integer(time) else pre(temp_1); 5102 5103 public 5104 record FunctionInlining.GlobalConst3.R1 5105 parameter Real x; 5106 end FunctionInlining.GlobalConst3.R1; 5107 5108 end FunctionInlining.GlobalConst3; 5109 ")}))); 5110 end GlobalConst3; 5111 5072 5112 model GlobalConstExtObj1 5073 5113 package P
Note: See TracChangeset
for help on using the changeset viewer.