mojoshader_compiler.c
changeset 1016 9c082b107efe
parent 1015 87c39e720f36
child 1028 74e7ee46ac93
equal deleted inserted replaced
1015:87c39e720f36 1016:9c082b107efe
  5817 
  5817 
  5818         default: assert(0 && "unexpected IR node"); break;
  5818         default: assert(0 && "unexpected IR node"); break;
  5819     } // switch
  5819     } // switch
  5820 } // print_ir
  5820 } // print_ir
  5821 
  5821 
  5822 static void delete_ir(Context *ctx, void *_ir)
       
  5823 {
       
  5824     MOJOSHADER_irNode *ir = (MOJOSHADER_irNode *) _ir;
       
  5825     if (ir == NULL)
       
  5826         return;
       
  5827 
       
  5828     switch (ir->ir.type)
       
  5829     {
       
  5830         case MOJOSHADER_IR_JUMP:
       
  5831         case MOJOSHADER_IR_LABEL:
       
  5832         case MOJOSHADER_IR_CONSTANT:
       
  5833         case MOJOSHADER_IR_TEMP:
       
  5834         case MOJOSHADER_IR_DISCARD:
       
  5835         case MOJOSHADER_IR_MEMORY:
       
  5836             break;  // nothing extra to free here.
       
  5837 
       
  5838         case MOJOSHADER_IR_BINOP:
       
  5839             delete_ir(ctx, ir->expr.binop.left);
       
  5840             delete_ir(ctx, ir->expr.binop.right);
       
  5841             break;
       
  5842 
       
  5843         case MOJOSHADER_IR_CALL:
       
  5844             delete_ir(ctx, ir->expr.call.args);
       
  5845             break;
       
  5846 
       
  5847         case MOJOSHADER_IR_ESEQ:
       
  5848             delete_ir(ctx, ir->expr.eseq.stmt);
       
  5849             delete_ir(ctx, ir->expr.eseq.expr);
       
  5850             break;
       
  5851 
       
  5852         case MOJOSHADER_IR_ARRAY:
       
  5853             delete_ir(ctx, ir->expr.array.array);
       
  5854             delete_ir(ctx, ir->expr.array.element);
       
  5855             break;
       
  5856 
       
  5857         case MOJOSHADER_IR_MOVE:
       
  5858             delete_ir(ctx, ir->stmt.move.dst);
       
  5859             delete_ir(ctx, ir->stmt.move.src);
       
  5860             break;
       
  5861 
       
  5862         case MOJOSHADER_IR_EXPR_STMT:
       
  5863             delete_ir(ctx, ir->stmt.expr.expr);
       
  5864             break;
       
  5865 
       
  5866         case MOJOSHADER_IR_CJUMP:
       
  5867             delete_ir(ctx, ir->stmt.cjump.left);
       
  5868             delete_ir(ctx, ir->stmt.cjump.right);
       
  5869             break;
       
  5870 
       
  5871         case MOJOSHADER_IR_SEQ:
       
  5872             delete_ir(ctx, ir->stmt.seq.first);
       
  5873             delete_ir(ctx, ir->stmt.seq.next);  // !!! FIXME: don't recurse?
       
  5874             break;
       
  5875 
       
  5876         case MOJOSHADER_IR_EXPRLIST:
       
  5877             delete_ir(ctx, ir->misc.exprlist.expr);
       
  5878             delete_ir(ctx, ir->misc.exprlist.next);  // !!! FIXME: don't recurse?
       
  5879             break;
       
  5880 
       
  5881         case MOJOSHADER_IR_SWIZZLE:
       
  5882             delete_ir(ctx, ir->expr.swizzle.expr);
       
  5883             break;
       
  5884 
       
  5885         case MOJOSHADER_IR_CONSTRUCT:
       
  5886             delete_ir(ctx, ir->expr.construct.args);
       
  5887             break;
       
  5888 
       
  5889         case MOJOSHADER_IR_CONVERT:
       
  5890             delete_ir(ctx, ir->expr.convert.expr);
       
  5891             break;
       
  5892 
       
  5893         default: assert(0 && "unexpected IR node"); break;
       
  5894     } // switch
       
  5895 
       
  5896     Free(ctx, ir);
       
  5897 } // delete_ir
       
  5898 
       
  5899 
       
  5900 static void print_whole_ir(Context *ctx, FILE *io)
  5822 static void print_whole_ir(Context *ctx, FILE *io)
  5901 {
  5823 {
  5902     if (ctx->ir != NULL)
  5824     if (ctx->ir != NULL)
  5903     {
  5825     {
  5904         int i;
  5826         int i;
  5908             print_ir(io, 1, ctx->ir[i]);
  5830             print_ir(io, 1, ctx->ir[i]);
  5909         } // for
  5831         } // for
  5910     } // if
  5832     } // if
  5911 } // print_whole_ir
  5833 } // print_whole_ir
  5912 
  5834 
       
  5835 static void delete_ir(Context *ctx, void *_ir)
       
  5836 {
       
  5837     MOJOSHADER_irNode *ir = (MOJOSHADER_irNode *) _ir;
       
  5838     if (ir == NULL)
       
  5839         return;
       
  5840 
       
  5841     switch (ir->ir.type)
       
  5842     {
       
  5843         case MOJOSHADER_IR_JUMP:
       
  5844         case MOJOSHADER_IR_LABEL:
       
  5845         case MOJOSHADER_IR_CONSTANT:
       
  5846         case MOJOSHADER_IR_TEMP:
       
  5847         case MOJOSHADER_IR_DISCARD:
       
  5848         case MOJOSHADER_IR_MEMORY:
       
  5849             break;  // nothing extra to free here.
       
  5850 
       
  5851         case MOJOSHADER_IR_BINOP:
       
  5852             delete_ir(ctx, ir->expr.binop.left);
       
  5853             delete_ir(ctx, ir->expr.binop.right);
       
  5854             break;
       
  5855 
       
  5856         case MOJOSHADER_IR_CALL:
       
  5857             delete_ir(ctx, ir->expr.call.args);
       
  5858             break;
       
  5859 
       
  5860         case MOJOSHADER_IR_ESEQ:
       
  5861             delete_ir(ctx, ir->expr.eseq.stmt);
       
  5862             delete_ir(ctx, ir->expr.eseq.expr);
       
  5863             break;
       
  5864 
       
  5865         case MOJOSHADER_IR_ARRAY:
       
  5866             delete_ir(ctx, ir->expr.array.array);
       
  5867             delete_ir(ctx, ir->expr.array.element);
       
  5868             break;
       
  5869 
       
  5870         case MOJOSHADER_IR_MOVE:
       
  5871             delete_ir(ctx, ir->stmt.move.dst);
       
  5872             delete_ir(ctx, ir->stmt.move.src);
       
  5873             break;
       
  5874 
       
  5875         case MOJOSHADER_IR_EXPR_STMT:
       
  5876             delete_ir(ctx, ir->stmt.expr.expr);
       
  5877             break;
       
  5878 
       
  5879         case MOJOSHADER_IR_CJUMP:
       
  5880             delete_ir(ctx, ir->stmt.cjump.left);
       
  5881             delete_ir(ctx, ir->stmt.cjump.right);
       
  5882             break;
       
  5883 
       
  5884         case MOJOSHADER_IR_SEQ:
       
  5885             delete_ir(ctx, ir->stmt.seq.first);
       
  5886             delete_ir(ctx, ir->stmt.seq.next);  // !!! FIXME: don't recurse?
       
  5887             break;
       
  5888 
       
  5889         case MOJOSHADER_IR_EXPRLIST:
       
  5890             delete_ir(ctx, ir->misc.exprlist.expr);
       
  5891             delete_ir(ctx, ir->misc.exprlist.next);  // !!! FIXME: don't recurse?
       
  5892             break;
       
  5893 
       
  5894         case MOJOSHADER_IR_SWIZZLE:
       
  5895             delete_ir(ctx, ir->expr.swizzle.expr);
       
  5896             break;
       
  5897 
       
  5898         case MOJOSHADER_IR_CONSTRUCT:
       
  5899             delete_ir(ctx, ir->expr.construct.args);
       
  5900             break;
       
  5901 
       
  5902         case MOJOSHADER_IR_CONVERT:
       
  5903             delete_ir(ctx, ir->expr.convert.expr);
       
  5904             break;
       
  5905 
       
  5906         default: assert(0 && "unexpected IR node"); break;
       
  5907     } // switch
       
  5908 
       
  5909     Free(ctx, ir);
       
  5910 } // delete_ir
  5913 
  5911 
  5914 static void intermediate_representation(Context *ctx)
  5912 static void intermediate_representation(Context *ctx)
  5915 {
  5913 {
  5916     const MOJOSHADER_astCompilationUnit *ast = NULL;
  5914     const MOJOSHADER_astCompilationUnit *ast = NULL;
  5917     const MOJOSHADER_astCompilationUnitFunction *astfn = NULL;
  5915     const MOJOSHADER_astCompilationUnitFunction *astfn = NULL;