Home | History | Annotate | Download | only in preprocessor
      1 /****************************************************************************\
      2 Copyright (c) 2002, NVIDIA Corporation.
      3 
      4 NVIDIA Corporation("NVIDIA") supplies this software to you in
      5 consideration of your agreement to the following terms, and your use,
      6 installation, modification or redistribution of this NVIDIA software
      7 constitutes acceptance of these terms.  If you do not agree with these
      8 terms, please do not use, install, modify or redistribute this NVIDIA
      9 software.
     10 
     11 In consideration of your agreement to abide by the following terms, and
     12 subject to these terms, NVIDIA grants you a personal, non-exclusive
     13 license, under NVIDIA's copyrights in this original NVIDIA software (the
     14 "NVIDIA Software"), to use, reproduce, modify and redistribute the
     15 NVIDIA Software, with or without modifications, in source and/or binary
     16 forms; provided that if you redistribute the NVIDIA Software, you must
     17 retain the copyright notice of NVIDIA, this notice and the following
     18 text and disclaimers in all such redistributions of the NVIDIA Software.
     19 Neither the name, trademarks, service marks nor logos of NVIDIA
     20 Corporation may be used to endorse or promote products derived from the
     21 NVIDIA Software without specific prior written permission from NVIDIA.
     22 Except as expressly stated in this notice, no other rights or licenses
     23 express or implied, are granted by NVIDIA herein, including but not
     24 limited to any patent rights that may be infringed by your derivative
     25 works or by other works in which the NVIDIA Software may be
     26 incorporated. No hardware is licensed hereunder.
     27 
     28 THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
     29 WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
     30 INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
     31 NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
     32 ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
     33 PRODUCTS.
     34 
     35 IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
     36 INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
     37 TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
     38 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
     39 OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
     40 NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
     41 TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
     42 NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     43 \****************************************************************************/
     44 //
     45 // cppstruct.c
     46 //
     47 
     48 #include <stdio.h>
     49 #include <stdlib.h>
     50 
     51 #include "compiler/preprocessor/slglobals.h"
     52 
     53 CPPStruct  *cpp      = NULL;
     54 static int  refCount = 0;
     55 
     56 int InitPreprocessor(void);
     57 int ResetPreprocessor(void);
     58 int FreeCPPStruct(void);
     59 int FinalizePreprocessor(void);
     60 
     61 /*
     62  * InitCPPStruct() - Initilaize the CPP structure.
     63  *
     64  */
     65 
     66 int InitCPPStruct(void)
     67 {
     68     int len;
     69     char *p;
     70 
     71     cpp = (CPPStruct *) malloc(sizeof(CPPStruct));
     72     if (cpp == NULL)
     73         return 0;
     74 
     75     refCount++;
     76 
     77     // Initialize public members:
     78     cpp->pLastSourceLoc = &cpp->lastSourceLoc;
     79 
     80 	p = (char *) &cpp->options;
     81     len = sizeof(cpp->options);
     82     while (--len >= 0)
     83         p[len] = 0;
     84 
     85     ResetPreprocessor();
     86     return 1;
     87 } // InitCPPStruct
     88 
     89 int ResetPreprocessor(void)
     90 {
     91     // Initialize private members:
     92 
     93     cpp->lastSourceLoc.file = 0;
     94     cpp->lastSourceLoc.line = 0;
     95 	cpp->pC=0;
     96     cpp->CompileError=0;
     97 	cpp->ifdepth=0;
     98     for(cpp->elsetracker=0; cpp->elsetracker<64; cpp->elsetracker++)
     99 		cpp->elsedepth[cpp->elsetracker]=0;
    100 	cpp->elsetracker=0;
    101     cpp->tokensBeforeEOF = 0;
    102     return 1;
    103 }
    104 
    105 //Intializing the Preprocessor.
    106 
    107 int InitPreprocessor(void)
    108 {
    109    #  define CPP_STUFF true
    110         #  ifdef CPP_STUFF
    111             FreeCPPStruct();
    112             InitCPPStruct();
    113             cpp->options.Quiet = 1;
    114             cpp->options.profileString = "generic";
    115             if (!InitAtomTable(atable, 0))
    116                 return 1;
    117             if (!InitScanner(cpp))
    118 	            return 1;
    119        #  endif
    120   return 0;
    121 }
    122 
    123 //FreeCPPStruct() - Free the CPP structure.
    124 
    125 int FreeCPPStruct(void)
    126 {
    127     if (refCount)
    128     {
    129        free(cpp);
    130        refCount--;
    131     }
    132 
    133     return 1;
    134 }
    135 
    136 //Finalizing the Preprocessor.
    137 
    138 int FinalizePreprocessor(void)
    139 {
    140    #  define CPP_STUFF true
    141         #  ifdef CPP_STUFF
    142             FreeAtomTable(atable);
    143             FreeCPPStruct();
    144             FreeScanner();
    145        #  endif
    146   return 0;
    147 }
    148 
    149 
    150 ///////////////////////////////////////////////////////////////////////////////////////////////
    151 ////////////////////////////////////// End of cppstruct.c //////////////////////////////////////
    152 ///////////////////////////////////////////////////////////////////////////////////////////////
    153