⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hal.c

📁 cg编译器
💻 C
📖 第 1 页 / 共 2 页
字号:
        default:
            size = 0;
            break;
        }
    } else {
        size = 0;
    }
    return size;
} // GetSizeof_HAL

/*
 * GetAlignment_HAL() - Return a profile specific alignment for this type.
 *         Used for defining struct member offsets for use by code generator.
 */

static int GetAlignment_HAL(Type *fType)
{
    int category, alignment;

    if (fType) {
        if (Cg->theHAL->IsTexobjBase(GetBase(fType))) {
            alignment = 4;
        } else {
            category = GetCategory(fType);
            switch (category) {
            case TYPE_CATEGORY_SCALAR:
                alignment = 4;
                break;
            case TYPE_CATEGORY_STRUCT:
            case TYPE_CATEGORY_ARRAY:
                alignment = 4;
                break;
            case TYPE_CATEGORY_FUNCTION:
            default:
                alignment = 1;
                break;
            }
        }
    } else {
        alignment = 1;
    }
    return alignment;
} // GetAlignment_HAL

/*
 * CheckDeclarators_HAL() - Check for profile-specific limitations of declarators.
 *
 */

static int CheckDeclarators_HAL(SourceLoc *loc, const dtype *fDtype)
{
    int numdims = 0;
    const Type *lType;

    lType = &fDtype->type;
    while (GetCategory(lType) == TYPE_CATEGORY_ARRAY) {
        if (lType->arr.numels == 0 && numdims > 0) {
            SemanticError(loc, ERROR___LOW_DIM_UNSPECIFIED);
            return 0;
        }
        if (lType->arr.numels > 4 && IsPacked(lType)) {
            SemanticError(loc, ERROR___PACKED_DIM_EXCEEDS_4);
            return 0;
        }
        lType = lType->arr.eltype;
        numdims++;
    }
    if (numdims > 3) {
        SemanticError(loc, ERROR___NUM_DIMS_EXCEEDS_3);
        return 0;
    }
    return 1;
} // CheckDeclarators_HAL

/*
 * CheckDefinition_HAL() - Check for profile-specific statement limitations.
 *
 */

static int CheckDefinition_HAL(SourceLoc *loc, int name, const Type *fType)
{
    return 1;
} // CheckDefinition_HAL

/*
 * CheckStatement_HAL() - Check for profile-specific limitations of statements.
 *
 */

static int CheckStatement_HAL(SourceLoc *loc, stmt *fstmt)
{
    return 1;
} // CheckStatement_HAL

/*
 * CheckInternalFunction_HAL() - Check for profile-specific internally implemented function.
 *
 */

static int CheckInternalFunction_HAL(Symbol *fSymb, int *group)
{
    return 0;
} // CheckInternalFunction_HAL

/*
 * IsValidScalarCast_HAL() - Is it valid to typecast a scalar from fromBase to toBase?.
 *
 */

static int IsValidScalarCast_HAL(int toBase, int fromBase, int Explicit)
{
    int answer;

    switch (toBase) {
    case TYPE_BASE_BOOLEAN:
    case TYPE_BASE_FLOAT:
    case TYPE_BASE_INT:
        switch (fromBase) {
        case TYPE_BASE_CFLOAT:
        case TYPE_BASE_CINT:
        case TYPE_BASE_FLOAT:
        case TYPE_BASE_INT:
            answer = 1;
            break;
        case TYPE_BASE_BOOLEAN:
            answer = (toBase == TYPE_BASE_BOOLEAN) || Explicit;
            break;
        default:
            answer = 0;
            break;
        }
        break;
    case TYPE_BASE_CFLOAT:
    case TYPE_BASE_CINT:
    default:
        answer = 0;
        break;
    }
    return answer;
} // IsValidScalarCast_HAL

/*
 * IsValidOperator_HAL() - Is this operator supported in this profile?  Print an error is not.
 *
 */

static int IsValidOperator_HAL(SourceLoc *loc, int name, int op, int suobp)
{
    switch (op) {
    default:
        return 1;
    }
} // IsValidOperator_HAL

/*
 * IsNumericBase_HAL() - Is fBase a numeric type?
 *
 */

static int IsNumericBase_HAL(int fBase)
{
    int answer;

    switch (fBase) {
    case TYPE_BASE_CFLOAT:
    case TYPE_BASE_CINT:
    case TYPE_BASE_FLOAT:
    case TYPE_BASE_INT:
        answer = 1;
        break;
    default:
        answer = 0;
        break;
    }
    return answer;
} // IsNumericBase_HAL

/*
 * IsIntegralBase_HAL() - Is fBase an integral type?
 *
 */

static int IsIntegralBase_HAL(int fBase)
{
    int answer;

    switch (fBase) {
    case TYPE_BASE_CINT:
    case TYPE_BASE_INT:
        answer = 1;
        break;
    default:
        answer = 0;
        break;
    }
    return answer;
} // IsIntegralBase_HAL

/*
 * IsTexobjBase_HAL() - Is fBase a texture object type?
 *
 */

static int IsTexobjBase_HAL(int fBase)
{
    return 0;
} // IsTexobjBase_HAL

/*
 * IsValidRuntimeBase_HAL() - Are runtime variables with a base of fBase supported?
 *         In other words, can a non-const variable of this base be declared in this profile?
 *
 */

static int IsValidRuntimeBase_HAL(int fBase)
{
    int answer;

    switch (fBase) {
    case TYPE_BASE_FLOAT:
        answer = 1;
        break;
    default:
        answer = 0;
        break;
    }
    return answer;
} // IsIntegralBase_HAL

/*
 * GetBinOpBase_HAL() - Return the base type for this binary operation.
 *
 */

static int GetBinOpBase_HAL(int lop, int lbase, int rbase, int llen, int rlen)
{
    int result;

    switch (lop) {
    case VECTOR_V_OP:
    case MUL_OP:
    case DIV_OP:
    case MOD_OP:
    case ADD_OP:
    case SUB_OP:
    case SHL_OP:
    case SHR_OP:
    case LT_OP:
    case GT_OP:
    case LE_OP:
    case GE_OP:
    case EQ_OP:
    case NE_OP:
    case AND_OP:
    case XOR_OP:
    case OR_OP:
    case COND_OP:
        if (lbase == rbase) {
            result = lbase;
        } else if (lbase == TYPE_BASE_FLOAT || rbase == TYPE_BASE_FLOAT) {
            result = TYPE_BASE_FLOAT;
        } else if (lbase == TYPE_BASE_CFLOAT || rbase == TYPE_BASE_CFLOAT) {
            if (lbase == TYPE_BASE_INT || rbase == TYPE_BASE_INT) {
                result = TYPE_BASE_FLOAT;
            } else {
                result = TYPE_BASE_CFLOAT;
            }
        } else {
            result = TYPE_BASE_INT;
        }
        break;
    default:
        result = TYPE_BASE_NO_TYPE;
        break;
    };
    return result;
} // GetBinOpBase_HAL

/*
 * ConvertConstant()_HAL - Convert a numeric scalar constant from one base type to another.
 *
 */

static int ConvertConstant_HAL(const scalar_constant *fval, int fbase, int tbase, expr **fexpr)
{
    expr *lexpr = NULL;

    switch (fbase) {
    case TYPE_BASE_CFLOAT:
    case TYPE_BASE_FLOAT:
        switch (tbase) {
        case TYPE_BASE_CFLOAT:
        case TYPE_BASE_FLOAT:
            lexpr = (expr *) NewFConstNode(FCONST_OP, fval->f, tbase);
            *fexpr = lexpr;
            break;
        case TYPE_BASE_CINT:
        case TYPE_BASE_INT:
            lexpr = (expr *) NewIConstNode(ICONST_OP, (int) fval->f, tbase);
            *fexpr = lexpr;
            break;
        default:
            return 0;
        }
        break;
    case TYPE_BASE_CINT:
    case TYPE_BASE_INT:
        switch (tbase) {
        case TYPE_BASE_CFLOAT:
        case TYPE_BASE_FLOAT:
            lexpr = (expr *) NewFConstNode(FCONST_OP, (float) fval->i, tbase);
            *fexpr = lexpr;
            break;
        case TYPE_BASE_CINT:
        case TYPE_BASE_INT:
            lexpr = (expr *) NewIConstNode(ICONST_OP, fval->i, tbase);
            *fexpr = lexpr;
            break;
        default:
            return 0;
        }
        break;
    default:
        return 0;
    }
    return 1;
} // ConvertConstant_HAL

/*
 * BindUniformUnbound_HAL() - Bind an unbound variable to a free uniform resource.
 *
 */

static int BindUniformUnbound_HAL(SourceLoc *loc, Symbol *fSymb, Binding *lBind)
{
    return 0;
} // BindUniformUnbound_HAL

/*
 * BindUniformPragma_HAL() - Bind a variable to a uniform resource based on a #pragma bind.
 *
 */

static int BindUniformPragma_HAL(SourceLoc *loc, Symbol *fSymb, Binding *lBind,
                                 const Binding *fBind)
{
    return 0;
} // BindUniformPragma_HAL

/*
 * BindVaryingSemantic_HAL() - Bind a variable to a specific varying semantic.
 *
 */

static int BindVaryingSemantic_HAL(SourceLoc *loc, Symbol *fSymb, int semantic,
                                              Binding *fBind, int IsOutVal)
{
    return 0;
} // BindVaryingSemantic_HAL

/*
 * BindVaryingPragma_HAL() - Bind a variable to a varying resource based on a #pragma bind.
 *
 */

static int BindVaryingPragma_HAL(SourceLoc *loc, Symbol *fSymb, Binding *lBind,
                                 const Binding *fBind, int IsOutVal)
{
    return 0;
} // BindVaryingPragma_HAL

/*
 * BindVaryingUnbound_HAL() - Bind a variable with no binding information to a varying resource.
 *
 */

static int BindVaryingUnbound_HAL(SourceLoc *loc, Symbol *fSymb, int name, int connector,
                                  Binding *fBind, int IsOutVal)
{
    return 0;
} // BindVaryingUnbound_HAL

/*
 * PrintCodeHeader_HAL() - Dummy header output.
 *
 */

static int PrintCodeHeader_HAL(FILE *out)

{
    InternalError(Cg->tokenLoc, ERROR_S_NO_CODE_HEADER, GetAtomString(atable, Cg->theHAL->profileName));
    return 1;
} // PrintCodeHeader_HAL

/*
 * GenerateCode_HAL() - Dummy code generator.
 *
 */

static int GenerateCode_HAL(SourceLoc *loc, Scope *fScope, Symbol *program)
{
    InternalError(Cg->tokenLoc, ERROR_S_NO_CODE_GENERATOR, GetAtomString(atable, Cg->theHAL->profileName));
    return 1;
} // GenerateCode_HAL

///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// End of hal.c ////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -