1 #include <libfirm/firm.h>
3 #include "../firm2arch_nodes_attr.h"
7 void transform_node(ir_node *node, void *env) {
8 ir_mode *mode = get_irn_mode(node);
9 opcode code = get_irn_opcode(node);
12 ir_node *asm_op = NULL;
13 ir_node *const_op = NULL;
14 ir_node *expr_op = NULL;
15 opcode code_op1, code_op2;
17 /* TODO: maybe one can transform
18 "Const -- Sub -- Exp" into "Exp -- Minus -- Add -- Const"
20 but I'm not sure about side effects */
22 #define GEN(a) case iro_##a: asm_op = new_ia32_##a(op1, op2, mode); break
23 #define GENI(a) case iro_##a: asm_op = new_ia32_##a##_i(expr_op, mode); break
26 /* commutative arith ops */
32 op1 = get_irn_n(node, 0);
33 op2 = get_irn_n(node, 1);
34 code_op1 = get_irn_opcode(op1);
35 code_op2 = get_irn_opcode(op2);
37 /* determine if one operator is a Const */
38 const_op = code_op1 == iro_Const ? op1 : (code_op2 == iro_Const ? op2 : NULL);
39 expr_op = code_op1 != iro_Const ? op1 : (code_op2 != iro_Const ? op2 : NULL);
43 /* not commutative arith ops: only construct the immediate nodes
44 when the right operand is a Const */
52 op1 = get_irn_n(node, 0);
53 op2 = get_irn_n(node, 1);
54 code_op1 = get_irn_opcode(op1);
55 code_op2 = get_irn_opcode(op2);
57 /* determine if the right operator is a Const */
58 const_op = code_op2 == iro_Const ? op2 : NULL;
62 assert(code_op1 != iro_Const && code_op2 != iro_Const && "Op(Const, Const) not expected!");
63 if ((code_op1 == iro_Const) && (code_op2 == iro_Const)) {
64 printf("Ignoring %s(Const, Const)\n", get_irn_opname(node));
68 if (const_op) { /* one of the operators is a Const */
86 /* make the Const an attribute */
87 asmop_attr *attr = (asmop_attr *)get_irn_generic_attr(const_op);
88 attr->tv = get_Const_tarval(const_op);
90 else { /* both operators need to be computed */
110 /* exchange the old firm node with the new assembler node */
111 exchange(node, asm_op);
114 fprintf(stderr, "Ignoring node: %s\n", get_irn_opname(node));