mojoshader_compiler.c
changeset 1111 7530b37979b8
parent 1060 4cdf5a3ceb03
child 1145 07f69ab909ec
equal deleted inserted replaced
1110:91a6af79b5e4 1111:7530b37979b8
  2323 } // datatype_elems
  2323 } // datatype_elems
  2324 
  2324 
  2325 static const MOJOSHADER_astDataType *datatype_base(Context *ctx, const MOJOSHADER_astDataType *dt)
  2325 static const MOJOSHADER_astDataType *datatype_base(Context *ctx, const MOJOSHADER_astDataType *dt)
  2326 {
  2326 {
  2327     dt = reduce_datatype(ctx, dt);
  2327     dt = reduce_datatype(ctx, dt);
       
  2328     if (dt == NULL)
       
  2329         return dt;
       
  2330 
  2328     switch (dt->type)
  2331     switch (dt->type)
  2329     {
  2332     {
  2330         case MOJOSHADER_AST_DATATYPE_VECTOR:
  2333         case MOJOSHADER_AST_DATATYPE_VECTOR:
  2331             dt = dt->vector.base;
  2334             dt = dt->vector.base;
  2332             break;
  2335             break;
  4598 static MOJOSHADER_irExpression *new_ir_binop(Context *ctx,
  4601 static MOJOSHADER_irExpression *new_ir_binop(Context *ctx,
  4599                                        const MOJOSHADER_irBinOpType op,
  4602                                        const MOJOSHADER_irBinOpType op,
  4600                                        MOJOSHADER_irExpression *left,
  4603                                        MOJOSHADER_irExpression *left,
  4601                                        MOJOSHADER_irExpression *right)
  4604                                        MOJOSHADER_irExpression *right)
  4602 {
  4605 {
       
  4606     if ((!left) || (!right)) return NULL;
  4603     NEW_IR_EXPR(retval, MOJOSHADER_irBinOp, MOJOSHADER_IR_BINOP, left->info.type, left->info.elements);
  4607     NEW_IR_EXPR(retval, MOJOSHADER_irBinOp, MOJOSHADER_IR_BINOP, left->info.type, left->info.elements);
  4604     assert(left->info.type == right->info.type);
  4608     assert(left->info.type == right->info.type);
  4605     assert(left->info.elements == right->info.elements);
  4609     assert(left->info.elements == right->info.elements);
  4606     retval->op = op;
  4610     retval->op = op;
  4607     retval->left = left;
  4611     retval->left = left;
  4611 
  4615 
  4612 static MOJOSHADER_irExpression *new_ir_eseq(Context *ctx,
  4616 static MOJOSHADER_irExpression *new_ir_eseq(Context *ctx,
  4613                                       MOJOSHADER_irStatement *stmt,
  4617                                       MOJOSHADER_irStatement *stmt,
  4614                                       MOJOSHADER_irExpression *expr)
  4618                                       MOJOSHADER_irExpression *expr)
  4615 {
  4619 {
       
  4620     if (!expr) return NULL;
  4616     NEW_IR_EXPR(retval, MOJOSHADER_irESeq, MOJOSHADER_IR_ESEQ, expr->info.type, expr->info.elements);
  4621     NEW_IR_EXPR(retval, MOJOSHADER_irESeq, MOJOSHADER_IR_ESEQ, expr->info.type, expr->info.elements);
  4617     retval->stmt = stmt;
  4622     retval->stmt = stmt;
  4618     retval->expr = expr;
  4623     retval->expr = expr;
  4619     return (MOJOSHADER_irExpression *) retval;
  4624     return (MOJOSHADER_irExpression *) retval;
  4620 } // new_ir_eseq
  4625 } // new_ir_eseq
  4777                                       MOJOSHADER_irExpression *dst,
  4782                                       MOJOSHADER_irExpression *dst,
  4778                                       MOJOSHADER_irExpression *src,
  4783                                       MOJOSHADER_irExpression *src,
  4779                                       const int writemask)
  4784                                       const int writemask)
  4780 {
  4785 {
  4781     NEW_IR_NODE(retval, MOJOSHADER_irMove, MOJOSHADER_IR_MOVE);
  4786     NEW_IR_NODE(retval, MOJOSHADER_irMove, MOJOSHADER_IR_MOVE);
  4782     assert(dst->info.type == src->info.type);
  4787     assert(dst && src && (dst->info.type == src->info.type));
  4783     assert(dst->info.elements == src->info.elements);
  4788     assert(dst && src && (dst->info.elements == src->info.elements));
  4784     retval->dst = dst;
  4789     retval->dst = dst;
  4785     retval->src = src;
  4790     retval->src = src;
  4786     retval->writemask = writemask;
  4791     retval->writemask = writemask;
  4787     return (MOJOSHADER_irStatement *) retval;
  4792     return (MOJOSHADER_irStatement *) retval;
  4788 } // new_ir_move
  4793 } // new_ir_move
  4830     const int t = generate_ir_label(ctx);
  4835     const int t = generate_ir_label(ctx);
  4831     const int f = generate_ir_label(ctx);
  4836     const int f = generate_ir_label(ctx);
  4832     const int join = generate_ir_label(ctx);
  4837     const int join = generate_ir_label(ctx);
  4833     const int tmp = generate_ir_temp(ctx);
  4838     const int tmp = generate_ir_temp(ctx);
  4834 
  4839 
  4835     assert(tval->info.type == fval->info.type);
  4840     assert(tval && fval && (tval->info.type == fval->info.type));
  4836     assert(tval->info.elements == fval->info.elements);
  4841     assert(tval && fval && (tval->info.elements == fval->info.elements));
  4837 
  4842 
  4838     const MOJOSHADER_astDataTypeType dt = tval->info.type;
  4843     const MOJOSHADER_astDataTypeType dt = tval->info.type;
  4839     const int elements = tval->info.elements;
  4844     const int elements = tval->info.elements;
  4840 
  4845 
  4841     return new_ir_eseq(ctx,
  4846     return new_ir_eseq(ctx,
  5317     const MOJOSHADER_astDataType *dt = reduce_datatype(ctx, ast->datatype);
  5322     const MOJOSHADER_astDataType *dt = reduce_datatype(ctx, ast->datatype);
  5318     const MOJOSHADER_astDataTypeType type = datatype_base(ctx, dt)->type;
  5323     const MOJOSHADER_astDataTypeType type = datatype_base(ctx, dt)->type;
  5319     const int elems = datatype_elems(ctx, dt);
  5324     const int elems = datatype_elems(ctx, dt);
  5320     MOJOSHADER_irExpression *expr = build_ir_expr(ctx, ast->identifier);
  5325     MOJOSHADER_irExpression *expr = build_ir_expr(ctx, ast->identifier);
  5321     MOJOSHADER_irExpression *finalexpr = expr;
  5326     MOJOSHADER_irExpression *finalexpr = expr;
       
  5327 
       
  5328     if (expr == NULL)
       
  5329         return NULL;
  5322 
  5330 
  5323     assert(!ast->isswizzle);
  5331     assert(!ast->isswizzle);
  5324 
  5332 
  5325     while (finalexpr->ir.type == MOJOSHADER_IR_ESEQ)
  5333     while (finalexpr->ir.type == MOJOSHADER_IR_ESEQ)
  5326         finalexpr = finalexpr->eseq.expr;
  5334         finalexpr = finalexpr->eseq.expr;