?? printutils.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.
\****************************************************************************/
// printutils.c
//
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "slglobals.h"
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// Debug Printing Functions: //////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
#undef PICK
#define PICK(a, b, c, d, e) b
const char *opcode_name[] = {
OPCODE_TABLE
};
#undef PICK
#define PICK(a, b, c, d, e) e
const subopkind subop_table[] = {
OPCODE_TABLE
};
#undef PICK
/*
* lIndent()
*
*/
static void lIndent(int level)
{
int ii;
for (ii = 0; ii < level; ii++)
printf(" ");
} // lIndent
/*
* lBPrintExpression() - Print a low level representation of an expression tree.
*
*/
static void lBPrintExpression(expr *fexpr, int level)
{
char s[32];
int subop, mask, ii, nn, bval;
int OK = 1, HasString = 0;
lIndent(level);
if (fexpr) {
switch (fexpr->common.kind) {
case DECL_N:
printf("DECLARATION");
OK = 0;
break;
case SYMB_N:
printf("S ");
break;
case CONST_N:
printf("C ");
break;
case UNARY_N:
printf("U ");
break;
case BINARY_N:
printf("B ");
break;
case TRINARY_N:
printf("T ");
break;
default:
printf("<kind=%02x>", fexpr->common.kind);
OK = 0;
break;
}
if (OK) {
printf("%c%c", fexpr->sym.IsLValue ? 'L' : ' ',
fexpr->common.HasSideEffects ? '+' : ' ');
subop = fexpr->co.subop;
switch (subop_table[fexpr->co.op]) {
case SUB_NONE:
printf("- - - ");
mask = ~0;
break;
case SUB_S:
printf("- - %1x ", SUBOP_GET_T(subop));
mask = 0x0000000f;
break;
case SUB_V:
case SUB_VS:
case SUB_SV:
printf("- %1x %1x ", SUBOP_GET_S(subop), SUBOP_GET_T(subop));
mask = 0x000000ff;
break;
case SUB_M:
case SUB_VM:
case SUB_MV:
printf("%1x %1x %1x ", SUBOP_GET_S2(subop), SUBOP_GET_S1(subop),
SUBOP_GET_T1(subop));
mask = 0x0000f0ff;
break;
case SUB_Z:
printf("%1x %1x %1x ", SUBOP_GET_S2(subop), SUBOP_GET_S1(subop),
SUBOP_GET_T1(subop));
mask = SUBOP_GET_MASK(subop);
nn = SUBOP_GET_S2(subop);
if (nn == 0)
nn = 1; // var.x is scalar, not array[1]
s[nn] = '\0';
for (ii = 0; ii < nn; ii++)
s[ii] = "xyzw"[(mask >> ii*2) & 3];
mask = 0x00fff0ff;
HasString = 1;
break;
case SUB_ZM:
printf("%1x %1x %1x %1x ", SUBOP_GET_S2(subop), SUBOP_GET_T2(subop),
SUBOP_GET_S1(subop), SUBOP_GET_T1(subop));
mask = SUBOP_GET_MASK16(subop);
nn = SUBOP_GET_T2(subop);
if (nn == 0)
nn = 1; // var.x is scalar, not array[1]
s[nn*3] = '\0';
for (ii = 0; ii < nn; ii++) {
s[ii*3] = '_';
s[ii*3 + 1] = '0' + ((mask >> (ii*4 + 2)) & 3);
s[ii*3 + 2] = '0' + ((mask >> ii*4) & 3);
}
mask = 0xffffffff;
HasString = 1;
break;
case SUB_CS:
printf("%1x - %1x ", SUBOP_GET_T2(subop), SUBOP_GET_T1(subop));
mask = 0x00000f0f;
break;
case SUB_CV:
printf("%1x %1x %1x ", SUBOP_GET_T2(subop), SUBOP_GET_S1(subop),
SUBOP_GET_T1(subop));
mask = 0x00000fff;
break;
case SUB_CM:
printf("%1x %1x %1x %1x ", SUBOP_GET_S2(subop), SUBOP_GET_T2(subop),
SUBOP_GET_S1(subop), SUBOP_GET_T1(subop));
mask = 0x0000ffff;
break;
case SUB_KV:
printf("- %1x %1x ", SUBOP_GET_S(subop), SUBOP_GET_T(subop));
mask = SUBOP_GET_MASK(subop) & 0xf;
for (ii = 0; ii < 4; ii++)
printf("%c", (mask >> ii) & 1 ? "xyzw"[ii] : '-');
printf(" ");
mask = 0x000f00ff;
break;
default:
mask = 0;
break;
}
if (subop & ~mask)
printf("<<non-zero:%08x>> ", subop & ~mask);
printf("%-6s ", opcode_name[fexpr->co.op]);
switch (fexpr->common.kind) {
case SYMB_N:
printf("\"%s\"", GetAtomString(atable, fexpr->sym.symbol->name));
break;
case CONST_N:
switch (fexpr->co.op) {
case ICONST_OP:
printf("%d", fexpr->co.val[0].i);
break;
case ICONST_V_OP:
nn = SUBOP_GET_S(subop);
printf("{ ");
for (ii = 0; ii < nn; ii++) {
if (ii > 0)
printf(", ");
printf("%d", fexpr->co.val[ii].i);
}
printf(" }");
break;
case BCONST_OP:
bval = fexpr->co.val[0].i;
if (bval == 0) {
printf("false");
} else if (bval == 1) {
printf("true");
} else {
printf("<<bad-bool-%08x>>", fexpr->co.val[0].i);
}
break;
case BCONST_V_OP:
nn = SUBOP_GET_S(subop);
printf("{ ");
for (ii = 0; ii < nn; ii++) {
if (ii > 0)
printf(", ");
bval = fexpr->co.val[ii].i;
if (bval == 0) {
printf("false");
} else if (bval == 1) {
printf("true");
} else {
printf("<<bad-bool-%08x>>", fexpr->co.val[ii].i);
}
}
printf(" }");
break;
case FCONST_OP:
case HCONST_OP:
case XCONST_OP:
printf("%1.6g", fexpr->co.val[0].f);
break;
case FCONST_V_OP:
case HCONST_V_OP:
case XCONST_V_OP:
nn = SUBOP_GET_S(subop);
printf("{ ");
for (ii = 0; ii < nn; ii++) {
if (ii > 0)
printf(", ");
printf("%1.6g", fexpr->co.val[ii].f);
}
printf(" }");
break;
default:
printf("UNKNOWN-CONSTANT");
break;
}
break;
case UNARY_N:
break;
case BINARY_N:
break;
case TRINARY_N:
break;
}
if (HasString)
printf(" %s", s);
printf(" ");
PrintType(fexpr->common.type, 1);
printf("\n");
switch (fexpr->common.kind) {
case SYMB_N:
break;
case CONST_N:
break;
case UNARY_N:
lBPrintExpression(fexpr->un.arg, level + 1);
break;
case BINARY_N:
lBPrintExpression(fexpr->bin.left, level + 1);
lBPrintExpression(fexpr->bin.right, level + 1);
break;
case TRINARY_N:
lBPrintExpression(fexpr->tri.arg1, level + 1);
lBPrintExpression(fexpr->tri.arg2, level + 1);
lBPrintExpression(fexpr->tri.arg3, level + 1);
break;
}
} else {
printf("\n");
}
} else {
printf("NULL\n");
}
} // lBPrintExpression
void BPrintExpression(expr *fexpr)
{
lBPrintExpression(fexpr, 0);
}
static void lBPrintStmt(stmt *fstmt, int level);
/*
* lBPrintStmtList()
*
*/
void lBPrintStmtList(stmt *fstmt, int level)
{
while (fstmt) {
lBPrintStmt(fstmt, level);
fstmt = fstmt->commonst.next;
}
} // lBPrintStmtList
void BPrintStmtList(stmt *fstmt)
{
lBPrintStmtList(fstmt, 0);
}
/*
* lBPrintStmt()
*
*/
static void lBPrintStmt(stmt *fstmt, int level)
{
stmt *lstmt;
switch (fstmt->exprst.kind) {
case EXPR_STMT:
if (fstmt->exprst.exp) {
lBPrintExpression(fstmt->exprst.exp, level);
} else {
printf("/* empty statement */\n");
}
break;
case IF_STMT:
lIndent(level);
printf("if\n");
lBPrintExpression(fstmt->ifst.cond, level + 1);
lIndent(level);
printf("then\n");
lBPrintStmtList(fstmt->ifst.thenstmt, level + 1);
if (fstmt->ifst.elsestmt) {
lIndent(level);
printf("else\n");
lBPrintStmtList(fstmt->ifst.elsestmt, level + 1);
}
break;
case WHILE_STMT:
lIndent(level);
printf("while\n");
lBPrintExpression(fstmt->whilest.cond, level + 1);
lBPrintStmtList(fstmt->whilest.body, level + 1);
break;
case DO_STMT:
lIndent(level);
printf("do\n");
lBPrintStmtList(fstmt->whilest.body, level + 1);
lIndent(level);
printf("while\n");
lBPrintExpression(fstmt->whilest.cond, level + 1);
break;
case FOR_STMT:
lIndent(level);
printf("for\n");
lstmt = fstmt->forst.init;
if (lstmt) {
lBPrintStmtList(fstmt->forst.init, level + 1);
}
printf("for-cond\n");
if (fstmt->forst.cond) {
lBPrintExpression(fstmt->forst.cond, level + 1);
}
printf("for-step\n");
lstmt = fstmt->forst.step;
if (lstmt) {
lBPrintStmtList(fstmt->forst.step, level + 1);
}
printf("for-body\n");
lBPrintStmtList(fstmt->forst.body, level + 1);
break;
case BLOCK_STMT:
if (level > 1)
lIndent(level - 1);
printf("{\n");
lBPrintStmtList(fstmt->blockst.body, level);
if (level > 1)
lIndent(level - 1);
printf("}\n");
break;
case RETURN_STMT:
lIndent(level);
printf("return\n");
if (fstmt->returnst.exp) {
lBPrintExpression(fstmt->returnst.exp, level + 1);
}
break;
case DISCARD_STMT:
lIndent(level);
printf("discard\n");
if (fstmt->discardst.cond)
lBPrintExpression(fstmt->discardst.cond, level + 1);
break;
case COMMENT_STMT:
lIndent(level);
printf("// %s\n", GetAtomString(atable, fstmt->commentst.str));
break;
default:
lIndent(level);
printf("<!BadStmt-0x%2x>\n", fstmt->exprst.kind);
}
} // lBPrintStmt
void BPrintStmt(stmt *fstmt)
{
lBPrintStmt(fstmt, 0);
}
/*
* FormatTypeString() - Build a printable string of a type.
*
* Arrays are shown as: "packed float[4]" instead of "float4".
*
*/
void FormatTypeString(char *name, int size, char *name2, int size2, Type *fType)
{
int qualifiers, category, base, cid;
char tname[32];
strcpy(name2, "");
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -