Skip to content

Commit

Permalink
Fixed bug with citation quotes on simulate command. Improved code gen…
Browse files Browse the repository at this point in the history
…eration of functions for simulation code. Added calculation of simple equations in simulation code. Fixed comment bug in comments from variables in simulation code.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1884 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Aug 22, 2005
1 parent 3cf7d77 commit 70568d5
Show file tree
Hide file tree
Showing 5 changed files with 339 additions and 53 deletions.
35 changes: 27 additions & 8 deletions Compiler/Ceval.rml
Expand Up @@ -1205,7 +1205,7 @@ end
Util.string_append_list([cname_str,".cpp"]) => filename &
Util.string_append_list([cname_str,"_functions.cpp"]) => funcfilename &
Util.string_append_list([cname_str,".makefile"]) => makefilename &
SimCodegen.generate_functions(dae,indexed_dlow',classname,funcfilename) &
SimCodegen.generate_functions(p',dae,indexed_dlow',classname,funcfilename) &
SimCodegen.generate_simulation_code(dae,indexed_dlow',ass1,ass2,m,mT,comps,classname,filename) &
SimCodegen.generate_makefile(makefilename,classname)
(* Util.string_append_list(["make -f ",cname_str, ".makefile\n"]) => s_call &
Expand Down Expand Up @@ -1249,25 +1249,26 @@ end
Util.string_append_list([cname_str,"_functions.cpp"]) => funcfilename &
Util.string_append_list([cname_str,"_init.txt"]) => init_filename &
Util.string_append_list([cname_str,".makefile"]) => makefilename &
SimCodegen.generate_functions(dae,indexed_dlow',classname,funcfilename) &
SimCodegen.generate_functions(p',dae,indexed_dlow',classname,funcfilename) &
SimCodegen.generate_simulation_code(dae,indexed_dlow',ass1,ass2,m,mT,comps,classname,filename) &
SimCodegen.generate_init_data(indexed_dlow',classname,init_filename,
starttime_r,stoptime_r,stepsize_r) &
SimCodegen.generate_makefile(makefilename,classname) &
(* Util.string_append_list(["make -f ",cname_str, ".makefile\n"]) => s_call &
*)
System.path_delimiter => pd &
System.read_env("OPENMODELICAHOME") => omhome &
Util.string_append_list(["\"",omhome, pd, "Compiler",
System.read_env("OPENMODELICAHOME") => omhome &
win_citation() => cit &
Util.string_append_list([cit,omhome, pd, "Compiler",
pd, "scripts", pd, "Compile ",
makefilename," > output.log 2>&1",
"\""]) => s_call &
makefilename," > output.log 2>&1",cit
]) => s_call &
(*> output.log 2>&1 = redirect stderr to stdout and put it in output.log *)

System.system_call(s_call) => 0 &
Util.string_append_list(["\"",".", pd, cname_str, " -m ",
Util.string_append_list([cit,".", pd, cname_str, " -m ",
method_str," >> output.log 2>&1",
"\""]) => sim_call &
cit]) => sim_call &
System.system_call(sim_call) => _ &
Util.string_append_list([cname_str,"_res.plt"]) => result_file &
let simValue = Values.RECORD(Absyn.IDENT("SimulationResult"),[Values.STRING(result_file)],["resultFile"]) &
Expand Down Expand Up @@ -1618,6 +1619,24 @@ end

end

(** relation: win_citation
** author: PA
**
** Returns a cition mark if platform is windows, otherwise empty string. Used
** by simulate to make whitespaces work in filepaths for WIN32
**)
relation win_citation: () => string =


rule System.platform => "WIN32"
-------------------
win_citation () => "\""

axiom win_citation() => ""
end



(** relation: get_builtin_attribute
**
** Retrieves a builtin attribute of a variable in a class by instantiating
Expand Down
37 changes: 31 additions & 6 deletions Compiler/Codegen.rml
Expand Up @@ -651,8 +651,6 @@ relation generate_function : DAE.Element => CFunction list =
(* External functions *)
rule generate_function_name fpath => fn_name_str &
Debug.fprintl ("cgtr", ["generating external function ", fn_name_str, "\n"]) &


let DAE.EXTERNALDECL(extfnname,extargs,extretarg,lang) = extdecl &

Debug.fprintln ("cgtrdumpdae1", "Dumping DAE:") &
Expand All @@ -671,7 +669,7 @@ relation generate_function : DAE.Element => CFunction list =
generate_ext_function_args (extargs, lang) => arg_strs &
c_make_function_decl(retstr,extfnname',struct_strs,arg_strs) => func_decl &
generate_read_call_write_external(fn_name_str,outvars,retstructtype,invars,extdecl,bivars) => rcw_fn
---------------------------------------------------------------------------------------------
-----------------------------------------------------------------------
generate_function DAE.EXTFUNCTION(fpath,
DAE.DAE(orgdae),
(Types.T_FUNCTION(args,restype),_),
Expand All @@ -682,12 +680,10 @@ relation generate_function : DAE.Element => CFunction list =
----------------------
generate_function DAE.COMP(n, DAE.DAE(daelist)) => cfns


rule Print.print_buf "# generate_function failed\n" &
DAE.dump2 DAE.DAE([comp])
------------------------------------
generate_function comp => fail

generate_function comp => fail
end


Expand Down Expand Up @@ -715,11 +711,22 @@ end
**
** All Modelica functions translates to a C function returning all
** Modelica ouput parameters in a struct. This relation generates that struct.
** Exception: Functions only returning one value does not need a struct.
**)

relation generate_result_struct : (DAE.Element list, Absyn.Path)
=> string list =

(* functions with one return value *)
rule generate_return_type fpath => ptname &
generate_single_return_type outvar => (type_str) &
Util.string_append_list(["typedef ",ptname," ", type_str, ";\n"])
=> res
-----------------------------------------
generate_result_struct ([outvar], fpath) => [res]


(* functions with several return values *)
rule generate_return_type fpath => ptname &
generate_return_decls outvars => (var_strs,var_names) &
generate_return_defs (ptname,var_names,1) => defs &
Expand Down Expand Up @@ -815,6 +822,24 @@ relation generate_return_decl: DAE.Element => (string, string) =

end

(** relation: generate_single_return_type
**
** Helper relation to generate_result_struct
**)

relation generate_single_return_type: DAE.Element => (string) =

rule is_array var => is_a &
dae_type_str (typ,is_a) => typ_str
---------------------------------------------------
generate_single_return_type (var as DAE.VAR(id, DAE.VARIABLE, DAE.OUTPUT,
typ, initopt, inst_dims,start,
flow,class,dae_var_attr,comment))
=> typ_str

axiom generate_single_return_type (_) => ""
end

(** relation: is_array
**
** Returns true if variable is part of an array.
Expand Down
15 changes: 13 additions & 2 deletions Compiler/DAELow.rml
Expand Up @@ -4959,8 +4959,10 @@ relation translate_dae: DAELow => DAELow =
calculate_indexes(varlst,knvarlst) => (varlst',knvarlst') &
list_append(varlst',knvarlst') => totvars &
equation_list(eqns) => eqnsl &
equation_list(seqns) => seqnsl &
variable_replacements(totvars,eqnsl) => (s,t) &
replace_variables(eqnsl,s,t) => eqnsl' &
replace_variables(seqnsl,s,t) => seqnsl' &
replace_variables_in_alg(al,s,t) => al' &
replace_variables_in_when_clauses(wc,s,t) => wc' &
transform_variables(varlst',s,t) => varlst'' &
Expand All @@ -4969,10 +4971,11 @@ relation translate_dae: DAELow => DAELow =
empty_vars() => knvars' &
add_vars(varlst'',vars') => vars'' &
add_vars(knvarlst'',knvars') => knvars'' &
list_equation(eqnsl') => eqns'
list_equation(eqnsl') => eqns' &
list_equation(seqnsl') => seqns'
------------------------------------
translate_dae(DAELOW(vars,knvars,eqns,seqns,ie,al,EVENT_INFO(wc,zc)))
=> DAELOW(vars'',knvars'',eqns',seqns,ie,al',EVENT_INFO(wc',zc))
=> DAELOW(vars'',knvars'',eqns',seqns',ie,al',EVENT_INFO(wc',zc))
end

(** relation: replace_variables_in_when_clauses
Expand Down Expand Up @@ -5688,6 +5691,14 @@ relation replace_variables: (Equation list,
---------------------------------------
replace_variables(EQUATION(e1,e2)::es,s,t) => EQUATION(e1',e2')::es'

rule Exp.replace_exp_list(Exp.CREF(cr,Exp.OTHER),s,t)
=> (Exp.CREF(cr',_),_) &
Exp.replace_exp_list(e1,s,t) => (e1',_) &
replace_variables(es,s,t) => es'
---------------------------------------
replace_variables(SOLVED_EQUATION(cr,e1)::es,s,t)
=> SOLVED_EQUATION(cr',e1')::es'

rule let e1 = Exp.CREF(cr,Exp.OTHER) &
Exp.replace_exp_list(e1,s,t) => (e1' as Exp.CREF(cr',_),_) &
Exp.replace_exp_list(e2,s,t) => (e2',_) &
Expand Down
73 changes: 72 additions & 1 deletion Compiler/Inst.rml
Expand Up @@ -209,6 +209,7 @@ module Inst:
=> Types.Binding

relation instantiate_class : (SCode.Program,SCode.Path) => (DAE.DAElist,Env.Env)
relation instantiate_class_implicit : (SCode.Program,SCode.Path) => (DAE.DAElist,Env.Env)

relation make_env_from_program: (SCode.Program,SCode.Path) => Env.Env
relation make_simple_env_from_program: (SCode.Program,SCode.Path) => Env.Env
Expand Down Expand Up @@ -408,7 +409,7 @@ end
** needs to be possible to instantiate. This relation performs the same
** action as `inst_program', but given a specific class to instantiate.
**
** First, all the class definitions is added to the environment without
** First, all the class definitions are added to the environment without
** modifications, and then the specified class is instantiated in the
** relation `inst_class_in_program'
**)
Expand Down Expand Up @@ -445,6 +446,46 @@ relation instantiate_class : (SCode.Program, SCode.Path)
instantiate_class(_,_) => fail
end

(** relation: instantiate_class_implicit
** author: PA
**
** Similar to instantiate_class, i.e. instantation of arbitrary classes
** but this one instantiates the class implicit, e.g. for functions.
**)

relation instantiate_class_implicit : (SCode.Program, SCode.Path)
=> (DAE.DAElist,Env.Env) =

rule Print.print_error_buf "# Empty program\n"
------------------------------
instantiate_class_implicit([],cr) => fail

(* top level class *)
rule Builtin.initial_env => env &
inst_class_decls(env,cdecls,path) => (env',dae1) &
inst_class_in_program_implicit(env',cdecls,path) => (dae,env'')
---------------------------------------------------------------
instantiate_class_implicit(cdecls as _::_, path as Absyn.IDENT(name2))
=> (DAE.DAE(dae),env'')

(* class in package *)
rule Builtin.initial_env => env &
inst_class_decls(env,cdecls,path)=> (env',_) &
Lookup.lookup_class(env',path,true)
=> (cdef as SCode.CLASS(n,_,_,_,_), env'') &
print "found class to instantiate implicit\n" &
implicit_instantiation(env'',Types.NOMOD,Prefix.NOPRE,[],cdef,[],false)
=> (env,dae)
& print "instantiated class\n"
--------------------------------------------
instantiate_class_implicit(cdecls as _::_, path as Absyn.QUALIFIED(name,_))
=> (DAE.DAE(dae),env)

rule print "-instantiate_class_implicit failed\n"
------------
instantiate_class_implicit(_,_) => fail
end

(** relation: inst_class_in_program
**
** Instantitates a specifc class in a Program. The class must reside on top
Expand Down Expand Up @@ -475,6 +516,36 @@ relation inst_class_in_program: (Env, SCode.Program, SCode.Path )

end

(** relation: inst_class_in_program_implicit
**
** Instantitates a specifc class in a Program using implicit instatiation.
** The class must reside on top level.
**)

relation inst_class_in_program_implicit: (Env, SCode.Program, SCode.Path )
=> (DAE.Element list, Env.Env) =

rule name = name2 &
implicit_instantiation(env, Types.NOMOD, Prefix.NOPRE, [], c, [], false(*packimpl*))
=> ( env',dae)
-------------------------------------------------------------
inst_class_in_program_implicit(env,(c as SCode.CLASS(name,_,_,_,_))::cs,Absyn.IDENT(name2))
=> (dae,env')

rule not name = name2 &
inst_class_in_program_implicit(env,cs,path) => (dae,env)
-------------------------------------------------------------
inst_class_in_program_implicit(env,(c as SCode.CLASS(name,_,_,_,_))::cs, path as Absyn.IDENT(name2))
=> (dae, env)

axiom inst_class_in_program_implicit(env,[],_) => ([],env)

rule (*Debug.fprint("failtrace", "inst_class_in_program failed\n")*)
-------------------------------
inst_class_in_program_implicit(env,_,_) => fail

end

(** relation: inst_class_decls
**
** This relation instantiated class definitions, i.e. adding the class
Expand Down

0 comments on commit 70568d5

Please sign in to comment.