Thread: [Plib-cvs] plib/src/psl pslCodeGen.cxx,1.25,1.26 pslCompiler.cxx,1.23,1.24 pslCompiler.h,1.26,1.27 p
Brought to you by:
sjbaker
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv30590/plib/src/psl Modified Files: pslCodeGen.cxx pslCompiler.cxx pslCompiler.h pslContext.cxx pslContext.h pslDump.cxx pslError.cxx pslOpcodes.h pslProgram.cxx Log Message: Added line numbers to process tracing. Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- pslCodeGen.cxx 15 Sep 2002 04:34:39 -0000 1.25 +++ pslCodeGen.cxx 15 Sep 2002 06:36:24 -0000 1.26 @@ -41,6 +41,14 @@ } +void pslCompiler::pushLineNumber ( int l ) +{ + pushCodeByte ( OPCODE_LINE_NUMBER ) ; + pushCodeByte ( l & 0xFF ) ; + pushCodeByte ( ( l >> 8 ) & 0xFF ) ; +} + + void pslCompiler::pushConstant ( const char *c ) { int isInteger = TRUE ; Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- pslCompiler.cxx 15 Sep 2002 04:34:39 -0000 1.23 +++ pslCompiler.cxx 15 Sep 2002 06:36:24 -0000 1.24 @@ -595,6 +595,9 @@ { char c [ MAX_TOKEN ] ; + if ( generate_line_numbers ) + pushLineNumber ( _pslGetLineNo () ) ; + getToken ( c ) ; if ( strcmp ( c, "static" ) == 0 ) return pushStaticVarDecl () ; Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- pslCompiler.h 15 Sep 2002 04:34:39 -0000 1.26 +++ pslCompiler.h 15 Sep 2002 06:36:24 -0000 1.27 @@ -73,6 +73,8 @@ void pushCodeAddr ( pslAddress a ) ; int printOpcode ( FILE *fd, int addr ) const ; + void pushLineNumber ( int l ) ; + /* Write single byte-coded instructions into code space. */ void pushStackDup () ; @@ -180,6 +182,8 @@ int next_code_symbol ; int next_define ; + int generate_line_numbers ; + char *define_token [ MAX_SYMBOL ] ; char *define_replacement [ MAX_SYMBOL ] ; @@ -297,6 +301,7 @@ program = prog ; progName = ulStrDup ( _progName ) ; + generate_line_numbers = FALSE ; code = _code ; extensions = _extn ; @@ -327,6 +332,13 @@ const pslExtension *getExtensions () const { return extensions ; } int printInstruction ( FILE *fd, int addr ) const ; + + + void generateLineNumbers () + { + generate_line_numbers = TRUE ; + } + void init () { Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- pslContext.cxx 15 Sep 2002 04:34:39 -0000 1.13 +++ pslContext.cxx 15 Sep 2002 06:36:24 -0000 1.14 @@ -32,6 +32,11 @@ pc++ ; return PSL_PROGRAM_END ; + case OPCODE_LINE_NUMBER : + line_no = code [ pc + 1 ] + ( code [ pc + 2 ] << 8 ) ; + pc+=3 ; + return PSL_PROGRAM_CONTINUE ; + case OPCODE_PUSH_INT_CONSTANT : { int ii ; Index: pslContext.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pslContext.h 15 Sep 2002 04:34:39 -0000 1.10 +++ pslContext.h 15 Sep 2002 06:36:24 -0000 1.11 @@ -35,6 +35,7 @@ int num_errors ; int num_warnings ; + int line_no ; void bumpErrors () { num_errors++ ; } void bumpWarnings () { num_warnings++ ; } @@ -57,6 +58,9 @@ ~pslContext () {} ; + int getLineNo () { return line_no ; } + + void pushInt ( int x ) { stack [ sp++ ] . set ( x ) ; } void pushFloat ( float x ) { stack [ sp++ ] . set ( x ) ; } void pushString ( const char *x ) { stack [ sp++ ] . set ( x ) ; } @@ -86,6 +90,8 @@ { for ( int i = 0 ; i < MAX_VARIABLE ; i++ ) variable [ i ] . reset () ; + + line_no = -1 ; sp = 0 ; pc = 0 ; Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- pslDump.cxx 15 Sep 2002 04:34:39 -0000 1.19 +++ pslDump.cxx 15 Sep 2002 06:36:24 -0000 1.20 @@ -38,6 +38,8 @@ { { "NO_OP" , OPCODE_NOOP , 0 }, + { "SOURCE LINE NUMBER:", OPCODE_LINE_NUMBER, 2 }, + /* Stack operations */ { "PUSH_INT_CONSTANT" , OPCODE_PUSH_INT_CONSTANT , sizeof(int) }, @@ -96,6 +98,7 @@ { "SHIFT_LEFT", OPCODE_SHIFTLEFT , 0 }, { "SHIFT_RIGHT", OPCODE_SHIFTRIGHT , 0 }, + /* Boolean operators */ { "LESS", OPCODE_LESS , 0 }, @@ -205,6 +208,11 @@ switch ( code [ addr ] ) { + case OPCODE_LINE_NUMBER : + fprintf ( fd, "%d =====================", + code[addr+1] + ( code[addr+2] << 8 ) ) ; + break ; + case OPCODE_SET_INT_VARIABLE : case OPCODE_SET_FLOAT_VARIABLE : case OPCODE_SET_STRING_VARIABLE : Index: pslError.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslError.cxx,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pslError.cxx 13 Sep 2002 22:32:15 -0000 1.6 +++ pslError.cxx 15 Sep 2002 06:36:24 -0000 1.7 @@ -48,12 +48,11 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( program, PSL_COMPILETIME_WARNING, _pslGetFname(), _pslGetLineNo(), - _pslErrorBuffer ) ; + (*_pslErrorCB)( program, PSL_COMPILETIME_WARNING, + _pslGetFname(), _pslGetLineNo(), _pslErrorBuffer ) ; else fprintf ( stderr, "PSL: \"%s\" line %3d: WARNING - %s\n", - _pslGetFname(), _pslGetLineNo(), - _pslErrorBuffer ) ; + _pslGetFname(), _pslGetLineNo(), _pslErrorBuffer ) ; bumpWarnings () ; return FALSE ; @@ -69,12 +68,11 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( program, PSL_COMPILETIME_ERROR, _pslGetFname(), _pslGetLineNo(), - _pslErrorBuffer ) ; + (*_pslErrorCB)( program, PSL_COMPILETIME_ERROR, + _pslGetFname(), _pslGetLineNo(), _pslErrorBuffer ) ; else fprintf ( stderr, "PSL: \"%s\" line %3d: *ERROR* - %s\n", - _pslGetFname(), _pslGetLineNo(), - _pslErrorBuffer ) ; + _pslGetFname(), _pslGetLineNo(), _pslErrorBuffer ) ; bumpErrors () ; return FALSE ; @@ -90,10 +88,15 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( program, PSL_RUNTIME_WARNING, getProgName(), pc, _pslErrorBuffer ) ; + (*_pslErrorCB)( program, PSL_RUNTIME_WARNING, + getProgName(), getLineNo(), _pslErrorBuffer ) ; else - fprintf ( stderr, "PSL: \"%s\" PC=%d: WARNING - %s\n", - getProgName(), pc, _pslErrorBuffer ) ; + if ( getLineNo () >= 0 ) + fprintf ( stderr, "PSL: \"%s\" Line %d: WARNING - %s\n", + getProgName(), getLineNo(), _pslErrorBuffer ) ; + else + fprintf ( stderr, "PSL: \"%s\": WARNING - %s\n", + getProgName(), _pslErrorBuffer ) ; bumpWarnings () ; } @@ -108,10 +111,15 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( program, PSL_RUNTIME_ERROR, getProgName(), pc, _pslErrorBuffer ) ; + (*_pslErrorCB)( program, PSL_RUNTIME_ERROR, + getProgName(), getLineNo(), _pslErrorBuffer ) ; else - fprintf ( stderr, "PSL: \"%s\" PC=%d: *ERROR* - %s\n", - getProgName(), pc, _pslErrorBuffer ) ; + if ( getLineNo () >= 0 ) + fprintf ( stderr, "PSL: \"%s\" Line %d: *ERROR* - %s\n", + getProgName(), getLineNo(), _pslErrorBuffer ) ; + else + fprintf ( stderr, "PSL: \"%s\": *ERROR* - %s\n", + getProgName(), _pslErrorBuffer ) ; bumpErrors () ; } Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pslOpcodes.h 15 Sep 2002 04:34:39 -0000 1.11 +++ pslOpcodes.h 15 Sep 2002 06:36:24 -0000 1.12 @@ -71,6 +71,7 @@ #define OPCODE_DECREMENT 0x2A #define OPCODE_PEEK_JUMP_FALSE 0x2B #define OPCODE_PEEK_JUMP_TRUE 0x2C +#define OPCODE_LINE_NUMBER 0x2D #define OPCODE_POP_ADD_VARIABLE 0x30 #define OPCODE_POP_SUB_VARIABLE 0x31 Index: pslProgram.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslProgram.cxx,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pslProgram.cxx 15 Sep 2002 04:34:39 -0000 1.12 +++ pslProgram.cxx 15 Sep 2002 06:36:24 -0000 1.13 @@ -50,6 +50,9 @@ force_trace = ( force_trace_env != NULL && ulStrEqual ( force_trace_env, "always" ) ) ; + + if ( force_trace ) + compiler -> generateLineNumbers () ; } |