Skip to content

Commit 8029771

Browse files
committed
Merged and resolved conflicts but examples not working.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1017 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 8fa5398 commit 8029771

File tree

6 files changed

+281
-39
lines changed

6 files changed

+281
-39
lines changed

modeq/codegen.rml

Lines changed: 150 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,22 @@ relation generate_return_decls : DAE.Element list => (string list,
542542

543543
end
544544

545+
relation tmpprintinit : Exp.Exp option => string =
546+
547+
axiom tmpprintinit NONE => ""
548+
549+
rule Exp.print_exp_str e => str &
550+
Util.string_append_list ([" /* ", str, " */"]) => str1
551+
--------------------------
552+
tmpprintinit SOME(e) => str1
553+
554+
end
545555

546556
relation generate_return_decl: DAE.Element => (string, string) =
547557

558+
(* changed DAE.VAR(..., NONE, inst_dims) to ..._, inst_dims) because removed second *)
559+
(* rule *)
560+
548561
rule is_array id => is_a &
549562
is_first_in_array id => true &
550563
dae_type_str (typ,is_a) => typ_str &
@@ -553,19 +566,23 @@ relation generate_return_decl: DAE.Element => (string, string) =
553566
Util.string_delimit_list(dim_strs,", ") => dims_str &
554567
Util.string_append_list([typ_str," ",id_str,";",
555568
" /* [",dims_str,"] */"])
556-
=> decl_str
569+
=> decl_str' &
570+
tmpprintinit initopt => expstr &
571+
string_append(decl_str', expstr) => decl_str
557572
---------------------------------------------------
558-
generate_return_decl (DAE.VAR(id, DAE.VARIABLE, DAE.OUTPUT, typ, NONE,inst_dims))
559-
=> (decl_str,id_str)
573+
generate_return_decl (DAE.VAR(id, DAE.VARIABLE, DAE.OUTPUT,
574+
typ, initopt, inst_dims)) => (decl_str,id_str)
560575

576+
(* not needed here, generate_return_decl is used to create the return struct
561577
rule is_array id => is_a &
562578
is_first_in_array id => true &
563579
dae_type_str (typ,is_a) => typ_str &
564580
comp_ref_cstr id => (id_str,_) &
565-
Util.string_append_list([typ_str," ",id_str,";"]) => decl_str &
581+
Util.string_append_list([typ_str," ",id_str,";"]) => decl_str' &
566582
Print.print_buf "# default/init values not implemented yet: " &
567583
Exp.print_exp_str e => str & Print.print_buf str &
568-
Print.print_buf "\n"
584+
Print.print_buf "\n" &
585+
Util.string_append_list ([decl_str', " /* ", str, " */"]) => decl_str
569586
-----------
570587
generate_return_decl (DAE.VAR(id,
571588
DAE.VARIABLE,
@@ -574,7 +591,7 @@ relation generate_return_decl: DAE.Element => (string, string) =
574591
SOME(e),
575592
_))
576593
=> (decl_str,id_str)
577-
594+
*)
578595

579596
axiom generate_return_decl (_) => ("","")
580597

@@ -592,6 +609,25 @@ relation is_array : Exp.ComponentRef => bool =
592609

593610
end
594611

612+
relation is_array_or_string : (Exp.ComponentRef, DAE.Type) => bool =
613+
614+
rule is_array cr => true &
615+
Print.print_buf "#-- array of strings is probably not supported yet\n"
616+
------------------------------------------------------------------
617+
is_array_or_string (cr, DAE.STRING) => fail
618+
619+
rule is_array cr => true
620+
-------------------
621+
is_array_or_string (cr, _) => true
622+
623+
axiom is_array_or_string (_, DAE.STRING) => true
624+
625+
rule Print.print_buf "#-- is_array_or_string failed\n"
626+
------------------------------------------------------------------
627+
is_array_or_string (_,_) => fail
628+
629+
end
630+
595631
relation is_first_in_array : Exp.ComponentRef => bool =
596632

597633
axiom is_first_in_array Exp.CREF_IDENT(_,[]) => true
@@ -753,7 +789,7 @@ relation generate_type_internal_namepart : Types.Type => string =
753789
axiom generate_type_internal_namepart((Types.T_REAL(_),_)) => "real"
754790
axiom generate_type_internal_namepart((Types.T_STRING(_),_)) => "string"
755791
axiom generate_type_internal_namepart((Types.T_BOOL(_),_)) => "boolean"
756-
axiom generate_type_internal_namepart((Types.T_ENUM,_)) => "NOT_IMPLEMENTED"
792+
axiom generate_type_internal_namepart((Types.T_ENUM,_)) => "T_ENUM_NOT_IMPLEMENTED"
757793

758794
end
759795

@@ -891,6 +927,11 @@ relation generate_function_arg : Types.FuncArg => string =
891927

892928
end
893929

930+
(* FIXME : shouldn't it be "const <type> *" instead of
931+
<type> const *"
932+
changed this already.
933+
*)
934+
894935
relation generate_ext_arg_type : (Types.Attributes, Types.Type) => string =
895936

896937
rule Types.is_array ty => false &
@@ -900,7 +941,7 @@ relation generate_ext_arg_type : (Types.Attributes, Types.Type) => string =
900941

901942
rule Types.is_array ty => true &
902943
generate_type_external ty => str &
903-
string_append(str," const *") => resstr
944+
Util.string_append_list(["const ",str," *"]) => resstr
904945
----------------------------------------------------
905946
generate_ext_arg_type (Types.ATTR(_,_,_,Absyn.INPUT), ty) => resstr
906947

@@ -960,7 +1001,7 @@ end
9601001
relation generate_ext_arg_type_f77 : (Types.Attributes, Types.Type) => string =
9611002

9621003
rule generate_type_external ty => str &
963-
string_append(str," const *") => resstr
1004+
Util.string_append_list(["const ", str, " *"]) => resstr
9641005
----------------------------------------------------
9651006
generate_ext_arg_type_f77 (Types.ATTR(_,_,_,Absyn.INPUT), ty) => resstr
9661007

@@ -1192,6 +1233,30 @@ end
11921233

11931234
relation generate_alloc_outvar_f77 : (DAE.Element,string,int) => (CFunction,int) =
11941235

1236+
rule is_array id => is_a &
1237+
is_first_in_array id => true &
1238+
dae_type_str (typ,is_a) => typ_str &
1239+
comp_ref_cstr id => (cref_str,_) &
1240+
(* list_reverse inst_dims => inst_dims' & *)
1241+
generate_size_subscripts(inst_dims,tnr) => (cfn1,dim_strs,tnr1) &
1242+
c_move_statements_to_inits cfn1 => cfn1' &
1243+
1244+
list_length dim_strs => ndims &
1245+
int_string ndims => ndims_str &
1246+
Util.string_delimit_list(dim_strs,", ") => dims_str &
1247+
Util.string_append_list(["alloc_",typ_str,
1248+
"(&",cref_str,", ",
1249+
ndims_str,", ",dims_str,");"])
1250+
=> alloc_str &
1251+
1252+
c_add_inits(cfn1',[alloc_str]) => cfn' &
1253+
Util.if (is_a,cfn',cfn1') => cfn
1254+
-----------
1255+
generate_alloc_outvar_f77(DAE.VAR(id, vk, DAE.BIDIR, typ, e,inst_dims),
1256+
prefix,
1257+
tnr)
1258+
=> (cfn,tnr1)
1259+
11951260
rule is_array id => is_a &
11961261
is_first_in_array id => true &
11971262
dae_type_str (typ,is_a) => typ_str &
@@ -1596,7 +1661,46 @@ relation generate_var_decls : (DAE.Element list,DAE.Element => (),int)
15961661

15971662
end
15981663

1664+
relation generate_var_inits : (DAE.Element list, int) => (CFunction, int) =
1665+
1666+
axiom generate_var_inits ([],tnr) => (c_empty_function, tnr)
1667+
1668+
rule generate_var_init (first, tnr) => (cfn1, tnr1) &
1669+
generate_var_inits(rest, tnr1) => (cfn2, tnr2) &
1670+
c_merge_fn(cfn1, cfn2) => cfn
1671+
-----------------------------
1672+
generate_var_inits (first::rest, tnr) => (cfn, tnr2)
1673+
1674+
rule Print.print_buf "# generate_var_inits failed\n"
1675+
---------------------------------
1676+
generate_var_inits (_,_) => fail
1677+
1678+
end
1679+
1680+
1681+
relation generate_var_init : (DAE.Element, int) => (CFunction, int) =
1682+
1683+
rule is_array id => is_a &
1684+
is_first_in_array id => true &
1685+
dae_type_str (typ, is_a) => typ_str &
1686+
comp_ref_cstr id => (id_str,_) &
1687+
Exp.print_exp_str e => expstr &
1688+
Util.string_append_list (["copy_", typ_str,
1689+
"_data(", id_str, ",", expstr, ");"
1690+
]) => init_str &
1691+
c_add_statements(c_empty_function,[init_str]) => cfn
1692+
-----------
1693+
generate_var_init (DAE.VAR(id,
1694+
DAE.VARIABLE,
1695+
DAE.OUTPUT,
1696+
typ,
1697+
SOME(e),
1698+
_),tnr)
1699+
=> (cfn, tnr)
1700+
1701+
axiom generate_var_init (_, tnr) => (c_empty_function, tnr)
15991702

1703+
end
16001704

16011705
relation generate_var : (DAE.Element,int) => (CFunction,int) =
16021706
(*
@@ -3034,13 +3138,23 @@ relation generate_read_call_write_external : (string,
30343138
list_append (invars, outvars) => vars' &
30353139
list_append (vars', bivars) => vars &
30363140

3037-
generate_ext_call (vars, extdecl, tnr_bivars) => (extcall, tnr_extcall) &
3141+
(*
3142+
generate_var_inits(outvars, tnr_bivars) => (cfnvarinits1, tnr_varinits1) &
3143+
generate_var_inits(bivars, tnr_varinits1) => (cfnvarinits2, tnr_varinits2) &
3144+
3145+
c_merge_fns([cfnvarinits1,cfnvarinits2]) => cfnvarinits &
3146+
3147+
generate_ext_call (vars, extdecl, tnr_varinits2) => (extcall, tnr_extcall) &
3148+
*)
30383149

3150+
generate_ext_call (vars, extdecl, tnr_bivars) => (extcall, tnr_extcall) &
30393151
c_add_statements(extcall,["PRE_OPEN_OUTFILE"]) => cfn4' &
30403152

30413153
generate_write(outvars) => cfn5 &
30423154
c_add_statements(cfn5,["PRE_WRITE_DONE"]) => cfn5' &
30433155

3156+
(* c_merge_fns([cfn1',cfn3',readdone,mem_fn,biallocstmts,cfnvarinits,cfn4',cfn5']) => cfn' & *)
3157+
30443158
c_merge_fns([cfn1',cfn3',readdone,mem_fn,biallocstmts,cfn4',cfn5']) => cfn' &
30453159

30463160
c_add_cleanups(cfn', [mem_stmt2, "return 0;"]) => cfn
@@ -3152,21 +3266,25 @@ relation generate_extcall_vardecl : DAE.ExtArg => CFunction =
31523266
(* INPUT NON-ARRAY *)
31533267
rule let DAE.EXTARG(cref, Types.ATTR(_,_,_,Absyn.INPUT), ty) = arg &
31543268
Types.is_array ty => false &
3269+
Types.is_string ty => false &
31553270
generate_type_external ty => tystr &
31563271
var_name_external cref => name &
31573272
comp_ref_cstr cref => (orgname, _) &
31583273
generate_vardecl_func (tystr, name, SOME(orgname)) => res
31593274
--------------------------------------------------------
31603275
generate_extcall_vardecl arg => res
31613276

3277+
(* INPUT NON-ARRAY STRING *)
3278+
(* do nothing *)
3279+
31623280
(* INPUT ARRAY *)
31633281
rule let DAE.EXTARG(cref, Types.ATTR(_,_,_,Absyn.INPUT), ty) = arg &
31643282
Types.is_array ty => true
31653283
--------------------------------------------------------
31663284
generate_extcall_vardecl arg => c_empty_function
31673285

31683286
(* OUTPUT NON-ARRAY *)
3169-
rule let DAE. EXTARG(cref, Types.ATTR(_,_,_,Absyn.OUTPUT), ty) = arg &
3287+
rule let DAE.EXTARG(cref, Types.ATTR(_,_,_,Absyn.OUTPUT), ty) = arg &
31703288
Types.is_array ty => false &
31713289
generate_type_external ty => tystr &
31723290
var_name_external cref => name &
@@ -3203,6 +3321,8 @@ relation generate_extcall_vardecl : DAE.ExtArg => CFunction =
32033321

32043322
end
32053323

3324+
3325+
32063326
relation generate_extcall_vardecls2_f77 : (DAE.ExtArg list, DAE.ExtArg, int)
32073327
=> (CFunction, DAE.ExtArg list, int) =
32083328

@@ -3230,12 +3350,13 @@ relation generate_c_to_f77_converter : Types.Type => string =
32303350
generate_type_internal_namepart elty => eltystr &
32313351
Util.string_append_list (["convert_alloc_",eltystr,"_array_to_f77"]) => str
32323352
---------------------------------------------------------------------
3233-
generate_c_to_f77_converter((Types.T_ARRAY(_,(Types.T_ARRAY(_,ty),_)),_)) => str
3353+
generate_c_to_f77_converter (ty as (Types.T_ARRAY(_,_),_)) => str
32343354

32353355
rule Print.print_buf "#-- generate_c_to_f77_converter failed\n" &
3236-
Print.print_buf "#-- Not an array?\n"
3356+
Print.print_buf "#-- Not an array?\n" &
3357+
Types.print_type ty
32373358
---------------------------------------------
3238-
generate_c_to_f77_converter _ => fail
3359+
generate_c_to_f77_converter ty => fail
32393360

32403361
end
32413362

@@ -3410,10 +3531,11 @@ end
34103531
*)
34113532
relation generate_ext_call_fcall_arg : DAE.ExtArg => string =
34123533

3413-
(* INPUT NON-ARRAY *)
3534+
(* INPUT NON-ARRAY NON-STRING *)
34143535
rule let DAE.EXTARG(cref, attr, ty) = arg &
34153536
Types.is_input_attr attr => true &
34163537
Types.is_array ty => false &
3538+
Types.is_string ty => false &
34173539
var_name_external cref => res
34183540
-----------------------------
34193541
generate_ext_call_fcall_arg arg => res
@@ -3435,9 +3557,9 @@ relation generate_ext_call_fcall_arg : DAE.ExtArg => string =
34353557
-----------------------------
34363558
generate_ext_call_fcall_arg arg => res
34373559

3438-
(* INPUT/OUTPUT ARRAY *)
3560+
(* INPUT/OUTPUT STRING *)
34393561
rule let DAE.EXTARG(cref, attr, ty) = arg &
3440-
Types.is_array ty => true &
3562+
Types.is_string ty => true &
34413563
comp_ref_cstr cref => (name,_) &
34423564
string_append(name, ".data") => res
34433565
-----------------------------
@@ -3469,9 +3591,11 @@ relation generate_ext_call_fcall_arg : DAE.ExtArg => string =
34693591
generate_ext_call_fcall_arg (arg as DAE.EXTARGSIZE(_,_,_,_)) => str
34703592

34713593

3472-
rule Print.print_buf "#-- generate_ext_call_fcall_arg failed\n"
3594+
rule Print.print_buf "#-- generate_ext_call_fcall_arg failed\n" &
3595+
DAE.dump_ext_arg_str arg => str &
3596+
Print.print_buf str & Print.print_buf "\n"
34733597
----------------------------------------------------------
3474-
generate_ext_call_fcall_arg _ => fail
3598+
generate_ext_call_fcall_arg arg => fail
34753599

34763600
end
34773601

@@ -3820,17 +3944,24 @@ end
38203944

38213945
relation var_name_array : (Exp.ComponentRef, Types.Attributes) => string =
38223946

3947+
(* INPUT *)
38233948
rule comp_ref_cstr cref => (str, _) &
38243949
Types.is_input_attr attr => true
38253950
---------------------------------------
38263951
var_name_array (cref,attr) => str
38273952

3953+
(* OUTPUT *)
38283954
rule comp_ref_cstr cref => (cref_str, _) &
38293955
Types.is_output_attr attr => true &
38303956
string_append ("out.", cref_str) => str
38313957
---------------------------------------
38323958
var_name_array (cref,attr) => str
38333959

3960+
(* INPUT/OUTPUT *)
3961+
rule comp_ref_cstr cref => (str, _)
3962+
---------------------------------------
3963+
var_name_array (cref,attr) => str
3964+
38343965
end
38353966

38363967
relation var_arg_names_external : DAE.Element list => string list =

modeq/exp.rml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module Exp:
6363
| LUNARY of Operator * Exp
6464
| RELATION of Exp * Operator * Exp
6565
| IFEXP of Exp * Exp * Exp
66-
| CALL of Absyn.Path * Exp list * bool * bool (* Function call bool1 = tuple bool2 = constant *)
66+
| CALL of Absyn.Path * Exp list * bool (* tuple *) * bool (* builtin *) (* Function call *)
6767
| ARRAY of Type * bool * Exp list
6868
| MATRIX of Type * int * (Exp*bool) list list
6969
| RANGE of Type * Exp * Exp option * Exp
@@ -540,7 +540,7 @@ relation print_component_ref2 =
540540

541541
rule RTOpts.modelica_output => false &
542542
Print.print_buf s &
543-
Print.print_buf "[" & print_list(l,print_subscript,",") & Print.print_buf "]"
543+
Print.print_buf "<cref>[" & print_list(l,print_subscript,",") & Print.print_buf "]"
544544
-------------------------------------------------------
545545
print_component_ref2 (s,l)
546546

@@ -671,7 +671,7 @@ relation print_exp2 : (Exp,int) => () =
671671
---------
672672
print_exp2 (TUPLE(es),_)
673673

674-
rule Print.print_buf "[" &
674+
rule Print.print_buf "<matrix>[" &
675675
print_list(es, print_row, ";") &
676676
Print.print_buf "]"
677677
---------
@@ -714,7 +714,7 @@ relation print_exp2 : (Exp,int) => () =
714714
print_leftpar(pri1,pri2) => pri3 &
715715
print_exp2 (e,pri3) &
716716
print_rightpar(pri1,pri2) &
717-
Print.print_buf "[" &
717+
Print.print_buf "<asub>[" &
718718
int_string i => s & Print.print_buf s & Print.print_buf "]"
719719
---------------------------------------
720720
print_exp2 (ASUB(e,i),pri1)

0 commit comments

Comments
 (0)