?? check.c
字號:
/****************************************************************************\
Copyright (c) 2002, NVIDIA Corporation.
NVIDIA Corporation("NVIDIA") supplies this software to you in
consideration of your agreement to the following terms, and your use,
installation, modification or redistribution of this NVIDIA software
constitutes acceptance of these terms. If you do not agree with these
terms, please do not use, install, modify or redistribute this NVIDIA
software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, NVIDIA grants you a personal, non-exclusive
license, under NVIDIA's copyrights in this original NVIDIA software (the
"NVIDIA Software"), to use, reproduce, modify and redistribute the
NVIDIA Software, with or without modifications, in source and/or binary
forms; provided that if you redistribute the NVIDIA Software, you must
retain the copyright notice of NVIDIA, this notice and the following
text and disclaimers in all such redistributions of the NVIDIA Software.
Neither the name, trademarks, service marks nor logos of NVIDIA
Corporation may be used to endorse or promote products derived from the
NVIDIA Software without specific prior written permission from NVIDIA.
Except as expressly stated in this notice, no other rights or licenses
express or implied, are granted by NVIDIA herein, including but not
limited to any patent rights that may be infringed by your derivative
works or by other works in which the NVIDIA Software may be
incorporated. No hardware is licensed hereunder.
THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER
PRODUCTS.
IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT,
INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY
OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE
NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
//
// check.c
//
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "slglobals.h"
static int CheckFunctionDefinition(Scope *fScope, Symbol *funSymb, int IsProgram);
#define NOT_CHECKED 0
#define BEING_CHECKED 1
#define ALREADY_CHECKED 2
/*
* CheckSymbolTree()
*
*/
static int CheckSymbolTree(Scope *fScope, Symbol *fSymb, int IsProgram)
{
int count = 0;
if (fSymb) {
Cg->theHAL->CheckDefinition(&fSymb->loc, fSymb->name, fSymb->type);
count += CheckSymbolTree(fScope, fSymb->left, IsProgram);
count += CheckSymbolTree(fScope, fSymb->right, IsProgram);
}
return count;
} // CheckSymbolTree
/*
* CheckParamsAndLocals() - Check this functions format parameters and local variables
* for unallowed things.
*/
static int CheckParamsAndLocals(Symbol *funSymb, int IsProgram)
{
Scope *lScope;
int count = 0;
lScope = funSymb->details.fun.locals;
count += CheckSymbolTree(lScope, lScope->symbols, IsProgram);
return count;
} // CheckParamsAndLocals
/*
* BuildProgramReturnAssignments() - Insert a series of assignment statements before each return
* statement to set the values of the program's result for these memeners. (Should only
* be applied to the main program.) Deletes the return statement.
*/
struct BuildReturnAssignments {
Scope *globalScope;
Symbol *program;
};
static stmt *BuildProgramReturnAssignments(stmt *fStmt, void *arg1, int arg2)
{
struct BuildReturnAssignments *lstr;
Symbol *program, *lSymb, *voutVar, *outSymb, *retSymb;
Type *lType, *rettype;
expr *lExpr, *rexpr, *returnVar, *outputVar;
Scope *lScope, *gScope, *voutScope;
stmt *lStmt, *stmtlist;
int category, len, lname;
if (fStmt->commonst.kind == RETURN_STMT) {
lstr = (struct BuildReturnAssignments *) arg1;
gScope = lstr->globalScope;
program = lstr->program;
lType = program->type;
rettype = lType->fun.rettype;
category = GetCategory(rettype);
if (IsVoid(rettype)) {
fStmt = NULL;
} else {
if (category == TYPE_CATEGORY_STRUCT) {
stmtlist = NULL;
voutVar = Cg->theHAL->varyingOut;
voutScope = voutVar->type->str.members;
lScope = rettype->str.members;
lSymb = lScope->symbols;
while (lSymb) {
// Create an assignment statement of the bound variable to the $vout member:
lname = lSymb->details.var.semantics ? lSymb->details.var.semantics : lSymb->name;
outSymb = LookUpLocalSymbol(voutScope, lname);
retSymb = LookUpLocalSymbol(lScope, lSymb->name);
if (outSymb && retSymb) {
// outSymb may not be in the symbol table if it's a "hidden" register.
returnVar = DupExpr(fStmt->returnst.exp);
outputVar = (expr *) NewSymbNode(VARIABLE_OP, voutVar);
lExpr = GenMemberReference(outputVar, outSymb);
rexpr = GenMemberReference(returnVar, retSymb);
if (IsScalar(lSymb->type) || IsVector(lSymb->type, &len)) {
lStmt = NewSimpleAssignmentStmt(&program->loc, lExpr, rexpr, 0);
stmtlist = ConcatStmts(stmtlist, lStmt);
} else {
FatalError("Return of unsupported type");
// xxx
}
}
lSymb = lSymb->next;
}
fStmt = stmtlist;
} else {
// Already reported:
// SemanticError(&program->loc, ERROR_S_PROGRAM_MUST_RETURN_STRUCT,
// GetAtomString(atable, program->name));
}
}
}
return fStmt;
} // BuildProgramReturnAssignments
/*
* CheckNodeForUndefinedFunctions() - Check an expression nodefor calls to undefined functions.
*
*/
static expr *CheckNodeForUndefinedFunctions(expr *fExpr, void *arg1, int arg2)
{
Symbol *lSymb;
expr *lExpr;
int *count = (int *) arg1;
switch (fExpr->common.kind) {
case DECL_N:
case SYMB_N:
case CONST_N:
case UNARY_N:
break;
case BINARY_N:
if (fExpr->bin.op == FUN_CALL_OP) {
lExpr = fExpr->bin.left;
if (lExpr->common.kind == SYMB_N) {
lSymb = lExpr->sym.symbol;
if (IsFunction(lSymb)) {
if (!(lSymb->properties & SYMB_IS_DEFINED)) {
SemanticError(Cg->pLastSourceLoc, ERROR_S_CALL_UNDEF_FUN,
GetAtomString(atable, lSymb->name));
count++;
} else {
if (lSymb->flags == BEING_CHECKED) {
SemanticError(Cg->pLastSourceLoc, ERROR_S_RECURSION,
GetAtomString(atable, lSymb->name));
count++;
} else {
CheckFunctionDefinition(NULL, lSymb, 0);
}
}
}
}
}
break;
case TRINARY_N:
break;
default:
assert(!"bad kind to CheckNodeForUndefinedFunctions()");
break;
}
return fExpr;
} // CheckNodeForUndefinedFunctions
/*
* CheckExpressionForUndefinedFunctions() - Check an expression for calls to undefined functions.
*
*/
static expr *CheckExpressionForUndefinedFunctions(expr *fExpr, void *arg1, int arg2)
{
PostApplyToNodes(CheckNodeForUndefinedFunctions, fExpr, arg1, arg2);
return fExpr;
} // CheckExpressionForUndefinedFunctions
/*
* CheckNodeForUnsupportedOperators() - Check a node for operators not supported
* in the target profile.
*/
static expr *CheckNodeForUnsupportedOperators(expr *fExpr, void *arg1, int arg2)
{
int *count = (int *) arg1;
switch (fExpr->common.kind) {
case DECL_N:
case SYMB_N:
case CONST_N:
break;
case UNARY_N:
if (!Cg->theHAL->IsValidOperator(Cg->pLastSourceLoc, opcode_atom[fExpr->un.op], fExpr->un.op,
fExpr->un.subop))
{
*count++;
}
break;
case BINARY_N:
if (!Cg->theHAL->IsValidOperator(Cg->pLastSourceLoc, opcode_atom[fExpr->bin.op], fExpr->bin.op,
fExpr->bin.subop))
{
*count++;
}
break;
case TRINARY_N:
if (!Cg->theHAL->IsValidOperator(Cg->pLastSourceLoc, opcode_atom[fExpr->tri.op], fExpr->tri.op,
fExpr->tri.subop))
{
*count++;
}
break;
default:
assert(!"bad kind to CheckNodeForUnsupportedOperators()");
break;
}
return fExpr;
} // CheckNodeForUnsupportedOperators
/*
* CheckForUnsupportedVariables() - Check for references to object that are not supported
* by the target profile.
*/
static expr *CheckForUnsupportedVariables(expr *fExpr, void *arg1, int arg2)
{
int *count = (int *) arg1;
switch (fExpr->common.kind) {
case SYMB_N:
if (fExpr->sym.op == VARIABLE_OP) {
///lSymb = fExpr->sym.symbol;
}
break;
case DECL_N:
case CONST_N:
case UNARY_N:
case BINARY_N:
case TRINARY_N:
break;
default:
assert(!"bad kind to CheckForUnsupportedVariables()");
break;
}
return fExpr;
} // CheckForUnsupportedVariables
/*
* CheckForGlobalUniformReferences() - Check for references to previously unreferenced non-static
* uniform global variables. These must have explicit or implied semantics. Add them to
* to the $uniform connector and insert an initialization statement at the start of main.
*/
static expr *CheckForGlobalUniformReferences(expr *fExpr, void *arg1, int arg2)
{
int category, domain, qualifiers;
Symbol *lSymb;
Type *lType;
int gname;
switch (fExpr->common.kind) {
case SYMB_N:
if (fExpr->sym.op == VARIABLE_OP) {
lSymb = fExpr->sym.symbol;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -