Skip to content

Commit

Permalink
Some OMCC updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jun 22, 2015
1 parent 6e21b0b commit 57342fe
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 135 deletions.
29 changes: 15 additions & 14 deletions openmodelica/omcc/GenerateParser.mos
Expand Up @@ -2,20 +2,21 @@ setCommandLineOptions({"+g=MetaModelica","+d=rml"});
loadFile("Types.mo");
loadFile("Absyn.mo");

//loadFile("../../../Compiler/FrontEnd/Absyn.mo");
loadFile("../../../Compiler/Util/Error.mo");
loadFile("../../../Compiler/Util/ErrorExt.mo");
loadFile("../../../Compiler/FrontEnd/Dump.mo");
loadFile("../../../Compiler/Util/Print.mo");
loadFile("../../../Compiler/Util/Flags.mo");
loadFile("../../../Compiler/Global/Global.mo");
loadFile("../../../Compiler/Util/Config.mo");
loadFile("../../../Compiler/Util/Debug.mo");
loadFile("../../../Compiler/Util/List.mo");
loadFile("../../../Compiler/Util/Settings.mo");
loadFile("../../../Compiler/Util/Corba.mo");
loadFile("../../../Compiler/Util/Util.mo");
loadFile("../../../Compiler/Util/System.mo");
compilerSources := "../../../OMCompiler/Compiler/";

loadFile(compilerSources + "Util/Error.mo");
loadFile(compilerSources + "Util/ErrorExt.mo");
loadFile(compilerSources + "FrontEnd/Dump.mo");
loadFile(compilerSources + "Util/Print.mo");
loadFile(compilerSources + "Util/Flags.mo");
loadFile(compilerSources + "Global/Global.mo");
loadFile(compilerSources + "Util/Config.mo");
loadFile(compilerSources + "Util/Debug.mo");
loadFile(compilerSources + "Util/List.mo");
loadFile(compilerSources + "Util/Settings.mo");
loadFile(compilerSources + "Util/Corba.mo");
loadFile(compilerSources + "Util/Util.mo");
loadFile(compilerSources + "Util/System.mo");
loadFile("TokenModelica.mo");
loadFile("LexTableModelica.mo");
loadFile("LexerCodeModelica.mo");
Expand Down
29 changes: 15 additions & 14 deletions openmodelica/omcc/LoadCompilerSources.mos
@@ -1,22 +1,23 @@
setCommandLineOptions("+g=MetaModelica");

compilerSources := "../../../OMCompiler/Compiler";
LoadCompilerSourcesRes:=boolAnd(x for x in OpenModelica.Scripting.loadFile({
"Types.mo",
"Absyn.mo",
"../../../Compiler/Util/Error.mo",
"../../../Compiler/Util/ErrorExt.mo",
"../../../Compiler/FrontEnd/Dump.mo",
"../../../Compiler/Util/Print.mo",
"../../../Compiler/Util/Flags.mo",
"../../../Compiler/Global/Global.mo",
"../../../Compiler/Util/Config.mo",
"../../../Compiler/Util/Debug.mo",
"../../../Compiler/Util/List.mo",
"../../../Compiler/Util/Settings.mo",
"../../../Compiler/Util/Corba.mo",
"../../../Compiler/Util/Flags.mo",
"../../../Compiler/Util/Util.mo",
"../../../Compiler/Util/System.mo",
compilerSources + "Util/Error.mo",
compilerSources + "Util/ErrorExt.mo",
compilerSources + "FrontEnd/Dump.mo",
compilerSources + "Util/Print.mo",
compilerSources + "Util/Flags.mo",
compilerSources + "Global/Global.mo",
compilerSources + "Util/Config.mo",
compilerSources + "Util/Debug.mo",
compilerSources + "Util/List.mo",
compilerSources + "Util/Settings.mo",
compilerSources + "Util/Corba.mo",
compilerSources + "Util/Flags.mo",
compilerSources + "Util/Util.mo",
compilerSources + "Util/System.mo",
"TokenModelica.mo",
"LexTableModelica.mo",
"LexerCodeModelica.mo",
Expand Down
5 changes: 5 additions & 0 deletions openmodelica/omcc/Makefile
Expand Up @@ -9,6 +9,11 @@ all: $(GEN_FILES)
LexerModelica.mo: OMCC.mos lexerModelica.l parserModelica.y LexerGenerator.mo ParserGenerator.mo OMCC.mo Absyn.mo LexerCode.tmo ParseCode.tmo Lexer.mo Types.mo Parser.mo
$(OMC) $<

omcc:
$(OMC) OMCC.mos
$(MAKE) -f OMCC_main.makefile MODELICAUSERCFLAGS='-DGENERATE_MAIN_EXECUTABLE -Os'
$(CC) -o OMCC OMCC_main.so '-Wl,-rpath,$$ORIGIN'

Main_main.so: GenerateParser.mos $(GEN_FILES) Main.mo
@rm -f $@
$(OMC) $<
Expand Down
146 changes: 55 additions & 91 deletions openmodelica/omcc/OMCC.mo
@@ -1,96 +1,60 @@
class OMCC

import Util;
import RTOpts;
import System;
import Absyn;
import LexerGenerator;
import ParserGenerator;
constant String copyright = "OMCCp v0.10.0 OpenModelica lexer and parser generator (2014)";

public function main
import Util;
import RTOpts;
import System;
import Absyn;
import LexerGenerator;
import ParserGenerator;
constant String copyright = "OMCCp v0.10.0 OpenModelica lexer and parser generator (2014)";

public function main
"function: main
This is the main function that the MetaModelica Compiler (MMC) runtime system calls to
start the translation."
input list<String> inStringLst;
algorithm

_ := matchcontinue (inStringLst)
local
String ver_str,errstr,filename,parser,ast;
list<String> args_1,args,chars;
String s,str,omhome,oldpath,newpath;
Boolean result;
case args as _::_
equation
{parser} = Flags.new(args);
print("Generating FLEX grammar file lexer" + parser +".c ...\n");
0 = System.systemCall("flex -t -l lexer" + parser +".l > lexer" + parser +".c");
print("Generating BISON grammar file parser" + parser +".c ...\n");
0 = System.systemCall("bison parser" + parser +".y --output=parser" + parser +".c");
str = LexerGenerator.genLexer("lexer"+ parser +".c", "lexer"+ parser +".l", parser);
print("Result:" + str + "\n");
str = ParserGenerator.genParser("parser"+ parser +".c","parser"+ parser +".y",parser);
print("Result:" + str + "\n");

print("\n 9 Files Generated for the language grammar:" + parser);
printUsage();
then ();
case _
equation
print("\n**********Error*************");
printUsage();
then fail();
end matchcontinue;
end main;

public function printUsage
protected
Integer n;
List<String> strs;
Absyn.Program prog;
Absyn.Class mClass;
Absyn.ClassDef mCDef;
algorithm
/* mCDef := Absyn.OVERLOAD({Absyn.IDENT("fname")},NONE());
mClass := Absyn.CLASS("ctest",false,false,false,Absyn.R_CLASS(),mCDef);
prog := Absyn.PROGRAM({mClass},Absyn.WITHIN(Absyn.IDENT("test")),Absyn.TIMESTAMP(System.getCurrentTime(),System.getCurrentTime()));
printAny(prog); */
print("\n" + copyright +& "\n");
end printUsage;

protected function readSettings
"function: readSettings
author: x02lucpo
Checks if 'settings.mos' exist and uses handleCommand with runScript(...) to execute it.
Checks if '-s <file>.mos' has been
returns Interactive.InteractiveSymbolTable which is used in the rest of the loop"
input list<String> inStringLst;
output String str;
algorithm
str:=
matchcontinue (inStringLst)
local
list<String> args;
case (args)
equation
outSymbolTable = Interactive.emptySymboltable;
"" = Util.flagValue("-s",args);
// this is out-commented because automatically reading settings.mos
// can make a system bad
// outSymbolTable = readSettingsFile("settings.mos", Interactive.emptySymboltable);
then
outSymbolTable;
case (args)
equation
str = Util.flagValue("-s",args);
str = System.trim(str," \"");
outSymbolTable = readSettingsFile(str, Interactive.emptySymboltable);
then
outSymbolTable;
end matchcontinue;
end readSettings;


This is the main function that the MetaModelica Compiler (MMC) runtime system calls to
start the translation."
input list<String> inStringLst;
algorithm

_ := matchcontinue (inStringLst)
local
String ver_str,errstr,filename,parser,ast;
list<String> args_1,args,chars;
String s,str,omhome,oldpath,newpath;
Boolean result;
case "--lexer-only" :: args
equation
{parser} = Flags.new(args);
print("Generating FLEX grammar file lexer" + parser +".c ...\n");
0 = System.systemCall("flex -t -l lexer" + parser +".l > lexer" + parser +".c");
str = LexerGenerator.genLexer("lexer"+ parser +".c", "lexer"+ parser +".l", parser);
print("Result:" + str + "\n");
print("\nGenerated files:\n" + sum(" " + s + "Modelica.mo\n" for s in {"LexerCode","Lexer","LexTable"}));
then ();
case args as _::_
equation
{parser} = Flags.new(args);
print("Generating FLEX grammar file lexer" + parser +".c ...\n");
0 = System.systemCall("flex -t -l lexer" + parser +".l > lexer" + parser +".c");
print("Generating BISON grammar file parser" + parser +".c ...\n");
0 = System.systemCall("bison parser" + parser +".y --output=parser" + parser +".c");
str = LexerGenerator.genLexer("lexer"+ parser +".c", "lexer"+ parser +".l", parser);
print("Result:" + str + "\n");
str = ParserGenerator.genParser("parser"+ parser +".c","parser"+ parser +".y",parser);
print("Result:" + str + "\n");

print("\n 9 Files Generated for the language grammar:" + parser);
then ();
case _
equation
print("\n**********Error*************");
printUsage();
then fail();
end matchcontinue;
end main;

public function printUsage
algorithm
print("\n" + copyright + "\n");
end printUsage;

end OMCC;
38 changes: 23 additions & 15 deletions openmodelica/omcc/OMCC.mos
@@ -1,21 +1,29 @@
OpenModelica.Scripting.setCFlags("-g " + getCFlags());getErrorString();
compilerSources := "../../../OMCompiler/Compiler/";
files := {
"OMCC.mo",
"../../../Compiler/FrontEnd/Absyn.mo",
"../../../Compiler/Util/List.mo",
"../../../Compiler/Util/Config.mo",
"../../../Compiler/Global/Global.mo",
"../../../Compiler/Util/Debug.mo",
"../../../Compiler/Util/ErrorExt.mo",
"../../../Compiler/Util/Error.mo",
"../../../Compiler/Util/Print.mo",
"../../../Compiler/Util/Corba.mo",
"../../../Compiler/Util/Settings.mo",
"../../../Compiler/Util/Flags.mo",
"../../../Compiler/Util/Util.mo",
"../../../Compiler/Util/System.mo",
compilerSources + "/Util/List.mo",
compilerSources + "/Util/Config.mo",
compilerSources + "/Global/Global.mo",
compilerSources + "/Util/Debug.mo",
compilerSources + "/Util/ErrorExt.mo",
compilerSources + "/Util/Error.mo",
compilerSources + "/Util/Print.mo",
compilerSources + "/Util/Corba.mo",
compilerSources + "/Util/Settings.mo",
compilerSources + "/Util/Flags.mo",
compilerSources + "/Util/Util.mo",
compilerSources + "/Util/StringUtil.mo",
compilerSources + "/Util/System.mo",
"LexerGenerator.mo",
"ParserGenerator.mo"};getErrorString();
setCommandLineOptions({"+g=MetaModelica","+d=rml"});
loadFile(files);getErrorString();
OMCC.main({"Modelica"});getErrorString();
res:=loadFile(files);
if min(res) == false then
print(getErrorString());
exit(1);
end if;
getErrorString();
// OMCC.main({"Modelica"});getErrorString();
generateCode(OMCC.main);
generateEntryPoint("omccMain.c", OMCC.main);
2 changes: 1 addition & 1 deletion openmodelica/omcc/ParserGenerator.mo
Expand Up @@ -425,7 +425,7 @@ package ParserGenerator
end if;
rest := substring(rest,pos1+2,pos2-4);
tokens := System.strtok(rest,",");
while (List.isEmpty(tokens)==false) loop
while (listEmpty(tokens)==false) loop
cp := "\n constant Integer ";
resTable := cp::resTable;
cp::tokens := tokens;
Expand Down

0 comments on commit 57342fe

Please sign in to comment.