Skip to content

Commit

Permalink
- Started updating the generation of files for parsing (to support bo…
Browse files Browse the repository at this point in the history
…otstrapping)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7144 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 21, 2010
1 parent 5ec29c5 commit 1df0955
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Compiler/Makefile.common
Expand Up @@ -13,7 +13,7 @@ else
CORBAOBJ = $(srcdir)/runtime/corbaimpl_stub.o
endif

AST = $(top_builddir)/Parser/libomparse.a $(top_builddir)/Parser/libantlr3.a
AST = $(top_builddir)/Parser/libomparse_rml.a $(top_builddir)/Parser/libantlr3.a

RTOBJ = \
$(srcdir)/runtime/runtime.a \
Expand Down
8 changes: 4 additions & 4 deletions Compiler/Parser.mo
Expand Up @@ -50,30 +50,30 @@ public function parse
input String inString;
output Absyn.Program outProgram;

external "C" ;
external "C" outProgram=Parser_parse(inString) annotation(Library = {"omcruntime","omparse","antlr3"});
end parse;

public function parseexp
input String inString;
output Interactive.InteractiveStmts outInteractiveStmts;

external "C" ;
external "C" outInteractiveStmts=Parser_parseexp(inString) annotation(Library = {"omcruntime","omparse","antlr3"});
end parseexp;

public function parsestring
input String inString;
output Absyn.Program outProgram;
output String outString;

external "C" ;
external "C" outProgram=Parser_parsestring(inString,outString) annotation(Library = {"omcruntime","omparse","antlr3"});
end parsestring;

public function parsestringexp
input String inString;
output Interactive.InteractiveStmts outInteractiveStmts;
output String outString;

external "C" ;
external "C" outInteractiveStmts=Parser_parsestringexp(inString,outString) annotation(Library = {"omcruntime","omparse","antlr3"});
end parsestringexp;
end Parser;

2 changes: 1 addition & 1 deletion Compiler/System.mo
Expand Up @@ -440,7 +440,7 @@ public function getCurrentDateTime
output Integer mday;
output Integer mon;
output Integer year;
external "C" annotation(Library = "omcruntime");
external "C" System_getCurrentDateTime(sec,min,hour,mday,mon,year) annotation(Library = "omcruntime");
end getCurrentDateTime;

public function getCurrentTimeStr "
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/Makefile.common
Expand Up @@ -29,7 +29,7 @@ OBJ = $(SRC:.c=.o) $(CPPSRC:.cpp=.o) $(CPPSRC:.cc=.o)
OMC_OBJ = Error_omc.o Print_omc.o RTOpts_omc.o System_omc.o Settings_omc.o \
IOStreamExt_omc.o ErrorMessage.o systemimplmisc.o rtclock.o \
UnitParserExt_omc.o unitparser.o BackendDAEEXT_omc.o Socket_omc.o \
corbaimpl_stub_omc.o Dynload_omc.o OptManager_rml.o
corbaimpl_stub_omc.o Dynload_omc.o OptManager_omc.o

all: runtime.a install
.PHONY: all install
Expand Down
8 changes: 4 additions & 4 deletions Compiler/runtime/OptManager_omc.cpp
Expand Up @@ -33,14 +33,14 @@
extern "C"
{

void OptManager_setOption(const char *strEntry, int strValue)
extern void OptManager_setOption(const char *strEntry, int strValue)
{
if (OptManagerImpl_setOption(strEntry,strValue)) throw 1;
if (OptManagerImpl__setOption(strEntry,strValue)) throw 1;
}

int OptManager_getOption(const char *strEntry)
extern int OptManager_getOption(const char *strEntry)
{
int res = OptManagerImpl_getOption(strEntry);
int res = OptManagerImpl__getOption(strEntry);
if (res == -1)
throw 1;
return res;
Expand Down
28 changes: 20 additions & 8 deletions Parser/Makefile.common
@@ -1,13 +1,18 @@
COMPILERHOME=../Compiler/
BUILDINC = -I../build/include/omc
RMLINC = -I$(RMLHOME)/include/plain

ANTLRCMD=java -cp ./antlr-3.2/lib/antlr-3.2.jar org.antlr.Tool -report
CFLAGS=-O3
CPPFLAGS=-I$(COMPILERHOME) $(RMLINC) -I. -Iantlr-3.2/runtime/C -Iantlr-3.2/runtime/C/include
CPPFLAGS=-I$(COMPILERHOME) $(RMLINC) -I. -Iantlr-3.2/runtime/C -Iantlr-3.2/runtime/C/include $(BUILDINC)
CC=g++

.PHONY: all
all: libantlr3.a libomparse.a
all: install libomparse_rml.a

#libomparse.a
install: libantlr3.a
cp libantlr3.a libomparse.a ../build/lib/omc/

libantlr3.a: antlr-3.2/runtime/C/src/* antlr-3.2/runtime/C/include/*
# build the library
Expand All @@ -27,19 +32,26 @@ HFILES = \

OBJS = \
MetaModelica_Lexer_BaseModelica_Lexer.o MetaModelica_Lexer.o \
Modelica_3_Lexer_BaseModelica_Lexer.o Modelica_3_Lexer.o \
ModelicaParser.o
Modelica_3_Lexer_BaseModelica_Lexer.o Modelica_3_Lexer.o

MetaModelica_Lexer.o: MetaModelica_Lexer.h MetaModelica_Lexer_BaseModelica_Lexer.h
Modelica_3_Lexer.o: Modelica_3_Lexer.h Modelica_3_Lexer_BaseModelica_Lexer.h
MetaModelica_Lexer_BaseModelica_Lexer.o: MetaModelica_Lexer_BaseModelica_Lexer.h
Modelica_3_Lexer_BaseModelica_Lexer.o: Modelica_3_Lexer_BaseModelica_Lexer.h

parse.o: $(HFILES)
ModelicaParser_rml.o: ModelicaParser.c ModelicaParser.h ModelicaParserCommon.h
ModelicaParser_omc.o: ModelicaParser.c ModelicaParser.h ModelicaParserCommon.h

Parser_rml.o: $(HFILES)
Parser_omc.o: $(HFILES)

libomparse_rml.a: Parser_rml.o $(OBJS) ModelicaParser_rml.o
rm -f $@
ar -ru $@ Parser_rml.o $(OBJS) ModelicaParser_rml.o
ranlib $@

libomparse.a: parse.o $(OBJS)
libomparse.a: Parser_omc.o $(OBJS) ModelicaParser_omc.o
rm -f $@
ar -ru $@ parse.o $(OBJS)
ar -ru $@ Parser_omc.o $(OBJS) ModelicaParser_omc.o
ranlib $@

parsergen = ModelicaParser.c ModelicaParser.h
Expand Down
9 changes: 0 additions & 9 deletions Parser/Modelica.g
Expand Up @@ -43,15 +43,6 @@ import MetaModelica_Lexer; /* Makes all tokens defined, imported in OptiMo_Lexer
#include <stdio.h>
#include <errno.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "rml.h"
#include "Absyn.h"
#include "Interactive.h"
#ifdef __cplusplus
}
#endif
#include "ModelicaParserCommon.h"
#include "runtime/errorext.h"
Expand Down
35 changes: 35 additions & 0 deletions Parser/ModelicaParser_omc.c
@@ -0,0 +1,35 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF 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öpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* 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 "meta_modelica.h"
#include "rml_compatibility.h"
#include "OpenModelicaBootstrappingHeader.h"

#include "ModelicaParser.c"
41 changes: 41 additions & 0 deletions Parser/ModelicaParser_rml.c
@@ -0,0 +1,41 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF 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öpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* 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.
*
*/

#ifdef __cplusplus
extern "C" {
#endif
#include "rml.h"
#include "Absyn.h"
#include "Interactive.h"
#ifdef __cplusplus
}
#endif

#include "ModelicaParser.c"
85 changes: 85 additions & 0 deletions Parser/Parser_omc.cpp
@@ -0,0 +1,85 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF 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öpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* 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 "meta_modelica.h"
#include "rml_compatibility.h"
#include "parse.c"

extern "C" {

void* Parser_parse(const char* filename)
{
fprintf(stderr, "Parser.mo NYI\n");throw 1;
void *res = parseFile(filename,PARSE_MODELICA);
if (res == NULL)
throw 1;
return res;
}

void* Parser_parseexp(const char* filename)
{
fprintf(stderr, "Parser.mo NYI\n");throw 1;
void *res = parseFile(filename,PARSE_EXPRESSION);
if (res == NULL)
throw 1;
return res;
}

void* Parser_parsestring(const char* data, char** msg)
{
fprintf(stderr, "Parser.mo NYI\n");throw 1;
ErrorImpl__setCheckpoint("parsestring");
void *res = parseString(data,PARSE_MODELICA);
if (res != NULL) {
*msg = "Ok";
ErrorImpl__rollBack("parsestring");
return res;
} else {
*msg = ErrorImpl__rollBackAndPrint("parsestring");
return NULL; // FIXME?!
}
}

void* Parser_parsestringexp(const char* data, char** msg)
{
fprintf(stderr, "Parser.mo NYI\n");throw 1;
ErrorImpl__setCheckpoint("parsestringexp");
void *res = parseString(data,PARSE_EXPRESSION);
if (res != NULL) {
*msg = "Ok";
ErrorImpl__rollBack("parsestring");
return res;
} else {
*msg = ErrorImpl__rollBackAndPrint("parsestring");
return NULL; // FIXME?!
}
}

}

0 comments on commit 1df0955

Please sign in to comment.