?? compile.c
字號:
expr *GenMatIndex(expr *mExpr, expr *xexpr, int base, int len, int len2)
{
expr *lExpr;
lExpr = (expr *) NewBinopNode(ARRAY_INDEX_OP, mExpr, xexpr);
lExpr->bin.type = GetStandardType(base, len, 0);
return lExpr;
} // GenMatIndex
/*
* GenBoolConst() - Create a Boolean constant node.
*
*/
expr *GenBoolConst(int fval)
{
expr *lExpr;
lExpr = (expr *) NewBConstNode(BCONST_OP, fval, TYPE_BASE_BOOLEAN);
return lExpr;
} // GenBoolConst
/*
* GenIntConst() - Create an integer constant node.
*
*/
expr *GenIntConst(int fval)
{
expr *lExpr;
lExpr = (expr *) NewIConstNode(ICONST_OP, fval, TYPE_BASE_INT);
return lExpr;
} // GenIntConst
/*
* GenFConstV() - Create a vector floating point constant node.
*
*/
expr *GenFConstV(float *fval, int len, int base)
{
expr *lExpr;
lExpr = (expr *) NewFConstNodeV(FCONST_V_OP, fval, len, base);
return lExpr;
} // GenFConstV
/*
* GenBoolNot() - Create a Boolean NOT.
*
*/
expr *GenBoolNot(expr *fExpr)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP__(TYPE_BASE_BOOLEAN);
lExpr = (expr *) NewUnopSubNode(BNOT_OP, lsubop, fExpr);
lExpr->un.type = BooleanType;
return lExpr;
} // GenBoolNot
/*
* GenBoolAssign() - Create a Boolean assignment.
*
*/
expr *GenBoolAssign(expr *fVar, expr *fExpr)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP__(TYPE_BASE_BOOLEAN);
lExpr = (expr *) NewBinopSubNode(ASSIGN_OP, lsubop, fVar, fExpr);
lExpr->bin.type = BooleanType;
return lExpr;
} // GenBoolAssign
/*
* GenSAssign() - Create a scalar assignment.
*
*/
expr *GenSAssign(expr *fVar, expr *fExpr, int base)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_S(base);
lExpr = (expr *) NewBinopSubNode(ASSIGN_OP, lsubop, fVar, fExpr);
lExpr->bin.type = GetStandardType(base, 0, 0);
return lExpr;
} // GenSAssign
/*
* GenVAssign() - Create a vector assignment.
*
*/
expr *GenVAssign(expr *fVar, expr *fExpr, int base, int len)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_V(len, base);
lExpr = (expr *) NewBinopSubNode(ASSIGN_V_OP, lsubop, fVar, fExpr);
lExpr->bin.type = GetStandardType(base, len, 0);
return lExpr;
} // GenCondSVAssign
/*
* GenMAssign() - Create a matrix assignment.
*
*/
expr *GenMAssign(expr *fVar, expr *fExpr, int base, int len, int len2)
{
expr *lExpr;
lExpr = (expr *) NewBinopNode(ASSIGN_GEN_OP, fVar, fExpr);
lExpr->bin.type = GetStandardType(base, len, len2);
return lExpr;
} // GenMAssign
/*
* GenCondSAssign() - Create a scalar conditional assignment.
*
*/
expr *GenCondSAssign(expr *fVar, expr *fCond, expr *fExpr, int base)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_S(base);
lExpr = (expr *) NewTriopSubNode(ASSIGN_COND_OP, lsubop, fVar, fCond, fExpr);
lExpr->tri.type = GetStandardType(base, 0, 0);
return lExpr;
} // GenCondSAssign
/*
* GenCondSVAssign() - Create a vector conditional assignment with a scalar Boolean argument.
*
*/
expr *GenCondSVAssign(expr *fVar, expr *fCond, expr *fExpr, int base, int len)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_SV(len, base);
lExpr = (expr *) NewTriopSubNode(ASSIGN_COND_SV_OP, lsubop, fVar, fCond, fExpr);
lExpr->tri.type = GetStandardType(base, len, 0);
return lExpr;
} // GenCondSVAssign
/*
* GenCondVAssign() - Create a vector conditional assignment with a vector Boolean argument.
*
*/
expr *GenCondVAssign(expr *fVar, expr *fCond, expr *fExpr, int base, int len)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_V(len, base);
lExpr = (expr *) NewTriopSubNode(ASSIGN_COND_V_OP, lsubop, fVar, fCond, fExpr);
lExpr->tri.type = GetStandardType(base, len, 0);
return lExpr;
} // GenCondVAssign
/*
* GenCondGenAssign() - Create a geeral conditional assignment.
*
*/
expr *GenCondGenAssign(expr *fVar, expr *fCond, expr *fExpr)
{
expr *lExpr;
int lsubop;
lsubop = 0;
lExpr = (expr *) NewTriopSubNode(ASSIGN_COND_GEN_OP, lsubop, fVar, fCond, fExpr);
lExpr->tri.type = fVar->common.type;
return lExpr;
} // GenCondGenAssign
/*
* GenBoolAnd() - Create a Boolean &&.
*
*/
expr *GenBoolAnd(expr *aExpr, expr *bExpr)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP__(TYPE_BASE_BOOLEAN);
lExpr = (expr *) NewBinopSubNode(BAND_OP, lsubop, aExpr, bExpr);
lExpr->bin.type = BooleanType;
return lExpr;
} // GenBoolAnd
/*
* GenBoolAndVec() - Create a Boolean Vector &&.
*
*/
expr *GenBoolAndVec(expr *aExpr, expr *bExpr, int len)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_V(len, TYPE_BASE_BOOLEAN);
lExpr = (expr *) NewBinopSubNode(BAND_V_OP, lsubop, aExpr, bExpr);
lExpr->bin.type = GetStandardType(TYPE_BASE_BOOLEAN, len, 0);
return lExpr;
} // GenBoolAndVec
/*
* GenBoolSmear() - Smear a Boolean Vector @xxxx.
*
*/
expr *GenBoolSmear(expr *fExpr, int len)
{
expr *lExpr;
int lsubop, mask;
mask = (0 << 6) | (0 << 4) | (0 << 2) | 0;
lsubop = SUBOP_Z(mask, len, 0, TYPE_BASE_BOOLEAN);
lExpr = (expr *) NewUnopSubNode(SWIZZLE_Z_OP, lsubop, fExpr);
lExpr->bin.type = GetStandardType(TYPE_BASE_BOOLEAN, len, 0);
return lExpr;
} // GenBoolSmear
/*
* GenExprList() - Add a node to an expression list.
*
*/
expr *GenExprList(expr *fExpr, expr *nExpr, Type *ftype)
{
expr *lExpr, *tExpr;
lExpr = (expr *) NewBinopNode(EXPR_LIST_OP, nExpr, NULL);
lExpr->common.type = ftype;
if (fExpr) {
tExpr = fExpr;
while (tExpr->bin.right)
tExpr = tExpr->bin.right;
tExpr->bin.right = lExpr;
} else {
fExpr = lExpr;
}
return fExpr;
} // GenExprList
/*
* GenVecMult() - Create a Vector Multiply
*
*/
expr *GenVecMult(expr *aExpr, expr *bExpr, int base, int len)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_V(len, base);
lExpr = (expr *) NewBinopSubNode(MUL_V_OP, lsubop, aExpr, bExpr);
lExpr->bin.type = GetStandardType(base, len, 0);
return lExpr;
} // GenVecMult
/*
* GenScaleVecMult() - Create a smeared Scalar-Vector Multiply
*
*/
expr *GenScaleVecMult(expr *aExpr, expr *bExpr, int base, int len)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_V(len, base);
lExpr = (expr *) NewBinopSubNode(MUL_VS_OP, lsubop, aExpr, bExpr);
lExpr->bin.type = GetStandardType(base, len, 0);
return lExpr;
} // GenScaleVecMult
/*
* GenVecAdd() - Create a Vector Addition
*
*/
expr *GenVecAdd(expr *aExpr, expr *bExpr, int base, int len)
{
expr *lExpr;
int lsubop;
lsubop = SUBOP_V(len, base);
lExpr = (expr *) NewBinopSubNode(ADD_V_OP, lsubop, aExpr, bExpr);
lExpr->bin.type = GetStandardType(base, len, 0);
return lExpr;
} // GenVecAdd
/*
* GenConvertVectorSize() - Convert a vector to another length, or to a scalar if newlen is 1.
* Return original expression if no conversion needed.
*/
expr *GenConvertVectorLength(expr *fExpr, int base, int len, int newlen)
{
int mask, ii;
expr *lExpr;
if (newlen != len) {
for (ii = 0; ii < newlen; ii++) {
if (ii < len) {
mask |= ii << (ii*2);
} else {
mask |= len - 1; // Use last component if source shorter than dest
}
}
if (newlen == 1)
newlen = 0; // I.e. scalar, not array[1]
lExpr = (expr *) NewUnopSubNode(SWIZZLE_Z_OP, SUBOP_Z(mask, newlen, len, base), fExpr);
lExpr->un.type = GetStandardType(base, newlen, 0);
} else {
lExpr = fExpr;
}
return lExpr;
} // GenConvertVectorLength
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// Duplicate Functions /////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
/*
* DuplicateNode() - Duplicate a node.
*
*/
expr *DuplicateNode(expr *fExpr, void *arg1, int arg2)
{
expr *lExpr;
if (fExpr) {
switch (fExpr->common.kind) {
case SYMB_N:
lExpr = (expr *) DupSymbNode(&fExpr->sym);
break;
case CONST_N:
lExpr = (expr *) DupConstNode(&fExpr->co);
break;
case UNARY_N:
lExpr = (expr *) DupUnaryNode(&fExpr->un);
break;
case BINARY_N:
lExpr = (expr *) DupBinaryNode(&fExpr->bin);
break;
case TRINARY_N:
lExpr = (expr *) DupTrinaryNode(&fExpr->tri);
break;
default:
assert(!"bad kind to DuplicateNode()");
lExpr = fExpr;
break;
}
} else {
lExpr = NULL;
}
return lExpr;
} // DuplicateNode
/*
* DupExpr() - Duplicate an expression tree.
*
*/
expr *DupExpr(expr *fExpr)
{
return PreApplyToNodes(DuplicateNode, fExpr, NULL, 0);
} // DupExpr
/*
* DuplicateStatement() - Duplicate a statement.
*
*/
stmt *DuplicateStatement(stmt *fStmt, void *arg1, int arg2)
{
stmt *lStmt;
if (fStmt) {
switch (fStmt->commonst.kind) {
case EXPR_STMT:
lStmt = (stmt *) NewExprStmt(&fStmt->commonst.loc, fStmt->exprst.exp);
break;
case IF_STMT:
lStmt = (stmt *) NewIfStmt(&fStmt->commonst.loc, fStmt->ifst.cond,
fStmt->ifst.thenstmt, fStmt->ifst.elsestmt);
break;
case WHILE_STMT:
case DO_STMT:
lStmt = (stmt *) NewWhileStmt(&fStmt->commonst.loc, fStmt->whilest.kind,
fStmt->whilest.cond, fStmt->whilest.body);
break;
case FOR_STMT:
lStmt = (stmt *) NewForStmt(&fStmt->commonst.loc, fStmt->forst.init,
fStmt->forst.cond, fStmt->forst.step, fStmt->forst.body);
break;
case BLOCK_STMT:
lStmt = (stmt *) NewBlockStmt(&fStmt->commonst.loc, fStmt->blockst.body);
break;
case RETURN_STMT:
lStmt = (stmt *) NewReturnStmt(&fStmt->commonst.loc, NULL, fStmt->exprst.exp);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -