1/****************************************************************************\ 2Copyright (c) 2002, NVIDIA Corporation. 3 4NVIDIA Corporation("NVIDIA") supplies this software to you in 5consideration of your agreement to the following terms, and your use, 6installation, modification or redistribution of this NVIDIA software 7constitutes acceptance of these terms. If you do not agree with these 8terms, please do not use, install, modify or redistribute this NVIDIA 9software. 10 11In consideration of your agreement to abide by the following terms, and 12subject to these terms, NVIDIA grants you a personal, non-exclusive 13license, under NVIDIA's copyrights in this original NVIDIA software (the 14"NVIDIA Software"), to use, reproduce, modify and redistribute the 15NVIDIA Software, with or without modifications, in source and/or binary 16forms; provided that if you redistribute the NVIDIA Software, you must 17retain the copyright notice of NVIDIA, this notice and the following 18text and disclaimers in all such redistributions of the NVIDIA Software. 19Neither the name, trademarks, service marks nor logos of NVIDIA 20Corporation may be used to endorse or promote products derived from the 21NVIDIA Software without specific prior written permission from NVIDIA. 22Except as expressly stated in this notice, no other rights or licenses 23express or implied, are granted by NVIDIA herein, including but not 24limited to any patent rights that may be infringed by your derivative 25works or by other works in which the NVIDIA Software may be 26incorporated. No hardware is licensed hereunder. 27 28THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT 29WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 30INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, 31NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 32ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER 33PRODUCTS. 34 35IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, 36INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 37TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 38USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY 39OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE 40NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, 41TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 42NVIDIA 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 53CPPStruct *cpp = NULL; 54static int refCount = 0; 55 56int InitPreprocessor(void); 57int ResetPreprocessor(void); 58int FreeCPPStruct(void); 59int FinalizePreprocessor(void); 60 61/* 62 * InitCPPStruct() - Initilaize the CPP structure. 63 * 64 */ 65 66int 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 89int 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 107int 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 125int FreeCPPStruct(void) 126{ 127 if (refCount) 128 { 129 free(cpp); 130 refCount--; 131 } 132 133 return 1; 134} 135 136//Finalizing the Preprocessor. 137 138int 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