Related sites: University of Antwerp | Department of Mathematics and Computer Science

# CANT Research Group

Navigation: Precompiler

# Usage

^ TOP

## Usage and parameters

Running the precompiler without parameters, displays the list of command line options :

    wschrep> ./precompile
    Usage: ./precompile <inputfile> <outputfile> [options]

    Options:
      -x <configfile>    specifies the conversion configuration file
      -preparse          preparse rather than precompile to generate a list of all variables and functions
                         that would normally be converted
      -c <skipfile>      specifies a file containing functions and/or variables which must not be converted
      -constants         identify all constants in C/C++ file
      -noprintf          don't convert printf statements
      -nofor             don't convert variables in for loops
      -init <initfile>   insert source code contained in <initfile> file after the main(){

    The following options are specific for transcription with the MpIeee library.

      -default           insert default MpIeee settings after the main(){
      -radix <size>      set the radix size, default size=2
      -precision <size>  set the precision size, default size=24
      -exp <low> <up>    set the exponent, default low=-126, upper=127
      -expbits <bitsize> set the number of exponent bits
      -round <n|p|m|z>   set the rounding mode, default = n
                          n = round to nearest
                          p = round to plus inf
                          m = round to min inf
                          z = round to zero
      -outputverbose     set verbose output
      -outputmpieee <p|d|b|y|h|r|f>+ set the MpIeee output format, default = d
                          p = parameter
                          d = decimal
                          b = binary
                          y = binary representation
                          h = hexadecimal representation
                          r = rational
                          f = flags

^ TOP

## Configuring the conversion (-x)

The -x <configfile> option specifies the XML configuration file that determines the conversions performed by the precompiler. We write and use a new configuration file in Example 9.

^ TOP

## Finding variables (-preparse)

With this option, the precompiler operates in preparse mode. This means that the output file will not contain converted source code but instead a list with the name of all variables and functions that would normally be converted when using the specified conversion configuration file. This option is illustrated in Example 2.

^ TOP

## Skipping variables and functions (-c)

With this option, the user can specify a file with functions and/or variables that must not be converted. The format of this file is XML. A sample skipfile is given in Example 4.

^ TOP

## Finding constants (-constants)

Analogue to the -preparse option, the -constants option is used to generate a file with all constants and their location in the input file. In Example 3 this option is used.

^ TOP

## Printf statements (-noprintf)

This option skips conversion of printf statements. This overrules the default behavior of the precompiler which converts printf statements to std::cout instructions. The default behavior is the obvious choice when converting standard types to C++ class types. This option is illustrated in Example 1.

^ TOP

## For loops (-nofor)

With this command line option, variables declared in for-loops are not converted. This option is illustrated in Example 1.

^ TOP

## Adding extra settings after main (-init)

With the option -init <initfile> , the C/C++ code in the initfile will be inserted at the beginning of the main function. It is mainly used to add extra initialization code. The same effect can also be achieved by using an <init>tag inside a configuration file. The usage of this option is illustrated in Example 7.

^ TOP

## MpIeee default settings (-default)

The MpIeee default settings for radix, precision, exp, expbits, rounding mode, and output format are inserted into the main routine of the input file. The default MpIeee settings can be overridden using one of the following options: -radix, -precision, -exp, -expbits, -round, -outputverbose, -outputmpieee. See Examples 5 and 6.

^ TOP

## MpIeee radix (-radix)

Initializes the given radix size in the main function. Needs to be used in combination with the -default option. The radix must be a power of 2 or 10. The default radix setting is 2. With the options

    ./precompile in.cpp out.cpp -radix 16 -default

the following is inserted in the main function of out.cpp:

    MpIeee::fpEnv.setRadix(16);

See also Example 5.

^ TOP

## MpIeee precision (-precision)

Initializes the given precision in the main function. Needs to be used in combination with the -default option. The default precision setting is 24. The given precision should be larger than or equal to 4. With the options

    ./precompile in.cpp out.cpp -precision 5 -default

the following is inserted in the main function of out.cpp:

    MpIeee::fpEnv.setPrecision(5);

See also Example 5.

^ TOP

## MpIeee exponent (-exp)

Sets the minimum and maximum exponent sizes L and U. The defaults are L=-126 and U=127. This option needs to be used in combination with the -default option. For example

    ./precompile in.cpp out.cpp -exp -2000 1999 -default

inserts the following in the main function of out.cpp:

    MpIeee::fpEnv.setExponentRange(-2000,1999);

See also Example 6.

^ TOP

## MpIeee exponent bits (-expbits)

Sets the number of exponent bits. The default is 8 bits, which corresponds to L=-126 and U=127. Use this option only in combination with the -default option. For example,

    ./precompile in.cpp out.cpp -expbits 16 -default

inserts the following in the main function of out.cpp:

    MpIeee::fpEnv.setExponentRange(-32766,32767);

See also Example 5.

^ TOP

## MpIeee rounding mode (-round)

Sets the rounding mode (n,p,m,z). The default setting is round to nearest. Use only in combination with the -default option. With the options

    ./precompile in.cpp out.cpp -round z -default

the following is inserted:

    MpIeee::fpEnv.setRound(FP_RZ);

See also Example 5.

^ TOP

## MpIeee verbose mode (-outputverbose)

This sets the ARITHMOS_IO_VERBOSE flag of the library which has the effect that more verbose information is printed when calling different routines in the MpIeee library. Use this option only in combination with the -default option. For example,

    ./precompile in.cpp out.cpp -outputverbose -default

inserts the following line of code in the main function of out.cpp:

    ArithmosIO::setIoMode(ARITHMOS_IO_VERBOSE|ARITHMOS_IO_MPIEEE_DECIMAL);

This is illustrated in Example 6.

^ TOP

## MpIeee output flags (-outputmpieee)

This option enables various output formats for MpIeee variables. Use this option only together with the -default option. To enable all 6 available MpIeee output options, include the following options:

    ./precompile in.cpp out.cpp -outputmpieee pdbyhf -default

This will set all available output options in out.cpp:

    ArithmosIO::setIoMode(ARITHMOS_IO_MPIEEE_PARAM|ARITHMOS_IO_MPIEEE_DECIMAL|
                                       ARITHMOS_IO_MPIEEE_BINARY|ARITHMOS_IO_MPIEEE_BINREP|
                                       ARITHMOS_IO_MPIEEE_HEXREP|ARITHMOS_IO_MPIEEE_FLAGS);