"Fossies" - the Fresh Open Source Software Archive  

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

About:

codegen.cc  (ragel-7.0.0.9):codegen.cc  (ragel-7.0.0.10)
/* /*
* Copyright 2001-2014 Adrian Thurston <thurston@complang.org> * Copyright 2001-2014 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 "codegen.h" #include "codegen.h"
#include "ragel.h" #include "ragel.h"
#include "redfsm.h" #include "redfsm.h"
#include "gendata.h" #include "gendata.h"
#include "inputdata.h" #include "inputdata.h"
#include "parsedata.h" #include "parsedata.h"
#include <sstream> #include <sstream>
#include <string> #include <string>
skipping to change at line 94 skipping to change at line 95
{ {
values += 1; values += 1;
if ( v < min ) if ( v < min )
min = v; min = v;
if ( v > max ) if ( v > max )
max = v; max = v;
} }
void TableArray::finishAnalyze() void TableArray::finishAnalyze()
{ {
if ( codeGen.backend == Direct ) { /* Calculate the type if it is not already set. */
/* Calculate the type if it is not already set. */ if ( type.empty() ) {
if ( type.empty() ) { if ( min >= S8BIT_MIN && max <= S8BIT_MAX ) {
if ( min >= S8BIT_MIN && max <= S8BIT_MAX ) { type = "char";
type = "char"; width = sizeof(char);
width = sizeof(char); }
} else if ( min >= S16BIT_MIN && max <= S16BIT_MAX ) {
else if ( min >= S16BIT_MIN && max <= S16BIT_MAX ) { type = "short";
type = "short"; width = sizeof(short);
width = sizeof(short); }
} else if ( min >= S32BIT_MIN && max <= S32BIT_MAX ) {
else if ( min >= S32BIT_MIN && max <= S32BIT_MAX ) { type = "int";
type = "int"; width = sizeof(int);
width = sizeof(int); }
} else if ( min >= S64BIT_MAX && max <= S64BIT_MAX ) {
else if ( min >= S64BIT_MAX && max <= S64BIT_MAX ) { type = "long";
type = "long"; width = sizeof(long);
width = sizeof(long); }
} else {
else { type = "long long";
type = "long long"; width = sizeof(long long);
width = sizeof(long long);
}
}
}
else {
/* Calculate the type if it is not already set. */
if ( type.empty() ) {
if ( min >= S8BIT_MIN && max <= S8BIT_MAX ) {
type = "s8";
width = sizeof(char);
}
else if ( min >= S16BIT_MIN && max <= S16BIT_MAX ) {
type = "s16";
width = sizeof(short);
}
else if ( min >= S32BIT_MIN && max <= S32BIT_MAX ) {
type = "s32";
width = sizeof(int);
}
else if ( min >= S64BIT_MAX && max <= S64BIT_MAX ) {
type = "s64";
width = sizeof(long);
}
else {
type = "s128";
width = sizeof(long long);
}
} }
} }
} }
void TableArray::startGenerate() void TableArray::startGenerate()
{ {
if ( codeGen.backend == Direct ) { if ( stringTables ) {
if ( stringTables ) { out << "static const char S_" << codeGen.DATA_PREFIX() << name <<
out << "static const char S_" << codeGen.DATA_PREFIX() << "[] __attribute__((aligned (16))) = \n\t\"";
name <<
"[] __attribute__((aligned (16))) = \n\t\"";
}
else {
out << "static const " << type << " " <<
"_" << codeGen.DATA_PREFIX() << name <<
"[] = {\n\t";
}
} }
else { else {
out << "array " << type << " " << out << "static const " << type << " " <<
"_" << codeGen.DATA_PREFIX() << name << "_" << codeGen.DATA_PREFIX() << name <<
"( " << min << ", " << max << " ) = { "; "[] = {\n\t";
} }
} }
void TableArray::stringGenerate( long long value ) void TableArray::stringGenerate( long long value )
{ {
char c; char c;
short h; short h;
int i; int i;
long l; long l;
unsigned char *p = 0; unsigned char *p = 0;
skipping to change at line 214 skipping to change at line 181
out << 'x'; out << 'x';
out << std::setw(2) << (unsigned int) *p++; out << std::setw(2) << (unsigned int) *p++;
} }
out.flags( prevFlags ); out.flags( prevFlags );
out.fill( prevFill ); out.fill( prevFill );
} }
void TableArray::valueGenerate( long long v ) void TableArray::valueGenerate( long long v )
{ {
if ( codeGen.backend == Direct ) { if ( stringTables ) {
if ( stringTables ) { stringGenerate( v );
stringGenerate( v );
if ( ++ln % iall == 0 ) {
if ( ++ln % iall == 0 ) { out << "\"\n\t\"";
out << "\"\n\t\""; ln = 0;
ln = 0;
}
}
else {
if ( isChar )
out << "c(" << v << ")";
else if ( !isSigned )
out << v << "u";
else
out << v;
if ( ( ++ln % iall ) == 0 ) {
out << ",\n\t";
ln = 0;
}
else {
out << ", ";
}
} }
} }
else { else {
if ( isChar ) if ( isChar )
out << "c(" << v << ")"; out << "c(" << v << ")";
else if ( !isSigned ) else if ( !isSigned )
out << "u(" << v << ")"; out << v << "u";
else else
out << v; out << v;
out << ", ";
if ( ( ++ln % iall ) == 0 ) {
out << ",\n\t";
ln = 0;
}
else {
out << ", ";
}
} }
} }
void TableArray::finishGenerate() void TableArray::finishGenerate()
{ {
if ( codeGen.backend == Direct ) { if ( stringTables ) {
if ( stringTables ) { out << "\";\nconst " << type << " *_" << codeGen.DATA_PREFIX() <<
out << "\";\nconst " << type << " *_" << codeGen.DATA_PREFIX() << name <<
name << " = (const " << type << "*) S_" << codeGen.DATA_P
" = (const " << type << "*) S_" << codeGen.DATA_PREFIX() REFIX() << name << ";\n\n";
<< name << ";\n\n";
}
else {
if ( isChar )
out << "c(0)\n};\n\n";
else if ( !isSigned )
out << "0u\n};\n\n";
else
out << "0\n};\n\n";
}
} }
else { else {
if ( isChar ) if ( isChar )
out << "c(0) };\n\n"; out << "c(0)\n};\n\n";
else if ( !isSigned ) else if ( !isSigned )
out << "u(0) };\n\n"; out << "0u\n};\n\n";
else else
out << "0 };\n\n"; out << "0\n};\n\n";
} }
if ( codeGen.red->id->printStatistics ) { if ( codeGen.red->id->printStatistics ) {
codeGen.red->id->stats() << name << "\t" << values << "\t" << codeGen.red->id->stats() << name << "\t" << values << "\t" <<
size() << "\t" << endl; size() << "\t" << endl;
} }
codeGen.tableData += size(); codeGen.tableData += size();
} }
skipping to change at line 332 skipping to change at line 278
finishGenerate(); finishGenerate();
break; break;
} }
} }
/* Init code gen with in parameters. */ /* Init code gen with in parameters. */
CodeGen::CodeGen( const CodeGenArgs &args ) CodeGen::CodeGen( const CodeGenArgs &args )
: :
CodeGenData( args ), CodeGenData( args ),
tableData( 0 ), tableData( 0 ),
backend( args.id->backend ),
stringTables( args.id->stringTables ) stringTables( args.id->stringTables )
{ {
} }
void CodeGen::statsSummary() void CodeGen::statsSummary()
{ {
if ( red->id->printStatistics ) if ( red->id->printStatistics )
red->id->stats() << "table-data\t\t" << tableData << endl << endl ; red->id->stats() << "table-data\t\t" << tableData << endl << endl ;
} }
string CodeGen::CAST( string type ) string CodeGen::CAST( string type )
{ {
if ( backend == Direct ) return "(" + type + ")";
return "(" + type + ")";
else
return "cast(" + type + ")";
} }
/* Write out the fsm name. */ /* Write out the fsm name. */
string CodeGen::FSM_NAME() string CodeGen::FSM_NAME()
{ {
return fsmName; return fsmName;
} }
/* Emit the offset of the start state as a decimal integer. */ /* Emit the offset of the start state as a decimal integer. */
string CodeGen::START_STATE_ID() string CodeGen::START_STATE_ID()
skipping to change at line 525 skipping to change at line 467
string result; string result;
while ( level-- > 0 ) while ( level-- > 0 )
result += "\t"; result += "\t";
return result; return result;
} }
/* Write out a key from the fsm code gen. Depends on wether or not the key is /* Write out a key from the fsm code gen. Depends on wether or not the key is
* signed. */ * signed. */
string CodeGen::KEY( Key key ) string CodeGen::KEY( Key key )
{ {
if ( backend == Direct ) { ostringstream ret;
ostringstream ret; if ( alphType->isChar )
if ( alphType->isChar ) ret << "c(" << (unsigned long) key.getVal() << ")";
ret << "c(" << (unsigned long) key.getVal() << ")"; else if ( keyOps->isSigned || !keyOps->explicitUnsigned )
else if ( keyOps->isSigned || !keyOps->explicitUnsigned ) ret << key.getVal();
ret << key.getVal(); else
else ret << (unsigned long) key.getVal() << "u";
ret << (unsigned long) key.getVal() << "u"; return ret.str();
return ret.str();
}
else {
ostringstream ret;
if ( alphType->isChar )
ret << "c(" << (unsigned long) key.getVal() << ")";
else if ( keyOps->isSigned || !keyOps->explicitUnsigned )
ret << key.getVal();
else
ret << "u(" << (unsigned long) key.getVal() << ")";
return ret.str();
}
} }
bool CodeGen::isAlphTypeSigned() bool CodeGen::isAlphTypeSigned()
{ {
return keyOps->isSigned; return keyOps->isSigned;
} }
void CodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFini sh ) void CodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFini sh )
{ {
/* The parser gives fexec two children. The double brackets are for D /* The parser gives fexec two children. The double brackets are for D
skipping to change at line 696 skipping to change at line 626
int targState, bool inFinish, bool csForced ) int targState, bool inFinish, bool csForced )
{ {
if ( item->children->length() > 0 ) { if ( item->children->length() > 0 ) {
/* Write the block and close it off. */ /* Write the block and close it off. */
ret << OPEN_GEN_EXPR(); ret << OPEN_GEN_EXPR();
INLINE_LIST( ret, item->children, targState, inFinish, csForced ) ; INLINE_LIST( ret, item->children, targState, inFinish, csForced ) ;
ret << CLOSE_GEN_EXPR(); ret << CLOSE_GEN_EXPR();
} }
} }
void CodeGen::INLINE_EXPR( ostream &ret, GenInlineList *inlineList )
{
ret << OPEN_HOST_EXPR();
INLINE_LIST( ret, inlineList, 0, false, false );
ret << CLOSE_HOST_EXPR();
}
void CodeGen::INLINE_BLOCK( ostream &ret, GenInlineExpr *inlineExpr )
{
out << OPEN_HOST_BLOCK( inlineExpr );
INLINE_LIST( out, inlineExpr->inlineList, 0, false, false );
out << CLOSE_HOST_BLOCK();
}
void CodeGen::INLINE_PLAIN( ostream &ret, GenInlineExpr *inlineExpr )
{
}
/* Write out an inline tree structure. Walks the list and possibly calls out /* Write out an inline tree structure. Walks the list and possibly calls out
* to virtual functions than handle language specific items in the tree. */ * to virtual functions than handle language specific items in the tree. */
void CodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList, void CodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList,
int targState, bool inFinish, bool csForced ) int targState, bool inFinish, bool csForced )
{ {
for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) { for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) {
switch ( item->type ) { switch ( item->type ) {
case GenInlineItem::Text: case GenInlineItem::Text:
translatedHostData( ret, item->data ); translatedHostData( ret, item->data );
break; break;
skipping to change at line 829 skipping to change at line 778
ostringstream ret; ostringstream ret;
for ( char *pc = path; *pc != 0; pc++ ) { for ( char *pc = path; *pc != 0; pc++ ) {
if ( *pc == '\\' ) if ( *pc == '\\' )
ret << "\\\\"; ret << "\\\\";
else else
ret << *pc; ret << *pc;
} }
return ret.str(); return ret.str();
} }
void CodeGen::EOF_CHECK( ostream &ret )
{
ret <<
" if ( " << P() << " == " << PE() << " )\n"
" goto _test_eof;\n";
testEofUsed = true;
}
void CodeGen::ACTION( ostream &ret, GenAction *action, IlOpts opts ) void CodeGen::ACTION( ostream &ret, GenAction *action, IlOpts opts )
{ {
ret << '\t'; ret << '\t';
ret << OPEN_HOST_BLOCK( action->loc.fileName, action->loc.line ); ret << OPEN_HOST_BLOCK( action->loc.fileName, action->loc.line );
INLINE_LIST( ret, action->inlineList, opts.targState, opts.inFinish, opts .csForced ); INLINE_LIST( ret, action->inlineList, opts.targState, opts.inFinish, opts .csForced );
ret << CLOSE_HOST_BLOCK(); ret << CLOSE_HOST_BLOCK();
} }
void CodeGen::CONDITION( ostream &ret, GenAction *condition ) void CodeGen::CONDITION( ostream &ret, GenAction *condition )
{ {
skipping to change at line 966 skipping to change at line 924
string ret = alphType->data1; string ret = alphType->data1;
if ( alphType->data2 != 0 ) { if ( alphType->data2 != 0 ) {
ret += " "; ret += " ";
ret += + alphType->data2; ret += + alphType->data2;
} }
return ret; return ret;
} }
void CodeGen::VALUE( string type, string name, string value ) void CodeGen::VALUE( string type, string name, string value )
{ {
if ( backend == Direct ) out << "static const " << type << " " << name << " = " << value << ";\n";
out << "static const " << type << " " << name << " = " << value <
< ";\n";
else
out << "value " << type << " " << name << " = " << value << ";\n"
;
} }
string CodeGen::STR( int v ) string CodeGen::STR( int v )
{ {
ostringstream s; ostringstream s;
s << v; s << v;
return s.str(); return s.str();
} }
void CodeGen::STATE_IDS() void CodeGen::STATE_IDS()
 End of changes. 22 change blocks. 
151 lines changed or deleted 104 lines changed or added

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