Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 9b09552

Browse files
perostOpenModelica-Hudson
authored andcommitted
Add evaluation of intBit*.
Belonging to [master]: - #2479
1 parent 9878b52 commit 9b09552

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

Compiler/FrontEnd/Ceval.mo

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,11 @@ algorithm
11361136
case "listMember" guard Config.acceptMetaModelicaGrammar() then cevalListMember;
11371137
case "anyString" guard Config.acceptMetaModelicaGrammar() then cevalAnyString;
11381138
case "listArrayLiteral" guard Config.acceptMetaModelicaGrammar() then cevalListArrayLiteral;
1139+
case "intBitAnd" guard Config.acceptMetaModelicaGrammar() then cevalIntBitAnd;
1140+
case "intBitOr" guard Config.acceptMetaModelicaGrammar() then cevalIntBitOr;
1141+
case "intBitXor" guard Config.acceptMetaModelicaGrammar() then cevalIntBitXor;
1142+
case "intBitLShift" guard Config.acceptMetaModelicaGrammar() then cevalIntBitLShift;
1143+
case "intBitRShift" guard Config.acceptMetaModelicaGrammar() then cevalIntBitRShift;
11391144
case "numBits" then cevalNumBits;
11401145
case "integerMax" then cevalIntegerMax;
11411146

@@ -2570,6 +2575,96 @@ algorithm
25702575
end match;
25712576
end cevalIntegerMax;
25722577

2578+
function cevalIntBitAnd
2579+
input output FCore.Cache cache;
2580+
input FCore.Graph env;
2581+
input list<DAE.Exp> args;
2582+
input Boolean impl;
2583+
input Absyn.Msg msg;
2584+
input Integer numIter;
2585+
output Values.Value result;
2586+
protected
2587+
DAE.Exp e1, e2;
2588+
Integer i1, i2;
2589+
algorithm
2590+
e1 :: e2 :: _ := args;
2591+
(cache, Values.INTEGER(i1)) := ceval(cache, env, e1, impl, msg, numIter + 1);
2592+
(cache, Values.INTEGER(i2)) := ceval(cache, env, e2, impl, msg, numIter + 1);
2593+
result := Values.INTEGER(intBitAnd(i1, i2));
2594+
end cevalIntBitAnd;
2595+
2596+
function cevalIntBitOr
2597+
input output FCore.Cache cache;
2598+
input FCore.Graph env;
2599+
input list<DAE.Exp> args;
2600+
input Boolean impl;
2601+
input Absyn.Msg msg;
2602+
input Integer numIter;
2603+
output Values.Value result;
2604+
protected
2605+
DAE.Exp e1, e2;
2606+
Integer i1, i2;
2607+
algorithm
2608+
e1 :: e2 :: _ := args;
2609+
(cache, Values.INTEGER(i1)) := ceval(cache, env, e1, impl, msg, numIter + 1);
2610+
(cache, Values.INTEGER(i2)) := ceval(cache, env, e2, impl, msg, numIter + 1);
2611+
result := Values.INTEGER(intBitOr(i1, i2));
2612+
end cevalIntBitOr;
2613+
2614+
function cevalIntBitXor
2615+
input output FCore.Cache cache;
2616+
input FCore.Graph env;
2617+
input list<DAE.Exp> args;
2618+
input Boolean impl;
2619+
input Absyn.Msg msg;
2620+
input Integer numIter;
2621+
output Values.Value result;
2622+
protected
2623+
DAE.Exp e1, e2;
2624+
Integer i1, i2;
2625+
algorithm
2626+
e1 :: e2 :: _ := args;
2627+
(cache, Values.INTEGER(i1)) := ceval(cache, env, e1, impl, msg, numIter + 1);
2628+
(cache, Values.INTEGER(i2)) := ceval(cache, env, e2, impl, msg, numIter + 1);
2629+
result := Values.INTEGER(intBitXor(i1, i2));
2630+
end cevalIntBitXor;
2631+
2632+
function cevalIntBitLShift
2633+
input output FCore.Cache cache;
2634+
input FCore.Graph env;
2635+
input list<DAE.Exp> args;
2636+
input Boolean impl;
2637+
input Absyn.Msg msg;
2638+
input Integer numIter;
2639+
output Values.Value result;
2640+
protected
2641+
DAE.Exp e1, e2;
2642+
Integer i, s;
2643+
algorithm
2644+
e1 :: e2 :: _ := args;
2645+
(cache, Values.INTEGER(i)) := ceval(cache, env, e1, impl, msg, numIter + 1);
2646+
(cache, Values.INTEGER(s)) := ceval(cache, env, e2, impl, msg, numIter + 1);
2647+
result := Values.INTEGER(intBitLShift(i, s));
2648+
end cevalIntBitLShift;
2649+
2650+
function cevalIntBitRShift
2651+
input output FCore.Cache cache;
2652+
input FCore.Graph env;
2653+
input list<DAE.Exp> args;
2654+
input Boolean impl;
2655+
input Absyn.Msg msg;
2656+
input Integer numIter;
2657+
output Values.Value result;
2658+
protected
2659+
DAE.Exp e1, e2;
2660+
Integer i, s;
2661+
algorithm
2662+
e1 :: e2 :: _ := args;
2663+
(cache, Values.INTEGER(i)) := ceval(cache, env, e1, impl, msg, numIter + 1);
2664+
(cache, Values.INTEGER(s)) := ceval(cache, env, e2, impl, msg, numIter + 1);
2665+
result := Values.INTEGER(intBitRShift(i, s));
2666+
end cevalIntBitRShift;
2667+
25732668
protected function makeLoadLibrariesEntry "Needed to be able to resolve modelica:// during runtime, etc.
25742669
Should not be part of CevalScript since ModelicaServices needs this feature and the frontend needs to take care of it."
25752670
input SCode.Element cl;

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,11 @@ algorithm
12971297
case "vector" then evalBuiltinVector(listHead(args));
12981298
case "zeros" then evalBuiltinZeros(args);
12991299
case "OpenModelica_uriToFilename" then evalUriToFilename(listHead(args));
1300+
case "intBitAnd" then evalIntBitAnd(args);
1301+
case "intBitOr" then evalIntBitOr(args);
1302+
case "intBitXor" then evalIntBitXor(args);
1303+
case "intBitLShift" then evalIntBitLShift(args);
1304+
case "intBitRShift" then evalIntBitRShift(args);
13001305
else
13011306
algorithm
13021307
Error.addInternalError(getInstanceName() + ": unimplemented case for " +
@@ -2231,6 +2236,76 @@ algorithm
22312236
end match;
22322237
end evalUriToFilename;
22332238

2239+
function evalIntBitAnd
2240+
input list<Expression> args;
2241+
output Expression result;
2242+
protected
2243+
Integer i1, i2;
2244+
algorithm
2245+
result := match args
2246+
case {Expression.INTEGER(value = i1), Expression.INTEGER(value = i2)}
2247+
then Expression.INTEGER(intBitAnd(i1, i2));
2248+
2249+
else algorithm printWrongArgsError(getInstanceName(), args, sourceInfo()); then fail();
2250+
end match;
2251+
end evalIntBitAnd;
2252+
2253+
function evalIntBitOr
2254+
input list<Expression> args;
2255+
output Expression result;
2256+
protected
2257+
Integer i1, i2;
2258+
algorithm
2259+
result := match args
2260+
case {Expression.INTEGER(value = i1), Expression.INTEGER(value = i2)}
2261+
then Expression.INTEGER(intBitOr(i1, i2));
2262+
2263+
else algorithm printWrongArgsError(getInstanceName(), args, sourceInfo()); then fail();
2264+
end match;
2265+
end evalIntBitOr;
2266+
2267+
function evalIntBitXor
2268+
input list<Expression> args;
2269+
output Expression result;
2270+
protected
2271+
Integer i1, i2;
2272+
algorithm
2273+
result := match args
2274+
case {Expression.INTEGER(value = i1), Expression.INTEGER(value = i2)}
2275+
then Expression.INTEGER(intBitXor(i1, i2));
2276+
2277+
else algorithm printWrongArgsError(getInstanceName(), args, sourceInfo()); then fail();
2278+
end match;
2279+
end evalIntBitXor;
2280+
2281+
function evalIntBitLShift
2282+
input list<Expression> args;
2283+
output Expression result;
2284+
protected
2285+
Integer i1, i2;
2286+
algorithm
2287+
result := match args
2288+
case {Expression.INTEGER(value = i1), Expression.INTEGER(value = i2)}
2289+
then Expression.INTEGER(intBitLShift(i1, i2));
2290+
2291+
else algorithm printWrongArgsError(getInstanceName(), args, sourceInfo()); then fail();
2292+
end match;
2293+
end evalIntBitLShift;
2294+
2295+
function evalIntBitRShift
2296+
input list<Expression> args;
2297+
output Expression result;
2298+
protected
2299+
Integer i1, i2;
2300+
algorithm
2301+
result := match args
2302+
case {Expression.INTEGER(value = i1), Expression.INTEGER(value = i2)}
2303+
then Expression.INTEGER(intBitRShift(i1, i2));
2304+
2305+
else algorithm printWrongArgsError(getInstanceName(), args, sourceInfo()); then fail();
2306+
end match;
2307+
end evalIntBitRShift;
2308+
22342309
function evalReduction
22352310
input Expression exp;
22362311
input Type ty;

0 commit comments

Comments
 (0)