Skip to content

Commit

Permalink
implemented set_compile_command and get_compile_command
Browse files Browse the repository at this point in the history
reimplemented compile_model to use get_compile_command
reimplemented Compile.bat and Compile to use the new way to call the compilation

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1983 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x02lucpo committed Nov 24, 2005
1 parent ba3afc8 commit 7bb11d9
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 18 deletions.
85 changes: 70 additions & 15 deletions Compiler/Ceval.rml
Expand Up @@ -1233,13 +1233,20 @@ axiom ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("clear"),[],_,_),s
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("jacobian"),[Exp.CREF(cr,_)],_,_),st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (Values.STRING(res),Interactive.SYMBOLTABLE(p,sp,ic',iv,cf))

rule translate_model(env,cr,st,msg,filenameprefix) => (ret_val,st',_)
rule translate_model(env,cr,st,msg,filenameprefix) => (ret_val,st',_,_)
-------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("translateModel"),
[Exp.CREF(cr,_),filenameprefix],_,_),
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (ret_val,st')(*(Values.STRING("The model have been translated"),st')*)

rule System. set_compile_command(cmd)
-------------------------
ceval_interactive_functions (env, Exp.CALL(Absyn.IDENT("setCompileCommand"),
[Exp.SCONST(cmd)],_,_),
st as Interactive.SYMBOLTABLE(p,sp,ic,iv,cf),msg)
=> (Values.BOOL(true),st)


rule build_model(env,exp,st',msg) => (executable,method_str,st,initfilename)
-------------------------------
Expand Down Expand Up @@ -1677,8 +1684,10 @@ end
Msg,
Exp.Exp)

=> (Values.Value, Interactive.InteractiveSymbolTable,
DAELow.DAELow) =
=> (Values.Value,
Interactive.InteractiveSymbolTable,
DAELow.DAELow,
string list (*libs *)) =

rule extract_file_prefix(env,fileprefix,st,msg) => filenameprefix &
Static.component_ref_to_path(cr) => classname &
Expand Down Expand Up @@ -1718,7 +1727,7 @@ end
msg,
fileprefix)
=> (Values.STRING("The model have been translated"),st,
indexed_dlow')
indexed_dlow', libs)

rule Print.print_error_buf("# translate_model failed\n")
---------------------------------------------
Expand Down Expand Up @@ -1814,7 +1823,7 @@ relation build_model:(Env.Env,
Interactive.InteractiveSymbolTable,
string) (*initfilename*) =

rule translate_model(env,cr,st',msg,fileprefix) => (ret_val, st,indexed_dlow') &
rule translate_model(env,cr,st',msg,fileprefix) => (ret_val, st,indexed_dlow',libs) &
Static.component_ref_to_path(cr) => classname &
Absyn.path_string(classname) => cname_str &

Expand All @@ -1829,7 +1838,7 @@ relation build_model:(Env.Env,
generate_makefilename(filenameprefix) => makefilename &
(* Util.string_append_list(["make -f ",cname_str, ".makefile\n"]) => s_call &
*)
compile_model(makefilename)
compile_model(filenameprefix,libs)

-------------------------------------------
build_model(env,exp as Exp.CALL(Absyn.IDENT(_),
Expand Down Expand Up @@ -1883,35 +1892,81 @@ relation change_to_file_dir:(Absyn.ComponentRef, (* class *)

end

(** relation:libs_to_string
** author: x02lucpo
**
** makes a string list to "" if list is empty or \"lib1 lib2\" if some are present
**)
relation libs_to_string:(string list) => string =

axiom libs_to_string([]) => ""

rule Util.string_delimit_list_no_empty(libs," ") => libs_str &
Util.string_append_list(["\"",libs_str,"\""]) => libs_str'
-------------
libs_to_string(libs) => libs_str'


end



(** relation: compile_model
** author: PA
** author: PA, x02lucpo
**
** Compiles a model given a makefilename, helper relation to build_model.
** Compiles a model given a file-prefix, helper relation to build_model.
**)
relation compile_model: (string) => () =
relation compile_model: (string, string list) => () =

rule System.path_delimiter => pd &
rule System.get_compile_command => "" &
System.path_delimiter => pd &
System.read_env("OPENMODELICAHOME") => omhome &
System.trim(omhome,"\"") => omhome' &
win_citation() => cit &
System.pwd => cd_path &
libs_to_string(libs) => libs_str &
Util.string_append_list([cit,omhome', pd, "Compiler",
pd, "scripts", pd, "Compile",cit," ",
makefilename," > output.log 2>&1"
(*"\"",cd_path,"\""," ",*)
fileprefix, " ",
libs_str
]) => s_call &
(*> output.log 2>&1 = redirect stderr to stdout and put it in output.log *)

(* print s_call & print "<<<< 1\n" & *)
System.system_call(s_call) => 0
--------------------------
compile_model(makefilename) => ()
compile_model(fileprefix, libs) => ()

rule System.get_compile_command => command &
Util.is_empty_string(command) => false & (*needed when the above rule does not work*)
System.pwd => cd_path &
win_citation() => cit &
libs_to_string(libs) => libs_str &
Util.string_append_list([command," ",
(*cit,cd_path,cit," ",*)
fileprefix, " ",
libs_str
]) => s_call &
(*> output.log 2>&1 = redirect stderr to stdout and put it in output.log *)
(* print s_call & print "<<<< 2\n" & *)

System.system_call(s_call) => 0
--------------------------
compile_model(fileprefix,libs) => ()

(* compilation failed\n *)
rule System.read_file("output.log") => str &
rule Util.string_append_list([fileprefix,".log"]) => filename &
System.regular_file_exist(filename) => 0 &
System.read_file(filename) => str &
Print.print_error_buf ("#Error building simulation code.\n buildlog:\n") &
Print.print_error_buf (str) &
Print.print_error_buf "\n"
--------------------------
compile_model(makefile_name) => fail
compile_model(fileprefix,libs) => fail

rule Print.print_error_buf ("#Error building simulation code.\n ")
--------------------------
compile_model(fileprefix,libs) => fail
end

(** relation: win_citation
Expand Down
10 changes: 10 additions & 0 deletions Compiler/System.rml
Expand Up @@ -354,5 +354,15 @@ relation get_classnames_for_simulation: () => string
** this adds a classname to the simulation list
**)
relation set_classnames_for_simulation: string => ()

(** relation set_compile_command
** this sets the compilecommand for compilation
**)
relation set_compile_command: (string) => ()

(** relation get_compile_command
** this retrives the compilecommand for compilation
**)
relation get_compile_command: () => string
end

34 changes: 33 additions & 1 deletion Compiler/runtime/systemimpl.c
Expand Up @@ -24,6 +24,9 @@
typedef int _file_select_func_type(const struct dirent *);
typedef int _file_compar_func_type(const struct dirent **, const struct dirent **);




void reallocdirents(struct dirent ***entries,
unsigned int oldsize,
unsigned int newsize) {
Expand Down Expand Up @@ -232,12 +235,13 @@ char *replace(const char *src, const char *from, const char *to)
return value;
}


void System_5finit(void)
{
set_cc("gcc");

set_cflags("-I$OPENMODELICAHOME/c_runtime -L$OPENMODELICAHOME/c_runtime -lc_runtime -lm $MODELICAUSERCFLAGS");


}

RML_BEGIN_LABEL(System__strtok)
Expand Down Expand Up @@ -1088,3 +1092,31 @@ RML_BEGIN_LABEL(System__set_5fclassnames_5ffor_5fsimulation)
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

char* compile_command = NULL;

RML_BEGIN_LABEL(System__set_5fcompile_5fcommand)
{
char* command = RML_STRINGDATA(rmlA0);
if(compile_command)
free(compile_command);

compile_command = (char*)malloc(strlen(command)+1);
if (compile_command == NULL) {
RML_TAILCALLK(rmlFC);
}
memcpy(compile_command,command,strlen(command)+1);

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__get_5fcompile_5fcommand)
{
if(compile_command)
rmlA0 = (void*) mk_scon(strdup(compile_command));
else
rmlA0 = (void*) mk_scon("");
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
2 changes: 1 addition & 1 deletion Compiler/scripts/Compile
@@ -1,2 +1,2 @@
#!/bin/sh
make -f $1 > /dev/null
make -f $1.makefile > /dev/null
2 changes: 1 addition & 1 deletion Compiler/scripts/Compile.bat
Expand Up @@ -4,7 +4,7 @@ set OLDPATH=%PATH%
pushd "%OPENMODELICAHOME%\MinGW\bin"
set PATH=%CD%
popd
mingw32-make -f %1 >nul
mingw32-make -f %1.makefile >nul
set RESULT=%ERRORLEVEL%
set PATH=%OLDPATH%
rem exit %RESULT%
27 changes: 27 additions & 0 deletions Compiler/winruntime/systemimpl.c
Expand Up @@ -1082,3 +1082,30 @@ RML_BEGIN_LABEL(System__set_5fclassnames_5ffor_5fsimulation)
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

char* compile_command = NULL;
RML_BEGIN_LABEL(System__set_5fcompile_5fcommand)
{
char* command = RML_STRINGDATA(rmlA0);
if(compile_command)
free(compile_command);

compile_command = (char*)malloc(strlen(command)+1);
if (compile_command == NULL) {
RML_TAILCALLK(rmlFC);
}
memcpy(compile_command,command,strlen(command)+1);

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__get_5fcompile_5fcommand)
{
if(compile_command)
rmlA0 = (void*) mk_scon(strdup(compile_command));
else
rmlA0 = (void*) mk_scon("");
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

0 comments on commit 7bb11d9

Please sign in to comment.