Skip to content

Commit

Permalink
- switch function generation also to new simulation runtime
Browse files Browse the repository at this point in the history
 - linking Compiler/runtime to new sim runtime.



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10898 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Jan 16, 2012
1 parent 9ff6a55 commit 8bb948d
Show file tree
Hide file tree
Showing 26 changed files with 1,117 additions and 38 deletions.
5 changes: 2 additions & 3 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -1184,7 +1184,6 @@ algorithm
end match;
end callTargetTemplatesFMU;


public function translateModel
"Entry point to translate a Modelica model for simulation.
Expand Down Expand Up @@ -1292,7 +1291,7 @@ algorithm
makefileParams = createMakefileParams(includeDirs, libs);
fnCode = FUNCTIONCODE(name, SOME(mainFunction), fns, literals, includes, makefileParams, extraRecordDecls);
// Generate code
_ = Tpl.tplString(SimCodeC.translateFunctions, fnCode);
_ = Tpl.tplString(CodegenC.translateFunctions, fnCode);
then
();
case (name, NONE(), daeElements, metarecordTypes, includes)
Expand All @@ -1303,7 +1302,7 @@ algorithm
makefileParams = createMakefileParams(includeDirs, libs);
fnCode = FUNCTIONCODE(name, NONE(), fns, literals, includes, makefileParams, extraRecordDecls);
// Generate code
_ = Tpl.tplString(SimCodeC.translateFunctions, fnCode);
_ = Tpl.tplString(CodegenC.translateFunctions, fnCode);
then
();
end match;
Expand Down
1 change: 1 addition & 0 deletions Compiler/runtime/Dynload.cpp
Expand Up @@ -33,6 +33,7 @@ extern "C" {

#include <stdio.h>
#include <stdlib.h>
#include "openmodelica.h"
#include "modelica.h"
#include "systemimpl.h"
#include "errorext.h"
Expand Down
2 changes: 2 additions & 0 deletions Compiler/runtime/Dynload_omc.cpp
Expand Up @@ -35,7 +35,9 @@ extern "C" {
#include <Windows.h>
#endif

#include "openmodelica.h"
#include "modelica.h"
#include "meta_modelica.h"
#include "rml_compatibility.h"
#include "OpenModelicaBootstrappingHeader.h"
#include "Dynload.cpp"
Expand Down
1 change: 1 addition & 0 deletions Compiler/runtime/Dynload_rml.cpp
Expand Up @@ -35,6 +35,7 @@

extern "C" {

#include "openmodelica.h"
#include "modelica.h"
#include "rml.h"
#include "Absyn.h"
Expand Down
4 changes: 3 additions & 1 deletion Compiler/runtime/Error_omc.cpp
Expand Up @@ -30,7 +30,9 @@

extern "C" {

#include "modelica.h"

#include "openmodelica.h"
#include "meta_modelica.h"
#include "rml_compatibility.h"
#define ADD_METARECORD_DEFINTIONS static
#include "OpenModelicaBootstrappingHeader.h"
Expand Down
3 changes: 2 additions & 1 deletion Compiler/runtime/IOStreamExt_omc.cpp
Expand Up @@ -42,7 +42,8 @@
*/

#include "IOStreamExt.c"
#include "modelica.h"
#include "openmodelica.h"
#include "meta_modelica.h"

extern "C" {

Expand Down
3 changes: 2 additions & 1 deletion Compiler/runtime/Lapack_omc.cpp
Expand Up @@ -30,7 +30,8 @@

extern "C" {

#include "modelica.h"
#include "openmodelica.h"
#include "meta_modelica.h"
#include "rml_compatibility.h"
#include "lapackimpl.c"

Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/Makefile.common
Expand Up @@ -16,7 +16,7 @@ ifndef OMDEV
else
configUnix =
endif
RML_COMPAT=$(top_builddir)/c_runtime/meta/rml_compatibility.h
RML_COMPAT=$(top_builddir)/SimulationRuntime/c/meta/rml_compatibility.h

SRC = Print_rml.c System_rml.c Settings_rml.c \
SimulationResults_rml.c IOStreamExt_rml.c Database_rml.c Socket_rml.c Lapack_rml.c
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/Makefile.in
Expand Up @@ -24,7 +24,7 @@ CC = @CC@
CXX = @CXX@
IDL = @IDLCMD@
CXXFLAGS = $(CFLAGS)
CPPFLAGS = -I$(RMLINCLUDE) -I$(top_builddir)/c_runtime -I$(top_builddir)/c_runtime/meta -I$(top_builddir)/c_runtime/meta/gc -I$(srcdir) -I. $(CORBAINCL)
CPPFLAGS = -I$(RMLINCLUDE) -I$(top_builddir)/SimulationRuntime/c -I$(top_builddir)/SimulationRuntime/c/simulation/results -I$(top_builddir)/SimulationRuntime/c/util -I$(top_builddir)/SimulationRuntime/c/meta -I$(top_builddir)/SimulationRuntime/c/meta/gc -I$(srcdir) -I. $(CORBAINCL)

include Makefile.common

Expand Down
3 changes: 2 additions & 1 deletion Compiler/runtime/System_omc.cpp
Expand Up @@ -35,7 +35,8 @@ extern "C" {
#endif

#include <ctype.h> /* for toupper */
#include "modelica.h"
#include "openmodelica.h"
#include "meta_modelica.h"
#include "rml_compatibility.h"
#define ADD_METARECORD_DEFINTIONS static
#include "OpenModelicaBootstrappingHeader.h"
Expand Down
1 change: 1 addition & 0 deletions Compiler/runtime/lapackimpl.c
Expand Up @@ -48,6 +48,7 @@ extern "C" {
#include "rtclock.h"
#include "config.h"
#include "errorext.h"
#include "f2c.h"

/*
* Platform specific includes and defines
Expand Down
1 change: 1 addition & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -56,6 +56,7 @@ extern "C" {
#include "rtclock.h"
#include "config.h"
#include "errorext.h"
#include "f2c.h"

#if defined(_MSC_VER) /* no iconv for VS! */

Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/systemimpl.h
Expand Up @@ -30,7 +30,7 @@
#ifndef __SYSTEMIMPL_H
#define __SYSTEMIMPL_H

#include "modelica.h"
#include "openmodelica.h"

char* _replace(const char* source_str,
const char* search_str,
Expand Down
7 changes: 5 additions & 2 deletions Compiler/susan_codegen/SimCode/CodegenC.tpl
Expand Up @@ -2053,8 +2053,8 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
DLLEXT=<%makefileParams.dllext%>
CFLAGS_BASED_ON_INIT_FILE=<%extraCflags%>
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) <%makefileParams.cflags%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags /* From the simulate() command */%>
CPPFLAGS=-I"<%makefileParams.omhome%>/include/omc2" -I. <%dirExtra%> <%makefileParams.includes ; separator=" "%>
LDFLAGS=-L"<%makefileParams.omhome%>/lib/omc2" -lModelicaExternalC -lSimulationRuntimeC <%makefileParams.ldflags%>
CPPFLAGS=-I"<%makefileParams.omhome%>/include/omc" -I. <%dirExtra%> <%makefileParams.includes ; separator=" "%>
LDFLAGS=-L"<%makefileParams.omhome%>/lib/omc" -lModelicaExternalC -lSimulationRuntimeC <%makefileParams.ldflags%>
SENDDATALIBS=<%makefileParams.senddatalibs%>
PERL=perl
MAINFILE=<%fileNamePrefix%><% if acceptMetaModelicaGrammar() then ".conv"%>.c
Expand Down Expand Up @@ -2191,6 +2191,7 @@ template commonHeader()
<% if acceptMetaModelicaGrammar() then "#define __OPENMODELICA__METAMODELICA"%>
<% if acceptMetaModelicaGrammar() then "#include \"meta_modelica.h\"" %>
<% if Flags.isSet(Flags.OPENMP) then "#include <omp.h>" else "#define omp_get_thread_num() 0" %>
#include "modelica.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Expand All @@ -2205,9 +2206,11 @@ template functionsFile(String filePrefix,
::=
<<
#include "<%filePrefix%>.h"
#include "modelica.h"
#define MODELICA_ASSERT(info,msg) { printInfo(stderr,info); fprintf(stderr,"Modelica Assert: %s!\n", msg); }
#define MODELICA_TERMINATE(msg) { fprintf(stderr,"Modelica Terminate: %s!\n", msg); fflush(stderr); }


<%literals |> literal hasindex i0 fromindex 0 => literalExpConst(literal,i0) ; separator="\n"%>

<%match mainFunction case SOME(fn) then functionBody(fn,true)%>
Expand Down
8 changes: 1 addition & 7 deletions Makefile.common
Expand Up @@ -33,22 +33,16 @@ mkbuilddirs:
mkdir -p $(builddir_share)/omnotebook
mkdir -p $(builddir_doc)/omc/testmodels
mkdir -p $(builddir_man)/man1/
mkdir -p $(builddir_lib)/omc2
mkdir -p $(top_builddir)/build/include/omc2

debug: .testvariables mkbuilddirs settings omcd
profiler: .testvariables mkbuilddirs settings omc_profiler
release: omc

oldc_runtime: .testvariables mkbuilddirs
$(MAKE) -C c_runtime -f $(defaultMakefileTarget)
newc_runtime: .testvariables mkbuilddirs
c_runtime: .testvariables mkbuilddirs
$(MAKE) -C SimulationRuntime/interactive -f $(defaultMakefileTarget)
# Depends on libinteractive.a
$(MAKE) -C SimulationRuntime/c -f $(defaultMakefileTarget)

c_runtime: oldc_runtime newc_runtime

docs: mkbuilddirs omlibrary
(cp -p doc/*.pdf doc/*.txt doc/OpenModelicaAPI-Howto/*.pdf $(builddir_doc)/omc)
rm -f build/doc/omc/CMakeLists.txt
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/Makefile.common
Expand Up @@ -56,12 +56,12 @@ install: ModelicaExternalC/libModelicaExternalC.a libSimulationRuntimeC.a simula
# move libraries
cp ./libSimulationRuntimeC.a \
./ModelicaExternalC/libModelicaExternalC.a \
./ModelicaExternalC/ModelicaUtilities.h \
../interactive/libinteractive.a $(builddir_lib)
test -z "$(LIBF2C)" || cp simulation/libf2c/libf2c.* $(builddir_lib)/
# move header files
cp ./inline.h \
./openmodelica.h \
./ModelicaExternalC/ModelicaUtilities.h \
./openmodelica_func.h \
./simulation_data.h \
./f2c.h \
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/Makefile.in
Expand Up @@ -6,8 +6,8 @@

top_builddir = ../..
builddir_bin=$(top_builddir)/build/bin
builddir_lib=$(top_builddir)/build/lib/omc2
builddir_inc=$(top_builddir)/build/include/omc2
builddir_lib=$(top_builddir)/build/lib/omc
builddir_inc=$(top_builddir)/build/include/omc

CC := @CC@
CXX := @CXX@
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/meta/meta_modelica.c
Expand Up @@ -63,7 +63,7 @@ void* mmc_mk_rcon(double d)
return MMC_TAGPTR(p);
}

void *mmc_mk_box_arr(int slots, unsigned ctor, const void** args)
void *mmc_mk_box_arr(int slots, unsigned ctor, void** args)
{
int i;
struct mmc_struct *p = (struct mmc_struct*)mmc_alloc_words(slots + 1);
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/meta/meta_modelica.h
Expand Up @@ -419,7 +419,7 @@ static inline void *mmc_mk_some(const void *x)
return mmc_mk_box1(1, x);
}

void *mmc_mk_box_arr(int slots, unsigned ctor, const void** args);
void *mmc_mk_box_arr(int slots, unsigned ctor, void** args);
void *mmc_mk_box_no_assign(int slots, unsigned ctor);

modelica_boolean valueEq(modelica_metatype,modelica_metatype);
Expand Down
54 changes: 54 additions & 0 deletions SimulationRuntime/c/openmodelica.h
Expand Up @@ -43,6 +43,7 @@ extern "C" {
#endif

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <float.h>
#include <assert.h>
Expand Down Expand Up @@ -192,6 +193,59 @@ typedef long int fortran_integer;
typedef unsigned long int fortran_uinteger;
#endif


/* BEFORE: read_write */
typedef struct type_desc_s type_description;

enum type_desc_e {
TYPE_DESC_NONE,
TYPE_DESC_REAL,
TYPE_DESC_REAL_ARRAY,
TYPE_DESC_INT,
TYPE_DESC_INT_ARRAY,
TYPE_DESC_BOOL,
TYPE_DESC_BOOL_ARRAY,
TYPE_DESC_STRING,
TYPE_DESC_STRING_ARRAY,
TYPE_DESC_TUPLE,
TYPE_DESC_COMPLEX,
TYPE_DESC_RECORD,
/* function pointer - added by stefan */
TYPE_DESC_FUNCTION,
TYPE_DESC_MMC,
TYPE_DESC_NORETCALL
};

struct type_desc_s {
enum type_desc_e type;
int retval : 1;
union {
modelica_real real;
real_array_t real_array;
modelica_integer integer;
integer_array_t int_array;
modelica_boolean boolean;
boolean_array_t bool_array;
modelica_string_const string;
string_array_t string_array;
struct {
size_t elements;
struct type_desc_s *element;
} tuple;
modelica_complex complex;
struct {
const char *record_name;
size_t elements;
char **name;
struct type_desc_s *element;
} record;
/* function pointer - stefan */
modelica_fnptr function;
void* mmc;
} data;
};


/* math functions (-lm)*/

/* Special Modelica builtin functions*/
Expand Down
23 changes: 13 additions & 10 deletions SimulationRuntime/c/util/modelica.h
Expand Up @@ -69,7 +69,17 @@ extern "C" {
#include <limits.h>
#include <float.h>

#include "compat.h"
#if defined(__MINGW32__) || defined(_MSC_VER)
#define EXIT(code) exit(code)
#else
/* We need to patch exit() on Unix systems
* It does not change the exit code of simulations for some reason! */
#include <unistd.h>
#define EXIT(code) {fflush(NULL); _exit(code);}
#endif

#include "inline.h"

#include "modelica_string.h"
#include "memory_pool.h"
#include "index_spec.h"
Expand All @@ -83,19 +93,12 @@ extern "C" {
#include "utility.h"
#include "division.h"


typedef real_array_t real_array;
typedef integer_array_t integer_array;
typedef boolean_array_t boolean_array;
typedef string_array_t string_array;

#include <assert.h>
/*#include "read_write.h"*/
#include "read_write.h"
#include "simulation_data.h"
#include "meta_modelica.h"
#include "meta_modelica_builtin.h"
#include "meta_modelica_real.h"
/*#include "matrix.h"
#include "simulation_varinfo.h"*/


/* math functions (-lm)*/
Expand Down

0 comments on commit 8bb948d

Please sign in to comment.