"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main.cc" between
ragel-7.0.0.9.tar.gz and ragel-7.0.0.10.tar.gz

About:

main.cc  (ragel-7.0.0.9):main.cc  (ragel-7.0.0.10)
/* /*
* Copyright 2001-2015 Adrian Thurston <thurston@complang.org> * Copyright 2001-2015 Adrian Thurston <thurston@colm.net>
*/
/* This file is part of Ragel.
* *
* Ragel is free software; you can redistribute it and/or modify * Permission is hereby granted, free of charge, to any person obtaining a copy
* it under the terms of the GNU General Public License as published by * of this software and associated documentation files (the "Software"), to
* the Free Software Foundation; either version 2 of the License, or * deal in the Software without restriction, including without limitation the
* (at your option) any later version. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* *
* Ragel is distributed in the hope that it will be useful, * The above copyright notice and this permission notice shall be included in al
* but WITHOUT ANY WARRANTY; without even the implied warranty of l
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * copies or substantial portions of the Software.
* GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* along with Ragel; if not, write to the Free Software * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <fstream> #include <fstream>
#include <unistd.h> #include <unistd.h>
#include <sstream> #include <sstream>
skipping to change at line 104 skipping to change at line 105
" -p Display printable characters on labels\n" " -p Display printable characters on labels\n"
" -S <spec> FSM specification to output (for graphviz output)\n" " -S <spec> FSM specification to output (for graphviz output)\n"
" -M <machine> Machine definition/instantiation to output (for\n" " -M <machine> Machine definition/instantiation to output (for\n"
" graphviz output)\n" " graphviz output)\n"
"host language:\n" "host language:\n"
" -C C, C++, Obj-C or Obj-C++ (default)\n" " -C C, C++, Obj-C or Obj-C++ (default)\n"
" All code styles supported.\n" " All code styles supported.\n"
" --asm --gas-x86-64-sys-v\n" " --asm --gas-x86-64-sys-v\n"
" GNU AS, x86_64, System V ABI.\n" " GNU AS, x86_64, System V ABI.\n"
" Generated in a code style equivalent to -G2\n" " Generated in a code style equivalent to -G2\n"
" -D D All code styles supported\n"
" -Z Go All code styles supported\n"
" -A C# -T0 -T1 -F0 -F1 -G0 -G1\n"
" -J Java -T0 -T1 -F0 -F1\n"
" -R Ruby -T0 -T1 -F0 -F1\n"
" -O OCaml -T0 -T1 -F0 -F1\n"
" -U Rust -T0 -T1 -F0 -F1\n"
" -Y Julia -T0 -T1 -F0 -F1\n"
" -K Crack -T0 -T1 -F0 -F1\n"
" -P JavaScript -T0 -T1 -F0 -F1\n"
"line directives:\n" "line directives:\n"
" -L Inhibit writing of #line directives\n" " -L Inhibit writing of #line directives\n"
"code style:\n" "code style:\n"
" -T0 Binary search (default)\n" " -T0 Binary search (default)\n"
" -T1 Binary search with expanded actions \n" " -T1 Binary search with expanded actions \n"
" -F0 Flat table\n" " -F0 Flat table\n"
" -F1 Flat table with expanded actions\n" " -F1 Flat table with expanded actions\n"
" -G0 Switch-driven\n" " -G0 Switch-driven\n"
" -G1 Switch-driven with expanded actions\n" " -G1 Switch-driven with expanded actions\n"
" -G2 Goto-driven with expanded actions\n" " -G2 Goto-driven with expanded actions\n"
"large machines:\n" "large machines:\n"
" --integral-tables Use integers for table data (default)\n" " --integral-tables Use integers for table data (default)\n"
" --string-tables Encode table data into strings for faster host lang\n" " --string-tables Encode table data into strings for faster host lang\n"
" compilation\n" " compilation (C)\n"
"analysis:\n" "analysis:\n"
" --prior-interaction Search for condition-based general repetitions\ n" " --prior-interaction Search for condition-based general repetitions\ n"
" that will not function properly due to state mo d\n" " that will not function properly due to state mo d\n"
" overlap and must be NFA reps. \n" " overlap and must be NFA reps. \n"
" --conds-depth=D Search for high-cost conditions inside a prefix \n" " --conds-depth=D Search for high-cost conditions inside a prefix \n"
" of the machine (depth D from start state).\n" " of the machine (depth D from start state).\n"
" --state-limit=L Report fail if number of states exceeds this\n" " --state-limit=L Report fail if number of states exceeds this\n"
" during compilation.\n" " during compilation.\n"
" --breadth-check=E1,E2,.. Report breadth cost of named entry points and\n " " --breadth-check=E1,E2,.. Report breadth cost of named entry points and\n "
" the start state.\n" " the start state.\n"
skipping to change at line 216 skipping to change at line 207
{ {
info() << info() <<
"--direct-backend --colm-backend" << endl; "--direct-backend --colm-backend" << endl;
abortCompile( 0 ); abortCompile( 0 );
} }
void InputData::showStyles() void InputData::showStyles()
{ {
switch ( hostLang->lang ) { switch ( hostLang->lang ) {
case HostLang::C: case HostLang::C:
case HostLang::D:
case HostLang::Go:
info() << "-T0 -T1 -F0 -F1 -G0 -G1 -G2" << endl; info() << "-T0 -T1 -F0 -F1 -G0 -G1 -G2" << endl;
break; break;
case HostLang::CSharp:
info() << "-T0 -T1 -F0 -F1 -G0 -G1" << endl;
break;
case HostLang::Asm: case HostLang::Asm:
info() << "-G2" << endl; info() << "-G2" << endl;
break; break;
case HostLang::Java:
case HostLang::Ruby:
case HostLang::OCaml:
case HostLang::Crack:
case HostLang::Rust:
case HostLang::Julia:
info() << "-T0 -T1 -F0 -F1" << endl;
break;
case HostLang::JS:
info() << "-T0" << endl;
break;
} }
abortCompile( 0 ); abortCompile( 0 );
} }
InputLoc makeInputLoc( const char *fileName, int line, int col ) InputLoc makeInputLoc( const char *fileName, int line, int col )
{ {
InputLoc loc( fileName, line, col ); InputLoc loc( fileName, line, col );
return loc; return loc;
} }
skipping to change at line 261 skipping to change at line 235
for ( char *pc = path; *pc != 0; pc++ ) { for ( char *pc = path; *pc != 0; pc++ ) {
if ( *pc == '\\' ) if ( *pc == '\\' )
out << "\\\\"; out << "\\\\";
else else
out << *pc; out << *pc;
} }
} }
void InputData::parseArgs( int argc, const char **argv ) void InputData::parseArgs( int argc, const char **argv )
{ {
ParamCheck pc( "r:o:dnmleabjkS:M:I:CDEJZRAOKUYPvHh?-:sT:F:G:LpV", argc, a rgv ); ParamCheck pc( "r:o:dnmleabjkS:M:I:CEvHh?-:sT:F:G:LpV", argc, argv );
bool showStylesOpt = false; bool showStylesOpt = false;
/* Decide if we were invoked using a path variable, or with an explicit p ath. */ /* Decide if we were invoked using a path variable, or with an explicit p ath. */
const char *lastSlash = strrchr( argv[0], '/' ); const char *lastSlash = strrchr( argv[0], '/' );
if ( lastSlash == 0 ) { if ( lastSlash == 0 ) {
/* Defualt to the the binary install location. */ /* Defualt to the the binary install location. */
dirName = BINDIR; dirName = BINDIR;
} }
else { else {
skipping to change at line 378 skipping to change at line 352
error() << "please specify an argument to -I" << endl; error() << "please specify an argument to -I" << endl;
else { else {
includePaths.append( pc.paramArg ); includePaths.append( pc.paramArg );
} }
break; break;
/* Host language types. */ /* Host language types. */
case 'C': case 'C':
hostLang = &hostLangC; hostLang = &hostLangC;
break; break;
case 'D':
hostLang = &hostLangD;
break;
case 'Z':
hostLang = &hostLangGo;
break;
case 'J':
hostLang = &hostLangJava;
break;
case 'R':
hostLang = &hostLangRuby;
break;
case 'A':
hostLang = &hostLangCSharp;
break;
case 'O':
hostLang = &hostLangOCaml;
break;
case 'K':
hostLang = &hostLangCrack;
break;
case 'U':
hostLang = &hostLangRust;
break;
case 'Y':
hostLang = &hostLangJulia;
break;
case 'P':
hostLang = &hostLangJS;
break;
/* Version and help. */ /* Version and help. */
case 'v': case 'v':
version(); version();
break; break;
case 'H': case 'h': case '?': case 'H': case 'h': case '?':
usage(); usage();
break; break;
case 's': case 's':
printStatistics = true; printStatistics = true;
skipping to change at line 457 skipping to change at line 401
else if ( strcmp( arg, "kelbt-frontend" ) == 0 ) { else if ( strcmp( arg, "kelbt-frontend" ) == 0 ) {
frontend = KelbtBased; frontend = KelbtBased;
frontendSpecified = true; frontendSpecified = true;
} }
#else #else
else if ( strcmp( arg, "kelbt-frontend" ) == 0 ) { else if ( strcmp( arg, "kelbt-frontend" ) == 0 ) {
error() << "--kelbt-frontend specified bu t, " error() << "--kelbt-frontend specified bu t, "
"ragel not built with rag el+kelbt support" << endp; "ragel not built with rag el+kelbt support" << endp;
} }
#endif #endif
else if ( strcmp( arg, "colm-frontend" ) == 0 ) {
frontend = ColmBased;
frontendSpecified = true;
}
else if ( strcmp( arg, "reduce-frontend" ) == 0 ) { else if ( strcmp( arg, "reduce-frontend" ) == 0 ) {
frontend = ReduceBased; frontend = ReduceBased;
frontendSpecified = true; frontendSpecified = true;
} }
else if ( strcmp( arg, "asm" ) == 0 ) else if ( strcmp( arg, "asm" ) == 0 )
hostLang = &hostLangAsm; hostLang = &hostLangAsm;
else if ( strcmp( arg, "gnu-asm-x86-64-sys-v" ) = = 0 ) else if ( strcmp( arg, "gnu-asm-x86-64-sys-v" ) = = 0 )
hostLang = &hostLangAsm; hostLang = &hostLangAsm;
else if ( strcmp( arg, "direct" ) == 0 ) {
backend = Direct;
backendSpecified = true;
}
else if ( strcmp( arg, "direct-backend" ) == 0 )
{
backend = Direct;
backendSpecified = true;
}
else if ( strcmp( arg, "colm-backend" ) == 0 ) {
backend = Translated;
backendSpecified = true;
}
else if ( strcmp( arg, "var-backend" ) == 0 ) {
/* Forces variable-based backend, even if
the target
* language supports the goto-based backe
nd. May require
* --colm-backend depending on the target
language (C for
* example is direct by default). */
backendFeature = VarFeature;
featureSpecified = true;
}
else if ( strcmp( arg, "goto-backend" ) == 0 ) {
/* Forces goto-based based backend. */
backendFeature = GotoFeature;
featureSpecified = true;
}
else if ( strcmp( arg, "string-tables" ) == 0 ) else if ( strcmp( arg, "string-tables" ) == 0 )
stringTables = true; stringTables = true;
else if ( strcmp( arg, "integral-tables" ) == 0 ) else if ( strcmp( arg, "integral-tables" ) == 0 )
stringTables = false; stringTables = false;
else if ( strcmp( arg, "host-lang-names" ) == 0 ) else if ( strcmp( arg, "host-lang-names" ) == 0 )
showHostLangNames(); showHostLangNames();
else if ( strcmp( arg, "host-lang-args" ) == 0 || else if ( strcmp( arg, "host-lang-args" ) == 0 ||
strcmp( arg, "supported-host-lang s" ) == 0 ) strcmp( arg, "supported-host-lang s" ) == 0 )
showHostLangArgs(); showHostLangArgs();
else if ( strcmp( arg, "supported-frontends" ) == 0 ) else if ( strcmp( arg, "supported-frontends" ) == 0 )
skipping to change at line 614 skipping to change at line 529
break; break;
} }
} }
if ( showStylesOpt ) if ( showStylesOpt )
showStyles(); showStyles();
} }
bool langSupportsGoto( const HostLang *hostLang ) bool langSupportsGoto( const HostLang *hostLang )
{ {
if ( hostLang->lang == HostLang::Ruby ||
hostLang->lang == HostLang::OCaml ||
hostLang->lang == HostLang::Rust ||
hostLang->lang == HostLang::Crack ||
hostLang->lang == HostLang::Julia )
return false;
return true; return true;
} }
void InputData::loadHistogram() void InputData::loadHistogram()
{ {
const int alphsize = 256; const int alphsize = 256;
/* Init a default. */ /* Init a default. */
histogram = new double[alphsize]; histogram = new double[alphsize];
ifstream h( histogramFn ); ifstream h( histogramFn );
skipping to change at line 691 skipping to change at line 599
abortCompile( 1 ); abortCompile( 1 );
/* Make sure we are not writing to the same file as the input file. */ /* Make sure we are not writing to the same file as the input file. */
if ( inputFileName != 0 && outputFileName != 0 && if ( inputFileName != 0 && outputFileName != 0 &&
strcmp( inputFileName, outputFileName ) == 0 ) strcmp( inputFileName, outputFileName ) == 0 )
{ {
error() << "output file \"" << outputFileName << error() << "output file \"" << outputFileName <<
"\" is the same as the input file" << endp; "\" is the same as the input file" << endp;
} }
if ( !frontendSpecified ) { if ( !frontendSpecified )
if ( hostLang->lang == HostLang::C || hostLang->lang == HostLang: frontend = ReduceBased;
:Asm )
frontend = ReduceBased;
else
frontend = ColmBased;
}
if ( !backendSpecified ) {
if ( hostLang->lang == HostLang::C || hostLang->lang == HostLang:
:Asm )
backend = Direct;
else
backend = Translated;
}
if ( !featureSpecified ) {
if ( langSupportsGoto( hostLang ) )
backendFeature = GotoFeature;
else
backendFeature = VarFeature;
}
if ( checkBreadth ) { if ( checkBreadth ) {
if ( histogramFn != 0 ) if ( histogramFn != 0 )
loadHistogram(); loadHistogram();
else else
defaultHistogram(); defaultHistogram();
} }
} }
/*
* result: analysis output
* out: contents of stdout
* err: contents of stderr
* argc, argv: ragel arguments, input file ignored
* input: input file contents
*/
extern "C"
int libragel( char **result, char **out, char **err, int argc, const char **argv
, const char *input )
{
InputData id;
try {
id.inLibRagel = true;
id.parseArgs( argc, argv );
id.checkArgs();
id.input = input;
id.frontend = ReduceBased;
id.process();
}
catch ( const AbortCompile &ac ) {
*result = strdup( "" );
}
if ( result != 0 )
*result = strdup( id.comm.c_str() );
if ( out != 0 )
*out = strdup( id.libcout.str().c_str() );
if ( err != 0 )
*err = strdup( id.libcerr.str().c_str() );
return 0;
}
char *InputData::readInput( const char *inputFileName ) char *InputData::readInput( const char *inputFileName )
{ {
struct stat st; struct stat st;
int res = stat( inputFileName, &st ); int res = stat( inputFileName, &st );
if ( res != 0 ) { if ( res != 0 ) {
error() << inputFileName << ": stat failed: " << strerror(errno) << endl; error() << inputFileName << ": stat failed: " << strerror(errno) << endl;
return 0; return 0;
} }
std::ifstream in( inputFileName ); std::ifstream in( inputFileName );
skipping to change at line 790 skipping to change at line 646
/* Main, process args and call yyparse to start scanning input. */ /* Main, process args and call yyparse to start scanning input. */
int main( int argc, const char **argv ) int main( int argc, const char **argv )
{ {
int code = 0; int code = 0;
InputData id; InputData id;
try { try {
id.parseArgs( argc, argv ); id.parseArgs( argc, argv );
id.checkArgs(); id.checkArgs();
if ( id.forceLibRagel ) { if ( !id.process() )
id.inLibRagel = true; id.abortCompile( 1 );
id.input = id.readInput( id.inputFileName );
if ( id.input != 0 ) {
id.frontend = ReduceBased;
if ( !id.process() )
id.abortCompile( 1 );
}
}
else {
if ( !id.process() )
id.abortCompile( 1 );
}
} }
catch ( const AbortCompile &ac ) { catch ( const AbortCompile &ac ) {
code = ac.code; code = ac.code;
} }
if ( id.comm.size() > 0 ) { if ( id.comm.size() > 0 ) {
if ( id.commFileName == 0 ) { if ( id.commFileName == 0 ) {
std::cout << id.comm; std::cout << id.comm;
} }
else { else {
ofstream ofs( id.commFileName, std::fstream::app ); ofstream ofs( id.commFileName, std::fstream::app );
ofs << id.comm; ofs << id.comm;
ofs.close(); ofs.close();
} }
} }
if ( id.forceLibRagel ) {
std::cerr << id.libcerr.str();
std::cout << id.libcout.str();
std::cerr.flush();
std::cout.flush();
}
return code; return code;
} }
 End of changes. 18 change blocks. 
191 lines changed or deleted 23 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS