2 * Translator from Modelica 2.x to flat Modelica
\r
4 * Copyright (C) 2005 - 2007 Imagine S.A.
\r
5 * For more information or commercial use please contact us at www.amesim.com
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program; if not, write to the Free Software
\r
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
25 (** {4 compiler options } *)
\r
27 (** List of library files added using the "-lib" compiler option *)
\r
28 let lib_files = ref []
\r
30 let add_library_file s = lib_files := !lib_files @ [s]
\r
32 (** Generation of and XML description of the instantiated model *)
\r
35 (** option for the generation of initialization code *)
\r
36 let init = ref false
\r
38 (** option "-command" value *)
\r
39 let command = ref None
\r
41 let define_command s =
\r
42 if !command <> None then failwith "More than one command issued."
\r
43 else command := Some s
\r
45 (** target file name, option "-o" *)
\r
46 let filename = ref None
\r
48 let define_filename s =
\r
49 if !filename <> None then failwith "More than one target filename specified."
\r
50 else filename := Some s
\r
52 (** {4 functions } *)
\r
54 (** Error displayed when the compiler is called with an invalid argument *)
\r
55 let set_input s = failwith ("Invalid command line argument: " ^ s)
\r
57 (** Parsing of compiler command line arguments *)
\r
60 [("-lib", Arg.String add_library_file,
\r
61 "<filename> Define <filename> to be a file containing a Modelica \
\r
62 library of classes.");
\r
63 ("-o", Arg.String define_filename,
\r
64 "<filename> Specify target filename (default is `<instance name>.mo`).");
\r
65 ("-command", Arg.String define_command,
\r
66 "\"command\" Define the component to be created as a regular Modelica \
\r
67 component declaration.");
\r
68 ("-xml", Arg.Set xml,
\r
69 "Generate an XML version of the model instead of flat Modelica code");
\r
70 ("-with-init", Arg.Set init,
\r
71 "Generate an XML version of the initialization problem in a file \
\r
72 named <filename>_init.xml.")]
\r
75 "usage: %s [-lib <filename>] [-o <filename>] [-fundir <dirname>] \
\r
76 -command \"command\""
\r
79 (** Compilation of libraries *)
\r
80 let compile_libraries lib_paths =
\r
82 let lib_syns = LibraryManager.parse_stored_libraries lib_paths in
\r
83 let comp_defs' = NameResolve.resolve_toplevel [] lib_syns in
\r
85 Instantiation.evaluate_toplevel_definitions [] comp_defs' in
\r
86 comp_defs', inst_defs'
\r
89 ExceptHandler.handle exn;
\r
92 (** Creation of components defined using the "-command" option argument *)
\r
93 let create_component comp_defs inst_defs filename cmd =
\r
95 let inst_syn = LibraryManager.parse_command cmd in
\r
96 let comp_defs' = NameResolve.resolve_toplevel comp_defs [ inst_syn ] in
\r
98 Instantiation.evaluate_toplevel_definitions inst_defs comp_defs' in
\r
99 CodeGeneration.generate_code !xml !init filename inst_defs'
\r
102 ExceptHandler.handle exn;
\r
105 (** Main function *)
\r
107 Printf.printf "---------------------------------------------------\n";
\r
108 Printf.printf "Translator v1.2 for Scicos from Modelica 2.x to flat Modelica\n";
\r
109 Printf.printf "Copyright (C) \n2005-2007 Imagine,\n2007-2008 LMS-Imagine\n";
\r
110 Versiondate.print_versiondate();
\r
111 Printf.printf "---------------------------------------------------\n";
\r
115 let comp_defs, inst_defs =
\r
116 compile_libraries !lib_files in
\r
117 let cmd = match !command with
\r
118 | None -> failwith "Command missing"
\r
119 | Some cmd -> cmd in
\r
120 create_component comp_defs inst_defs !filename cmd
\r