Skip to content

Commit

Permalink
- Further changes from char* to const char*
Browse files Browse the repository at this point in the history
  - Now all strings in the simulation runtime should be const
- Implemented some additional external functions for libomcruntime.a


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7098 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 18, 2010
1 parent cbdc3b5 commit e04f2b1
Show file tree
Hide file tree
Showing 21 changed files with 307 additions and 315 deletions.
2 changes: 1 addition & 1 deletion Compiler/Inst.mo
Expand Up @@ -11086,7 +11086,7 @@ protected function instExtGetFname
algorithm
outIdent := matchcontinue (inExternalDecl,inIdent)
local String id,fid;
case (Absyn.EXTERNALDECL(funcName = SOME(id)),fid) then id;
case (Absyn.EXTERNALDECL(funcName = SOME(id)),_) then id;
case (Absyn.EXTERNALDECL(funcName = NONE()),fid) then fid;
end matchcontinue;
end instExtGetFname;
Expand Down
37 changes: 24 additions & 13 deletions Compiler/SimCodeC.mo
Expand Up @@ -16698,6 +16698,20 @@ algorithm
txt = Tpl.writeTok(txt, Tpl.ST_STRING(")) return 1;"));
then txt;

case ( txt,
SimCode.VARIABLE(name = (i_name as i_cr), ty = (i_ty as DAE.ET_STRING())) )
local
DAE.ExpType i_ty;
DAE.ComponentRef i_cr;
DAE.ComponentRef i_name;
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("if (read_"));
txt = expTypeArrayIf(txt, i_ty);
txt = Tpl.writeTok(txt, Tpl.ST_STRING("(&inArgs, (char**) &"));
txt = contextCref(txt, i_name, SimCode.contextFunction);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(")) return 1;"));
then txt;

case ( txt,
SimCode.VARIABLE(ty = i_ty, name = i_name) )
local
Expand Down Expand Up @@ -17801,17 +17815,16 @@ algorithm
local
Tpl.Text i_strVar;
equation
(i_strVar, i_varDecls) = tempDecl(Tpl.emptyTxt, "modelica_string", i_varDecls);
(i_strVar, i_varDecls) = tempDecl(Tpl.emptyTxt, "modelica_string_t", i_varDecls);
i_varCopy = Tpl.writeText(i_varCopy, i_strVar);
i_varCopy = Tpl.writeTok(i_varCopy, Tpl.ST_STRING(" = strdup("));
i_varCopy = contextCref(i_varCopy, i_var_name, SimCode.contextFunction);
i_varCopy = Tpl.writeTok(i_varCopy, Tpl.ST_STRING(");"));
i_varCopy = Tpl.writeTok(i_varCopy, Tpl.ST_NEW_LINE());
i_varAssign = Tpl.writeTok(i_varAssign, Tpl.ST_STRING("init_modelica_string(&"));
i_varAssign = Tpl.writeStr(i_varAssign, i_dest);
i_varAssign = Tpl.writeTok(i_varAssign, Tpl.ST_STRING(".targ"));
i_varAssign = Tpl.writeStr(i_varAssign, intString(i_ix));
i_varAssign = Tpl.writeTok(i_varAssign, Tpl.ST_STRING(","));
i_varAssign = Tpl.writeTok(i_varAssign, Tpl.ST_STRING(" = init_modelica_string("));
i_varAssign = Tpl.writeText(i_varAssign, i_strVar);
i_varAssign = Tpl.writeTok(i_varAssign, Tpl.ST_STRING_LIST({
");\n",
Expand Down Expand Up @@ -24816,9 +24829,8 @@ algorithm
i_e1,
i_tmpStr )
equation
txt = Tpl.writeTok(txt, Tpl.ST_STRING("cat_modelica_string(&"));
txt = Tpl.writeText(txt, i_tmpStr);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(","));
txt = Tpl.writeTok(txt, Tpl.ST_STRING(" = cat_modelica_string("));
txt = Tpl.writeText(txt, i_e1);
txt = Tpl.writeTok(txt, Tpl.ST_STRING(","));
txt = Tpl.writeText(txt, i_e2);
Expand Down Expand Up @@ -27163,10 +27175,10 @@ algorithm
(i_sExp, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_s, i_context, i_preExp, i_varDecls);
(i_formatExp, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_format, i_context, i_preExp, i_varDecls);
i_typeStr = expTypeFromExpModelica(Tpl.emptyTxt, i_s);
i_preExp = Tpl.writeText(i_preExp, i_typeStr);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING("_to_modelica_string_format(&"));
i_preExp = Tpl.writeText(i_preExp, i_tvar);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(", "));
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(" = "));
i_preExp = Tpl.writeText(i_preExp, i_typeStr);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING("_to_modelica_string_format("));
i_preExp = Tpl.writeText(i_preExp, i_sExp);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(", "));
i_preExp = Tpl.writeText(i_preExp, i_formatExp);
Expand Down Expand Up @@ -27195,10 +27207,10 @@ algorithm
(i_minlenExp, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_minlen, i_context, i_preExp, i_varDecls);
(i_leftjustExp, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_leftjust, i_context, i_preExp, i_varDecls);
i_typeStr = expTypeFromExpModelica(Tpl.emptyTxt, i_s);
i_preExp = Tpl.writeText(i_preExp, i_typeStr);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING("_to_modelica_string(&"));
i_preExp = Tpl.writeText(i_preExp, i_tvar);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(", "));
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(" = "));
i_preExp = Tpl.writeText(i_preExp, i_typeStr);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING("_to_modelica_string("));
i_preExp = Tpl.writeText(i_preExp, i_sExp);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(", "));
i_preExp = Tpl.writeText(i_preExp, i_minlenExp);
Expand Down Expand Up @@ -27230,9 +27242,8 @@ algorithm
(i_minlenExp, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_minlen, i_context, i_preExp, i_varDecls);
(i_leftjustExp, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_leftjust, i_context, i_preExp, i_varDecls);
(i_signdigExp, i_preExp, i_varDecls) = daeExp(Tpl.emptyTxt, i_signdig, i_context, i_preExp, i_varDecls);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING("modelica_real_to_modelica_string(&"));
i_preExp = Tpl.writeText(i_preExp, i_tvar);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(", "));
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(" = modelica_real_to_modelica_string("));
i_preExp = Tpl.writeText(i_preExp, i_sExp);
i_preExp = Tpl.writeTok(i_preExp, Tpl.ST_STRING(", "));
i_preExp = Tpl.writeText(i_preExp, i_minlenExp);
Expand Down
12 changes: 6 additions & 6 deletions Compiler/System.mo
Expand Up @@ -187,7 +187,7 @@ end getLinker;
public function setLDFlags
input String inString;

external "C" System_LDFlags(inString) annotation(Library = "omcruntime");
external "C" System_setLDFlags(inString) annotation(Library = "omcruntime");
end setLDFlags;

public function getLDFlags
Expand Down Expand Up @@ -252,12 +252,12 @@ end sendData;

public function enableSendData
input Boolean enable;
external "C" System_enableSendData(enable) annotation(Library = "omcruntime");
external "C" SystemImpl__enableSendData(enable) annotation(Library = "omcruntime");
end enableSendData;

public function setDataPort
input Integer port;
external "C" System_setDataPort(port) annotation(Library = "omcruntime");
external "C" SystemImpl__setDataPort(port) annotation(Library = "omcruntime");
end setDataPort;

public function setVariableFilter
Expand Down Expand Up @@ -301,7 +301,7 @@ end getVariableNames;
public function systemCall
input String inString;
output Integer outInteger;
external "C" outInteger=System_systemCall(inString) annotation(Library = "omcruntime");
external "C" outInteger=SystemImpl__systemCall(inString) annotation(Library = "omcruntime");
end systemCall;

public function cd
Expand Down Expand Up @@ -343,7 +343,7 @@ end moFiles;

public function time
output Real outReal;
external "C" outReal=System_time() annotation(Library = "omcruntime");
external "C" outReal=SystemImpl__time() annotation(Library = "omcruntime");
end time;

public function pathDelimiter
Expand All @@ -359,7 +359,7 @@ end groupDelimiter;
public function regularFileExists
input String inString;
output Boolean outBool;
external "C" outBool = System_regularFileExists(inString) annotation(Library = "omcruntime");
external "C" outBool = SystemImpl__regularFileExists(inString) annotation(Library = "omcruntime");
end regularFileExists;

public function removeFile "Removes a file, returns 0 if suceeds, implemented using remove() in stdio.h"
Expand Down
30 changes: 25 additions & 5 deletions Compiler/runtime/System_omc.cpp
Expand Up @@ -32,11 +32,6 @@

extern "C" {

extern int System_regularFileExists(const char* str)
{
return SystemImpl__regularFileExists(str)!=0;
}

extern void System_writeFile(const char* filename, const char* data)
{
if (SystemImpl__writeFile(filename, data))
Expand Down Expand Up @@ -147,4 +142,29 @@ extern const char* System_trim(const char* str, const char* chars_to_remove)
return SystemImpl__trim(str,chars_to_remove);
}

extern const char* System_basename(const char* str)
{
return strdup(SystemImpl__basename(str));
}

extern const char* System_configureCommandLine()
{
return CONFIGURE_COMMANDLINE;
}

extern const char* System_platform()
{
return CONFIG_PLATFORM;
}

extern const char* System_pathDelimiter()
{
return CONFIG_PATH_DELIMITER;
}

extern const char* System_groupDelimiter()
{
return CONFIG_GROUP_DELIMITER;
}

}

0 comments on commit e04f2b1

Please sign in to comment.