C++ parser for source code instrumentation


This work area provides a parser program that produces modified source code for performance estimation. The original code is analyzed indentifying the basic blocks and adding code marks to integrate the blocks execution time and optionally the information for instruction cache modeling. The execution time is stored in a variable declared as : "extern unsigned long long uc_segment_consumed_time; " in the parsed files. This variable can be read at the end of code semgnets to annotate the execution time. Then, the value has to be cleaned to start the next segment.

The work area requires only lex and yacc, or flex and bison.

Index:

  • Command line options
  • Files that compose the parser source code
  • How to build the parser
  • Description of the configuration files
  • How to execute the test
  • Examples provided
  • Original C++ grammar used

  • Command Line

    The test grammar is a simple command line utility, for analysing a single pre-processed source file (use CC -E to run just the preprocessor on your source files)..

    	grammar [options] < source-file

    The full set of command line options is:

    	Parser options:
    	-i: prepare the code to model instruction caches
    	-c: print each keywork in stdout
    	-t: print the number of the line analyzed
    	-m: print makrs when gramatical rules are discarded during checking
    	-y: print all gramatical operations (shifts and reductions)
    	-p processor: define the processor where the code will run
    	-f files: list of files to be parsed. The list ends when other option is speficied.
    	          If no -f option is used, stdin and stdout are used by default
    	-a: parse all included files that are not in /usr/ directory
    	          If option -a is not used only the code between START_CODE and END_CODE pragmas is parsed 
    

    On completion a three line diagnostic summarises the search activity.


    Files

    CxxLexer.l A simple lexer for all C and/or C++ tokens

    CxxParser.y The parser, automatically extracted from FogParser.y.

    CxxToken.hxx, CxxToken.cxx A trivial class used by the parser to represent each parsed token.

    CxxLexing.hxx, CxxLexing.cxx Interface and implementation of token creation routines for the lexer.

    CxxParsing.hxx, CxxParsing.cxx Interface and implementation of token manioulation routines for the parser.

    CxxCosts.hxx, CxxCosts.cxx Configuration file loader.

    CxxAnnotation.hxx, CxxAnnotation.cxx Introduces the annotation instructions in the code.

    CxxLexer.cpp, CxxParser.cpp, CxxToken.cpp Degenerate compilation units for the above.

    makefile, makefile.macros, makefile.unix Unix build scripts

    sun4o/parser Built executable (on Unix)

    tests Tests directory

    examples Examples directory

    The work area is self-sufficient, requiring only lex and yacc, or flex and bison.


    Linux / Unix Builds

    The code builds with Gnu gcc 4.1 release, with flex 2.5.33, bison 2.3

    	make gnu

    or under Solaris 2.5 and with Sun C++ 4.2.

    	make sun

    Configuration files

    The parser annotates the code with the execution costs provided by the file "time_param.dat":

    	clause <processor>: Encapsulates all the information regarding a processor type
    		clause <type>: Indicates the processor type. The name is selected by the parser when the "-f name" option is used
    		clause <time>: Execution time costs for the C/C++ operators
    		clause <instructions>: Number of  words in the binary code needed to implement the C/C++ operators
    			clause <int>: Execution time costs for int operators
    			clause <float>: Execution time costs for float operators
    			clause <char>: Execution time costs for char operators
    			clause <bool>: Execution time costs for boolean operators
    			clause <control>: Execution time costs for C/C++ control statmenets
    

    Tests

    There are several tests to chech if the parser is correct. To check it run:

    	make check

    Examples

    There is a large example provided together with the parser. The example is a gsm vocoder, modeled as a single task. To compile the example go to the "examples/vocoder_gsm/simgle_source_parsed" directory. There are two options to compile the code, compile without instruction cache:

    	make [nocache]

    or with instruction cache.

    	make icache

    To run the example, execute "vocoder.x"

    This process requires SCope tool running and having the environment variable SCOPE_HOME properly configured



    Original C++ Grammar


    The parser is based on a demonstration of the superset C++ grammar downloadable from The grammar is described in Chapter 5 of Ed Willink's thesis on Meta-Compilation for C++.