Skip to content

Commit

Permalink
- Fixed codegen for div()
Browse files Browse the repository at this point in the history
- Moved some MetaModelica builtin functions (Boolean/Integer) to Builtin.mo instead of C sources


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7356 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 11, 2010
1 parent 58a5043 commit 35b051d
Show file tree
Hide file tree
Showing 6 changed files with 1,072 additions and 1,066 deletions.
233 changes: 203 additions & 30 deletions Compiler/Builtin.mo
Expand Up @@ -194,6 +194,201 @@ end print;
"
;

protected constant String initialFunctionStrMM =
"
function boolAnd
input Boolean b1;
input Boolean b2;
output Boolean b;
annotation(Inline = true);
algorithm
b := b1 and b2;
end boolAnd;

function boolOr
input Boolean b1;
input Boolean b2;
output Boolean b;
annotation(Inline = true);
algorithm
b := b1 or b2;
end boolOr;

function boolNot
input Boolean b;
output Boolean nb;
annotation(Inline = true);
algorithm
nb := not b;
end boolNot;

function boolEq
input Boolean b1;
input Boolean b2;
output Boolean b;
annotation(Inline = true);
algorithm
b := b1 == b2;
end boolEq;

function boolString
input Boolean b;
output String str;
annotation(Inline = true);
algorithm
str := if b then \"true\" else \"false\";
end boolString;

function intAdd
input Integer i1;
input Integer i2;
output Integer i;
annotation(Inline = true);
algorithm
i := i1 + i2;
end intAdd;

function intSub
input Integer i1;
input Integer i2;
output Integer i;
annotation(Inline = true);
algorithm
i := i1 - i2;
end intSub;

function intMul
input Integer i1;
input Integer i2;
output Integer i;
annotation(Inline = true);
algorithm
i := i1 * i2;
end intMul;

function intDiv
input Integer i1;
input Integer i2;
output Integer i;
annotation(Inline = true);
algorithm
i := div(i1,i2);
end intDiv;

function intMod
input Integer i1;
input Integer i2;
output Integer i;
annotation(Inline = true);
algorithm
i := mod(i1,i2);
end intMod;

function intMax
input Integer i1;
input Integer i2;
output Integer i;
annotation(Inline = true);
algorithm
i := max(i1,i2);
end intMax;

function intMin
input Integer i1;
input Integer i2;
output Integer i;
annotation(Inline = true);
algorithm
i := min(i1,i2);
end intMin;

function intAbs
input Integer i;
output Integer oi;
annotation(Inline = true);
algorithm
oi := abs(i);
end intAbs;

function intNeg
input Integer i;
output Integer oi;
annotation(Inline = true);
algorithm
oi := -i;
end intNeg;

function intLt
input Integer i1;
input Integer i2;
output Boolean b;
annotation(Inline = true);
algorithm
b := i1 < i2;
end intLt;

function intLe
input Integer i1;
input Integer i2;
output Boolean b;
annotation(Inline = true);
algorithm
b := i1 <= i2;
end intLe;

function intEq
input Integer i1;
input Integer i2;
output Boolean b;
annotation(Inline = true);
algorithm
b := i1 == i2;
end intEq;

function intNe
input Integer i1;
input Integer i2;
output Boolean b;
annotation(Inline = true);
algorithm
b := i1 <> i2;
end intNe;

function intGe
input Integer i1;
input Integer i2;
output Boolean b;
annotation(Inline = true);
algorithm
b := i1 >= i2;
end intGe;

function intGt
input Integer i1;
input Integer i2;
output Boolean b;
annotation(Inline = true);
algorithm
b := i1 > i2;
end intGt;

function intReal
input Integer i;
output Real r;
annotation(Inline = true);
algorithm
r := i;
end intReal;

function intString
input Integer i;
output String s;
external \"builtin\";
end intString;

"
;

// Predefined DAE.Types
// Real arrays
protected constant DAE.Type T_REAL_ARRAY_DEFAULT =
Expand Down Expand Up @@ -2482,7 +2677,6 @@ public function initialEnv "function: initialEnv
input Env.Cache inCache;
output Env.Cache outCache;
output list<Env.Frame> env;
list<Env.Frame> env;
Env.Cache cache;
algorithm
(outCache,env) := matchcontinue(inCache)
Expand Down Expand Up @@ -2976,35 +3170,6 @@ algorithm
true = RTOpts.acceptMetaModelicaGrammar();
env = Env.extendFrameT(env, "mmc_boxes_equal", AA2bool);

// Boolean Operations
env = Env.extendFrameT(env, "boolAnd", boolBool2bool);
env = Env.extendFrameT(env, "boolOr", boolBool2bool);
env = Env.extendFrameT(env, "boolNot", bool2bool);
env = Env.extendFrameT(env, "boolEq", boolBool2bool);
env = Env.extendFrameT(env, "boolString", bool2string);

// Integer Operations
env = Env.extendFrameT(env, "intAdd", intInt2int);
env = Env.extendFrameT(env, "intSub", intInt2int);
env = Env.extendFrameT(env, "intMul", intInt2int);
env = Env.extendFrameT(env, "intDiv", intInt2int);
env = Env.extendFrameT(env, "intMod", intInt2int);
env = Env.extendFrameT(env, "intMax", intInt2int);
env = Env.extendFrameT(env, "intMin", intInt2int);

env = Env.extendFrameT(env, "intAbs", int2int);
env = Env.extendFrameT(env, "intNeg", int2int);

env = Env.extendFrameT(env, "intLt", intInt2bool);
env = Env.extendFrameT(env, "intLe", intInt2bool);
env = Env.extendFrameT(env, "intEq", intInt2bool);
env = Env.extendFrameT(env, "intNe", intInt2bool);
env = Env.extendFrameT(env, "intGe", intInt2bool);
env = Env.extendFrameT(env, "intGt", intInt2bool);

env = Env.extendFrameT(env, "intReal", int2real);
env = Env.extendFrameT(env, "intString", int2string);

// Real Operations
env = Env.extendFrameT(env, "realAdd", realReal2real);
env = Env.extendFrameT(env, "realSub", realReal2real);
Expand Down Expand Up @@ -3126,10 +3291,18 @@ algorithm
then initialProgram;*/
case ()
equation
false = RTOpts.acceptMetaModelicaGrammar();
(initialProgram,msg) = Parser.parsestring(initialFunctionStr);
Error.assertion(msg ==& "Ok", msg, Absyn.dummyInfo);
//setGlobalRoot...
then initialProgram;
case ()
equation
true = RTOpts.acceptMetaModelicaGrammar();
(initialProgram,msg) = Parser.parsestring(initialFunctionStr +& initialFunctionStrMM);
Error.assertion(msg ==& "Ok", msg, Absyn.dummyInfo);
//setGlobalRoot...
then initialProgram;
end matchcontinue;
end getInitialFunctions;

Expand Down
6 changes: 6 additions & 0 deletions Compiler/Lookup.mo
Expand Up @@ -2145,6 +2145,12 @@ algorithm
list<Env.Frame> i_env;
Absyn.Path path;
Env.Cache cache;
case (cache,path)
equation
(cache,i_env) = Builtin.initialEnv(cache);
(cache,SCode.CLASS(restriction = SCode.R_FUNCTION()),_) = lookupClass(cache,i_env,path,false);
// External functions without external declaration have parts. We don't consider them builtin.
then (cache,false);
case (cache,path)
equation
(cache,i_env) = Builtin.initialEnv(cache);
Expand Down

0 comments on commit 35b051d

Please sign in to comment.