Skip to content

Commit

Permalink
- Added test mosfiles/FinalTests, from MathCore
Browse files Browse the repository at this point in the history
- Added the ModelicaUtilities.h header (Utility functions for external C function)
  - Changed the generation of makesfiles to make it possible to reference these functions.
  - Added a simple implementation of these functions.
  - Added test mosfiles/ModelicaUtilities
- Fixed a bug in SimCodegen where solved string would not be escaped before printed as C-code.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5136 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 12, 2010
1 parent 67fe549 commit 7571353
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Compiler/CevalScript.mo
Expand Up @@ -4173,8 +4173,9 @@ algorithm
pathstr,": ",cfilename,"\n","\t $(LINK)",
" $(CFLAGS)",
" -o ",pathstr,"$(DLLEXT) ",cfilename,
" ",libsstr,
" $(LDFLAGS)",
" ",libsstr," -lm \n"});
" -lm \n"});
System.writeFile(makefilename, str);
compileModel(pathstr, {}, "", "");
then
Expand Down
3 changes: 2 additions & 1 deletion Compiler/SimCodegen.mo
Expand Up @@ -8490,7 +8490,7 @@ algorithm
/* Solves a discrete variable, typically in when-clause */
case(discVars,vars,knvars,eqns,blck,ass2,mT)
equation
(eqn_lst,var_lst) = Util.listMap32(blck, getEquationAndSolvedVar, eqns, vars, ass2);
(eqn_lst,var_lst) = Util.listMap32(blck, getEquationAndSolvedVar, eqns, vars, ass2);
_::_ = Util.listSelect(var_lst,DAELow.isVarDiscrete);
discVars = DAELow.addVars(var_lst,discVars);
then discVars;
Expand Down Expand Up @@ -9242,6 +9242,7 @@ algorithm

case (DAE.SCONST(string = s),_)
equation
s = Util.escapeModelicaStringToCString(s);
s_1 = stringAppend("\"", s);
s_2 = stringAppend(s_1, "\"");
then
Expand Down
4 changes: 2 additions & 2 deletions c_runtime/Makefile.common
Expand Up @@ -12,7 +12,7 @@ modelica_string.o bigden.o \
ddasrt.o dlinpk.o enorm.o hybrd1.o nelmead.o qform.o r1updt.o \
biglag.o ddassl.o dogleg.o fdjac1.o hybrj.o newuoa.o qrfac.o trsapp.o \
daux.o dlamch.o dpmpar.o hybrd.o lsame.o newuob.o r1mpyq.o update.o \
java_interface.o meta_modelica.o meta_modelica_builtin.o $(EXTRA_OBJS)
java_interface.o meta_modelica.o meta_modelica_builtin.o ModelicaUtilities.o $(EXTRA_OBJS)

SIMOBJS = $(FOBJS) simulation_runtime.o simulation_init.o simulation_input.o simulation_events.o \
solver_dasrt.o solver_euler.o simulation_result.o simulation_delay.o tables.o options.o dgesv_aux.o $(EXTRA_SIMOBJS)
Expand All @@ -24,7 +24,7 @@ HFILES = blaswrap.h f2c.h integer_array.h memory_pool.h modelica_string.h \
simulation_init.h simulation_input.h solver_dasrt.h solver_euler.h simulation_result.h \
meta_modelica.h meta_modelica_builtin.h sendData/sendData.h sendData/humbug.h \
java_interface.h jni.h jni_md.h jni_md_solaris.h jni_md_windows.h \
simulation_delay.h fortran_types.h
simulation_delay.h fortran_types.h ModelicaUtilities.h

LIBS = libc_runtime.a libsim.a

Expand Down
71 changes: 71 additions & 0 deletions c_runtime/ModelicaUtilities.c
@@ -0,0 +1,71 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Linköping University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköping University, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

#include "ModelicaUtilities.h"
#include "modelica_string.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void ModelicaMessage(const char* string) {
ModelicaFormatMessage("%s", string);
}

void ModelicaFormatMessage(const char* string,...) {
va_list args;
va_start(args, string);
vfprintf(stdout, string, args);
va_end(args);
fflush(stdout);
}

void ModelicaError(const char* string) {
ModelicaFormatError("%s", string);
}

void ModelicaFormatError(const char* string, ...) {
va_list args;
va_start(args, string);
vfprintf(stderr, string, args);
va_end(args);
}

char* ModelicaAllocateString(size_t len) {
char* res;
alloc_modelica_string(&res,len);
return res;
}

char* ModelicaAllocateStringWithErrorReturn(size_t len) {
char* res;
alloc_modelica_string(&res,len);
return res;
}
17 changes: 17 additions & 0 deletions c_runtime/ModelicaUtilities.h
@@ -0,0 +1,17 @@
#ifndef MODELICA_UTILITIES_H
#define MODELICA_UTILITIES_H

#include <stddef.h>
/*
* Utility functions for external functions.
* The functionality is defined in the Modelica 2.x and 3.x specifications.
*/

void ModelicaMessage(const char* string);
void ModelicaFormatMessage(const char* string,...);
void ModelicaError(const char* string);
void ModelicaFormatError(const char* string, ...);
char* ModelicaAllocateString(size_t len);
char* ModelicaAllocateStringWithErrorReturn(size_t len);

#endif /* MODELICA_UTILITIES_H */

0 comments on commit 7571353

Please sign in to comment.