);
}
break;
+ case slang_oper_equal:
+ return new_node(IR_SEQUAL,
+ slang_assemble_operation(A, &oper->children[0]),
+ slang_assemble_operation(A, &oper->children[1]));
+ case slang_oper_notequal:
+ return new_node(IR_SNEQUAL,
+ slang_assemble_operation(A, &oper->children[0]),
+ slang_assemble_operation(A, &oper->children[1]));
+ case slang_oper_greater:
+ return new_node(IR_SGT,
+ slang_assemble_operation(A, &oper->children[0]),
+ slang_assemble_operation(A, &oper->children[1]));
case slang_oper_less:
- return new_node(IR_LESS,
+ /* child[0] < child[1] ----> child[1] > child[0] */
+ return new_node(IR_SGT,
+ slang_assemble_operation(A, &oper->children[1]),
+ slang_assemble_operation(A, &oper->children[0]));
+ case slang_oper_greaterequal:
+ return new_node(IR_SGE,
slang_assemble_operation(A, &oper->children[0]),
slang_assemble_operation(A, &oper->children[1]));
+ case slang_oper_lessequal:
+ /* child[0] <= child[1] ----> child[1] >= child[0] */
+ return new_node(IR_SGE,
+ slang_assemble_operation(A, &oper->children[1]),
+ slang_assemble_operation(A, &oper->children[0]));
case slang_oper_add:
{
slang_ir_node *n;
{ IR_CJUMP, "IR_CJUMP", 0, 0, 0 },
{ IR_CALL, "IR_CALL", 0, 0, 0 },
{ IR_MOVE, "IR_MOVE", 0, 0, 1 },
- { IR_LESS, "IR_LESS", 0, 1, 2 },
{ IR_NOT, "IR_NOT", 0, 1, 1 },
{ IR_VAR, "IR_VAR", 0, 0, 0 },
{ IR_VAR_DECL, "IR_VAR_DECL", 0, 0, 0 },
static struct prog_instruction *
-gen(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog);
+emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog);
/**
* Generate code for a simple binary-op instruction.
*/
static struct prog_instruction *
-gen_binop(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog)
+emit_binop(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog)
{
struct prog_instruction *inst;
const slang_ir_info *info = slang_find_ir_info(n->Opcode);
assert(info);
- gen(gc, n->Children[0], prog);
- gen(gc, n->Children[1], prog);
+ assert(info->InstOpcode != OPCODE_NOP);
+
+ emit(gc, n->Children[0], prog);
+ emit(gc, n->Children[1], prog);
inst = new_instruction(prog, info->InstOpcode);
/* alloc temp storage for the result: */
if (!n->Store || n->Store->File == PROGRAM_UNDEFINED) {
static struct prog_instruction *
-gen_unop(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog)
+emit_unop(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog)
{
struct prog_instruction *inst;
const slang_ir_info *info = slang_find_ir_info(n->Opcode);
assert(info->NumParams == 1);
- gen(gc, n->Children[0], prog);
+ emit(gc, n->Children[0], prog);
inst = new_instruction(prog, info->InstOpcode);
/*slang_resolve_storage(gc, n, prog);*/
static struct prog_instruction *
-gen(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog)
+emit(slang_gen_context *gc, slang_ir_node *n, struct gl_program *prog)
{
struct prog_instruction *inst;
if (!n)
case IR_SEQ:
assert(n->Children[0]);
assert(n->Children[1]);
- gen(gc, n->Children[0], prog);
- inst = gen(gc, n->Children[1], prog);
+ emit(gc, n->Children[0], prog);
+ inst = emit(gc, n->Children[1], prog);
n->Store = n->Children[1]->Store;
return inst;
break;
case IR_MOVE:
/* rhs */
assert(n->Children[1]);
- inst = gen(gc, n->Children[1], prog);
+ inst = emit(gc, n->Children[1], prog);
/* lhs */
- gen(gc, n->Children[0], prog);
+ emit(gc, n->Children[0], prog);
#if 1
if (inst && is_temporary(gc, n->Children[1]->Store)) {
case IR_POW:
case IR_EXP:
case IR_EXP2:
- return gen_binop(gc, n, prog);
+ return emit_binop(gc, n, prog);
break;
case IR_RSQ:
case IR_RCP:
case IR_ABS:
case IR_SIN:
case IR_COS:
- return gen_unop(gc, n, prog);
+ return emit_unop(gc, n, prog);
break;
case IR_LABEL:
/*printf("LAB: %s\n", n->Target);*/
n->Store = alloc_constant(n->Value, 4, prog); /*XXX fix size */
break;
default:
- printf("gen: ?\n");
+ printf("emit: ?\n");
abort();
}
return NULL;
printf("************ Begin generate code\n");
- gen(gc, n, prog);
+ (void) emit(gc, n, prog);
{
struct prog_instruction *inst;