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

Commit

Permalink
Initial commit for embedded C code generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Nov 30, 2016
1 parent 8dcb443 commit debe19c
Show file tree
Hide file tree
Showing 8 changed files with 745 additions and 7 deletions.
30 changes: 30 additions & 0 deletions Compiler/SimCode/SimCodeMain.mo
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import Builtin;
import ClockIndexes;
import CevalScriptBackend;
import CodegenC;
import CodegenEmbeddedC;
import CodegenFMU;
import CodegenFMUCpp;
import CodegenFMUCppHpcom;
Expand Down Expand Up @@ -713,6 +714,35 @@ algorithm
Tpl.closeFile(Tpl.tplCallWithFailError3(CodegenC.simulationMakefile,Config.simulationCodeTarget(),simCode,strs,txt=Tpl.redirectToFile(Tpl.emptyTxt, simCode.fileNamePrefix+".makefile")));
then ();

case "ExperimentalEmbeddedC"
algorithm
guid := System.getUUIDStr();

System.realtimeTick(ClockIndexes.RT_PROFILER0);
codegenFuncs := {};
for f in {
(CodegenEmbeddedC.mainFile, "_main.c")
} loop
(func,str) := f;
codegenFuncs := (function runTplWriteFile(func=function func(a_simCode=simCode), file=simCode.fileNamePrefix + str)) :: codegenFuncs;
end for;

// Test the parallel code generator in the test suite. Should give decent results given that the task is disk-intensive.
numThreads := max(1, if Config.getRunningTestsuite() then min(2, System.numProcessors()) else Config.noProc());
if (not Flags.isSet(Flags.PARALLEL_CODEGEN)) or numThreads==1 then
res := list(func() for func in codegenFuncs);
else
res := System.launchParallelTasks(numThreads, codegenFuncs, runCodegenFunc);
end if;
strs := {};
for tpl in res loop
(true,tmp) := tpl;
strs := List.append_reverse(tmp, strs);
end for;
strs := listReverse(strs);
// write the makefile last!
then ();

case "JavaScript" equation
guid = System.getUUIDStr();
Tpl.tplNoret(CodegenC.translateModel, simCode);
Expand Down
8 changes: 4 additions & 4 deletions Compiler/Template/CodegenCFunctions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5493,7 +5493,7 @@ template daeExpCall(Exp call, Context context, Text &preExp, Text &varDecls, Tex
expLst={e1, e2}) then
let var1 = daeExp(e1, context, &preExp, &varDecls, &auxFunction)
let var2 = daeExp(e2, context, &preExp, &varDecls, &auxFunction)
'<%var2%>'
var2

case CALL(path=IDENT(name="DIVISION"),
expLst={e1, e2}) then
Expand Down Expand Up @@ -5995,7 +5995,7 @@ simple_alloc_1d_base_array(&<%tvar%>, <%nElts%>, <%tvardata%>);
case PARALLEL_FUNCTION_CONTEXT(__) then res
else
if boolAnd(profileFunctions(),boolNot(attr.builtin)) then
let funName = '<%underscorePath(exp.path)%>'
let funName = underscorePath(exp.path)
let tvar = match attr.ty
case T_NORETCALL(__) then
""
Expand Down Expand Up @@ -6918,8 +6918,8 @@ template crefShortType(ComponentRef cr) "template crefType
Like cref but with cast if type is integer."
::=
match cr
case CREF_IDENT(__) then '<%expTypeShort(identType)%>'
case CREF_QUAL(__) then '<%crefShortType(componentRef)%>'
case CREF_IDENT(__) then expTypeShort(identType)
case CREF_QUAL(__) then crefShortType(componentRef)
else "crefType:ERROR"
end match
end crefShortType;
Expand Down

0 comments on commit debe19c

Please sign in to comment.