fixed some bugs
[libfirm] / ir / be / ia32 / ia32_new_nodes.c
1 /**
2  * This file implements the creation of the achitecture specific firm opcodes
3  * and the coresponding node constructors for the $arch assembler irg.
4  * @author Christian Wuerdig
5  * $Id$
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #ifdef _WIN32
13 #include <malloc.h>
14 #else
15 #include <alloca.h>
16 #endif
17
18 #include <stdlib.h>
19
20 #include "irprog_t.h"
21 #include "irgraph_t.h"
22 #include "irnode_t.h"
23 #include "irmode_t.h"
24 #include "ircons_t.h"
25 #include "iropt_t.h"
26 #include "irop.h"
27 #include "firm_common_t.h"
28 #include "irvrfy_t.h"
29 #include "irprintf.h"
30
31 #include "../bearch.h"
32
33 #include "ia32_nodes_attr.h"
34 #include "ia32_new_nodes.h"
35 #include "gen_ia32_regalloc_if.h"
36
37 #ifdef obstack_chunk_alloc
38 # undef obstack_chunk_alloc
39 # define obstack_chunk_alloc xmalloc
40 #else
41 # define obstack_chunk_alloc xmalloc
42 # define obstack_chunk_free free
43 #endif
44
45 /***********************************************************************************
46  *      _                                   _       _             __
47  *     | |                                 (_)     | |           / _|
48  *   __| |_   _ _ __ ___  _ __   ___ _ __   _ _ __ | |_ ___ _ __| |_ __ _  ___ ___
49  *  / _` | | | | '_ ` _ \| '_ \ / _ \ '__| | | '_ \| __/ _ \ '__|  _/ _` |/ __/ _ \
50  * | (_| | |_| | | | | | | |_) |  __/ |    | | | | | ||  __/ |  | || (_| | (_|  __/
51  *  \__,_|\__,_|_| |_| |_| .__/ \___|_|    |_|_| |_|\__\___|_|  |_| \__,_|\___\___|
52  *                       | |
53  *                       |_|
54  ***********************************************************************************/
55
56 /**
57  * Prints a tarval to file F.
58  * @param F         output file
59  * @param tv        tarval
60  * @param brackets  1 == print square brackets around tarval
61  */
62 static void fprintf_tv(FILE *F, tarval *tv, int brackets) {
63         char buf[1024];
64         tarval_snprintf(buf, sizeof(buf), tv);
65
66         if (brackets)
67                 fprintf(F, "[%s]", buf);
68         else
69                 fprintf(F, "%s", buf);
70 }
71
72 /**
73  * Returns the name of a SymConst.
74  * @param symc  the SymConst
75  * @return name of the SymConst
76  */
77 const char *get_sc_name(ir_node *symc) {
78         if (get_irn_opcode(symc) != iro_SymConst)
79                 return "NONE";
80
81         switch (get_SymConst_kind(symc)) {
82                 case symconst_addr_name:
83                         return get_id_str(get_SymConst_name(symc));
84
85                 case symconst_addr_ent:
86                         return get_entity_ld_name(get_SymConst_entity(symc));
87
88                 default:
89                         assert(0 && "Unsupported SymConst");
90         }
91
92         return NULL;
93 }
94
95 /**
96  * Returns a string containing the names of all registers within the limited bitset
97  */
98 static char *get_limited_regs(const arch_register_req_t *req, char *buf, int max) {
99         bitset_t *bs   = bitset_alloca(req->cls->n_regs);
100         char     *p    = buf;
101         int       size = 0;
102         int       i, cnt;
103
104         req->limited(NULL, bs);
105
106         for (i = 0; i < req->cls->n_regs; i++) {
107                 if (bitset_is_set(bs, i)) {
108                         cnt = snprintf(p, max - size, " %s", req->cls->regs[i].name);
109                         if (cnt < 0) {
110                                 fprintf(stderr, "dumper problem, exiting\n");
111                                 exit(1);
112                         }
113
114                         p    += cnt;
115                         size += cnt;
116
117                         if (size >= max)
118                                 break;
119                 }
120         }
121
122         return buf;
123 }
124
125 /**
126  * Dumps the register requirements for either in or out.
127  */
128 static void dump_reg_req(FILE *F, ir_node *n, const ia32_register_req_t **reqs, int inout) {
129         char *dir = inout ? "out" : "in";
130         int   max = inout ? get_ia32_n_res(n) : get_irn_arity(n);
131         char *buf = alloca(1024);
132         int   i;
133
134         memset(buf, 0, 1024);
135
136         if (reqs) {
137                 for (i = 0; i < max; i++) {
138                         fprintf(F, "%sreq #%d =", dir, i);
139
140                         if (reqs[i]->req.type == arch_register_req_type_none) {
141                                 fprintf(F, " n/a");
142                         }
143
144                         if (reqs[i]->req.type & arch_register_req_type_normal) {
145                                 fprintf(F, " %s", reqs[i]->req.cls->name);
146                         }
147
148                         if (reqs[i]->req.type & arch_register_req_type_limited) {
149                                 fprintf(F, " %s", get_limited_regs(&reqs[i]->req, buf, 1024));
150                         }
151
152                         if (reqs[i]->req.type & arch_register_req_type_should_be_same) {
153                                 ir_fprintf(F, " same as %+F", get_irn_n(n, reqs[i]->same_pos));
154                         }
155
156                         if (reqs[i]->req.type & arch_register_req_type_should_be_different) {
157                                 ir_fprintf(F, " different from %+F", get_irn_n(n, reqs[i]->different_pos));
158                         }
159
160                         fprintf(F, "\n");
161                 }
162
163                 fprintf(F, "\n");
164         }
165         else {
166                 fprintf(F, "%sreq = N/A\n", dir);
167         }
168 }
169
170 /**
171  * Dumper interface for dumping ia32 nodes in vcg.
172  * @param n        the node to dump
173  * @param F        the output file
174  * @param reason   indicates which kind of information should be dumped
175  * @return 0 on success or != 0 on failure
176  */
177 static int dump_node_ia32(ir_node *n, FILE *F, dump_reason_t reason) {
178         ir_mode     *mode = NULL;
179         int          bad  = 0;
180         int          i;
181         ia32_attr_t *attr;
182         const ia32_register_req_t **reqs;
183         const arch_register_t     **slots;
184
185         switch (reason) {
186                 case dump_node_opcode_txt:
187                         fprintf(F, "%s", get_irn_opname(n));
188                         break;
189
190                 case dump_node_mode_txt:
191                         mode = get_irn_mode(n);
192
193                         if (mode == mode_BB || mode == mode_ANY || mode == mode_BAD || mode == mode_T) {
194                                 mode = NULL;
195                         }
196                         else if (is_ia32_Load(n)) {
197                                 mode = get_irn_mode(get_irn_n(n, 0));
198                         }
199                         else if (is_ia32_Store(n)) {
200                                 mode = get_irn_mode(get_irn_n(n, 2));
201                         }
202
203                         if (mode) {
204                                 fprintf(F, "[%s]", get_mode_name(mode));
205                         }
206                         break;
207
208                 case dump_node_nodeattr_txt:
209                         if (is_ia32_Call(n)) {
210                                 fprintf(F, "&%s ", get_ia32_sc(n));
211                         }
212                         else if (get_ia32_cnst(n)) {
213                                 char *pref = "";
214
215                                 if (get_ia32_sc(n)) {
216                                         pref = "SymC ";
217                                 }
218
219                                 fprintf(F, "[%s%s]", pref, get_ia32_cnst(n));
220                         }
221
222                         if (is_ia32_AddrModeS(n) || is_ia32_AddrModeD(n)) {
223                                 fprintf(F, "[AM] ");
224                         }
225
226                         break;
227
228                 case dump_node_info_txt:
229                         attr = get_ia32_attr(n);
230                         fprintf(F, "=== IA32 attr begin ===\n");
231
232                         /* dump IN requirements */
233                         if (get_irn_arity(n) > 0) {
234                                 reqs = get_ia32_in_req_all(n);
235                                 dump_reg_req(F, n, reqs, 0);
236                         }
237
238                         /* dump OUT requirements */
239                         if (attr->n_res > 0) {
240                                 reqs = get_ia32_out_req_all(n);
241                                 dump_reg_req(F, n, reqs, 1);
242                         }
243
244                         /* dump assigned registers */
245                         slots = get_ia32_slots(n);
246                         if (slots && attr->n_res > 0) {
247                                 for (i = 0; i < attr->n_res; i++) {
248                                         if (slots[i]) {
249                                                 fprintf(F, "reg #%d = %s\n", i, slots[i]->name);
250                                         }
251                                         else {
252                                                 fprintf(F, "reg #%d = n/a\n", i);
253                                         }
254                                 }
255                         }
256                         fprintf(F, "\n");
257
258                         /* dump op type */
259                         fprintf(F, "op = ");
260                         switch (attr->tp) {
261                                 case ia32_Normal:
262                                         fprintf(F, "Normal");
263                                         break;
264                                 case ia32_Const:
265                                         fprintf(F, "Const");
266                                         break;
267                                 case ia32_SymConst:
268                                         fprintf(F, "SymConst");
269                                         break;
270                                 case ia32_AddrModeD:
271                                         fprintf(F, "AM Dest (Load+Store)");
272                                         break;
273                                 case ia32_AddrModeS:
274                                         fprintf(F, "AM Source (Load)");
275                                         break;
276                         }
277                         fprintf(F, "\n");
278
279
280                         /* dump supported am */
281                         fprintf(F, "AM support = ");
282                         switch (attr->am_support) {
283                                 case ia32_am_None:
284                                         fprintf(F, "none");
285                                         break;
286                                 case ia32_am_Source:
287                                         fprintf(F, "source only (Load)");
288                                         break;
289                                 case ia32_am_Dest:
290                                         fprintf(F, "dest only (Load+Store)");
291                                         break;
292                                 case ia32_am_Full:
293                                         fprintf(F, "full");
294                                         break;
295                         }
296                         fprintf(F, "\n");
297
298                         /* dump AM offset */
299                         fprintf(F, "AM offset = ");
300                         if (attr->am_offs) {
301                                 fprintf(F, "%s", get_ia32_am_offs(n));
302                         }
303                         else {
304                                 fprintf(F, "n/a");
305                         }
306                         fprintf(F, "\n");
307
308                         /* dump AM scale */
309                         fprintf(F, "AM scale = %d\n", get_ia32_am_scale(n));
310
311                         /* dump pn code */
312                         fprintf(F, "pn_code = %d\n", get_ia32_pncode(n));
313
314                         /* dump n_res */
315                         fprintf(F, "n_res = %d\n", get_ia32_n_res(n));
316
317                         /* dump flags */
318                         fprintf(F, "flags =");
319                         if (attr->flags & arch_irn_flags_dont_spill) {
320                                 fprintf(F, " unspillable");
321                         }
322                         if (attr->flags & arch_irn_flags_rematerializable) {
323                                 fprintf(F, " remat");
324                         }
325                         if (attr->flags & arch_irn_flags_ignore) {
326                                 fprintf(F, " ignore");
327                         }
328                         fprintf(F, "\n");
329
330                         fprintf(F, "=== IA32 attr end ===\n");
331                         /* end of: case dump_node_info_txt */
332                         break;
333         }
334
335         return bad;
336 }
337
338
339
340 /***************************************************************************************************
341  *        _   _                   _       __        _                    _   _               _
342  *       | | | |                 | |     / /       | |                  | | | |             | |
343  *   __ _| |_| |_ _ __   ___  ___| |_   / /_ _  ___| |_   _ __ ___   ___| |_| |__   ___   __| |___
344  *  / _` | __| __| '__| / __|/ _ \ __| / / _` |/ _ \ __| | '_ ` _ \ / _ \ __| '_ \ / _ \ / _` / __|
345  * | (_| | |_| |_| |    \__ \  __/ |_ / / (_| |  __/ |_  | | | | | |  __/ |_| | | | (_) | (_| \__ \
346  *  \__,_|\__|\__|_|    |___/\___|\__/_/ \__, |\___|\__| |_| |_| |_|\___|\__|_| |_|\___/ \__,_|___/
347  *                                        __/ |
348  *                                       |___/
349  ***************************************************************************************************/
350
351  static char *copy_str(char *dst, const char *src) {
352          dst = xcalloc(1, strlen(src) + 1);
353          strncpy(dst, src, strlen(src) + 1);
354          return dst;
355  }
356
357  static char *set_cnst_from_tv(char *cnst, tarval *tv) {
358          if (cnst) {
359                  free(cnst);
360          }
361
362          cnst = xcalloc(1, 64);
363          assert(tarval_snprintf(cnst, 63, tv));
364          return cnst;
365  }
366
367 /**
368  * Wraps get_irn_generic_attr() as it takes no const ir_node, so we need to do a cast.
369  * Firm was made by people hating const :-(
370  */
371 ia32_attr_t *get_ia32_attr(const ir_node *node) {
372         assert(is_ia32_irn(node) && "need ia32 node to get ia32 attributes");
373         return (ia32_attr_t *)get_irn_generic_attr((ir_node *)node);
374 }
375
376 /**
377  * Gets the type of an ia32 node.
378  */
379 ia32_op_type_t get_ia32_op_type(const ir_node *node) {
380         ia32_attr_t *attr = get_ia32_attr(node);
381         return attr->tp;
382 }
383
384 /**
385  * Sets the type of an ia32 node.
386  */
387 void set_ia32_op_type(ir_node *node, ia32_op_type_t tp) {
388         ia32_attr_t *attr = get_ia32_attr(node);
389         attr->tp          = tp;
390 }
391
392 /**
393  * Gets the supported addrmode of an ia32 node
394  */
395 ia32_am_type_t get_ia32_am_support(const ir_node *node) {
396         ia32_attr_t *attr = get_ia32_attr(node);
397         return attr->am_support;
398 }
399
400 /**
401  * Sets the supported addrmode of an ia32 node
402  */
403 void set_ia32_am_support(ir_node *node, ia32_am_type_t am_tp) {
404         ia32_attr_t *attr = get_ia32_attr(node);
405         attr->am_support  = am_tp;
406 }
407
408 /**
409  * Gets the addrmode flavour of an ia32 node
410  */
411 ia32_am_flavour_t get_ia32_am_flavour(const ir_node *node) {
412         ia32_attr_t *attr = get_ia32_attr(node);
413         return attr->am_flavour;
414 }
415
416 /**
417  * Sets the addrmode flavour of an ia32 node
418  */
419 void set_ia32_am_flavour(ir_node *node, ia32_am_flavour_t am_flavour) {
420         ia32_attr_t *attr = get_ia32_attr(node);
421         attr->am_support  = am_flavour;
422 }
423
424 /**
425  * Joins all offsets to one string with adds.
426  */
427 char *get_ia32_am_offs(const ir_node *node) {
428         ia32_attr_t *attr = get_ia32_attr(node);
429         char        *res  = NULL;
430         int          size;
431
432         if (! attr->am_offs) {
433                 return NULL;
434         }
435
436         size = obstack_object_size(attr->am_offs);
437     if (size > 0) {
438                 res = xcalloc(1, size + 1);
439                 memcpy(res, obstack_base(attr->am_offs), size);
440     }
441
442         res[size] = '\0';
443         return res;
444 }
445
446 /**
447  * Add an offset for addrmode.
448  */
449 static void extend_ia32_am_offs(ir_node *node, char *offset, char op) {
450         ia32_attr_t *attr = get_ia32_attr(node);
451
452         if (!attr->am_offs) {
453                 /* obstack is not initialized */
454                 attr->am_offs = xcalloc(1, sizeof(*(attr->am_offs)));
455                 obstack_init(attr->am_offs);
456         }
457         else {
458                 /* obstack is initialized -> there is already one offset */
459                 /* present -> connect the offsets with an add            */
460                 obstack_printf(attr->am_offs, " %c ", op);
461         }
462
463         obstack_printf(attr->am_offs, "%s", offset);
464 }
465
466 /**
467  * Add an offset for addrmode.
468  */
469 void add_ia32_am_offs(ir_node *node, char *offset) {
470         extend_ia32_am_offs(node, offset, '+');
471 }
472
473 /**
474  * Sub an offset for addrmode.
475  */
476 void sub_ia32_am_offs(ir_node *node, char *offset) {
477         extend_ia32_am_offs(node, offset, '-');
478 }
479
480 /**
481  * Gets the addr mode const.
482  */
483 int get_ia32_am_scale(const ir_node *node) {
484         ia32_attr_t *attr = get_ia32_attr(node);
485         return attr->am_scale;
486 }
487
488 /**
489  * Sets the index register scale for addrmode.
490  */
491 void set_ia32_am_scale(ir_node *node, int scale) {
492         ia32_attr_t *attr = get_ia32_attr(node);
493         attr->am_scale    = scale;
494 }
495
496 /**
497  * Return the tarval of an immediate operation or NULL in case of SymConst
498  */
499 tarval *get_ia32_Immop_tarval(const ir_node *node) {
500         ia32_attr_t *attr = get_ia32_attr(node);
501     return attr->tv;
502 }
503
504 /**
505  * Sets the attributes of an immediate operation to the specified tarval
506  */
507 void set_ia32_Immop_tarval(ir_node *node, tarval *tv) {
508         ia32_attr_t *attr = get_ia32_attr(node);
509         attr->tv          = tv;
510         attr->cnst        = set_cnst_from_tv(attr->cnst, attr->tv);
511 }
512
513 /**
514  * Return the sc attribute.
515  */
516 char *get_ia32_sc(const ir_node *node) {
517   ia32_attr_t *attr = get_ia32_attr(node);
518   return attr->sc;
519 }
520
521 /**
522  * Sets the sc attribute.
523  */
524 void set_ia32_sc(ir_node *node, char *sc) {
525   ia32_attr_t *attr = get_ia32_attr(node);
526   attr->sc          = copy_str(attr->sc, sc);
527
528   if (attr->cnst) {
529           free(attr->cnst);
530   }
531   attr->cnst = attr->sc;
532 }
533
534 /**
535  * Gets the string representation of the internal const (tv or symconst)
536  */
537 char *get_ia32_cnst(ir_node *node) {
538   ia32_attr_t *attr = get_ia32_attr(node);
539   return attr->cnst;
540 }
541
542 /**
543  * Returns the argument register requirements of an ia32 node.
544  */
545 const ia32_register_req_t **get_ia32_in_req_all(const ir_node *node) {
546         ia32_attr_t *attr = get_ia32_attr(node);
547         return attr->in_req;
548 }
549
550 /**
551  * Returns the result register requirements of an ia32 node.
552  */
553 const ia32_register_req_t **get_ia32_out_req_all(const ir_node *node) {
554         ia32_attr_t *attr = get_ia32_attr(node);
555         return attr->out_req;
556 }
557
558 /**
559  * Returns the argument register requirement at position pos of an ia32 node.
560  */
561 const ia32_register_req_t *get_ia32_in_req(const ir_node *node, int pos) {
562         ia32_attr_t *attr = get_ia32_attr(node);
563         return attr->in_req[pos];
564 }
565
566 /**
567  * Returns the result register requirement at position pos of an ia32 node.
568  */
569 const ia32_register_req_t *get_ia32_out_req(const ir_node *node, int pos) {
570         ia32_attr_t *attr = get_ia32_attr(node);
571         return attr->out_req[pos];
572 }
573
574 /**
575  * Sets the OUT register requirements at position pos.
576  */
577 void set_ia32_req_out(ir_node *node, const ia32_register_req_t *req, int pos) {
578         ia32_attr_t *attr  = get_ia32_attr(node);
579         attr->out_req[pos] = req;
580 }
581
582 /**
583  * Sets the IN register requirements at position pos.
584  */
585 void set_ia32_req_in(ir_node *node, const ia32_register_req_t *req, int pos) {
586         ia32_attr_t *attr = get_ia32_attr(node);
587         attr->in_req[pos] = req;
588 }
589
590 /**
591  * Returns the register flag of an ia32 node.
592  */
593 arch_irn_flags_t get_ia32_flags(const ir_node *node) {
594         ia32_attr_t *attr = get_ia32_attr(node);
595         return attr->flags;
596 }
597
598 /**
599  * Sets the register flag of an ia32 node.
600  */
601 void set_ia32_flags(const ir_node *node, arch_irn_flags_t flags) {
602         ia32_attr_t *attr = get_ia32_attr(node);
603         attr->flags       = flags;
604 }
605
606 /**
607  * Returns the result register slots of an ia32 node.
608  */
609 const arch_register_t **get_ia32_slots(const ir_node *node) {
610         ia32_attr_t *attr = get_ia32_attr(node);
611         return attr->slots;
612 }
613
614 /**
615  * Returns the name of the OUT register at position pos.
616  */
617 const char *get_ia32_out_reg_name(const ir_node *node, int pos) {
618         ia32_attr_t *attr = get_ia32_attr(node);
619
620         assert(is_ia32_irn(node) && "Not an ia32 node.");
621         assert(pos < attr->n_res && "Invalid OUT position.");
622         assert(attr->slots[pos]  && "No register assigned");
623
624         return arch_register_get_name(attr->slots[pos]);
625 }
626
627 /**
628  * Returns the index of the OUT register at position pos within its register class.
629  */
630 int get_ia32_out_regnr(const ir_node *node, int pos) {
631         ia32_attr_t *attr = get_ia32_attr(node);
632
633         assert(is_ia32_irn(node) && "Not an ia32 node.");
634         assert(pos < attr->n_res && "Invalid OUT position.");
635         assert(attr->slots[pos]  && "No register assigned");
636
637         return arch_register_get_index(attr->slots[pos]);
638 }
639
640 /**
641  * Returns the OUT register at position pos.
642  */
643 const arch_register_t *get_ia32_out_reg(const ir_node *node, int pos) {
644         ia32_attr_t *attr = get_ia32_attr(node);
645
646         assert(is_ia32_irn(node) && "Not an ia32 node.");
647         assert(pos < attr->n_res && "Invalid OUT position.");
648         assert(attr->slots[pos]  && "No register assigned");
649
650         return attr->slots[pos];
651 }
652
653 /**
654  * Sets the number of results.
655  */
656 void set_ia32_n_res(ir_node *node, int n_res) {
657         ia32_attr_t *attr = get_ia32_attr(node);
658         attr->n_res       = n_res;
659 }
660
661 /**
662  * Returns the number of results.
663  */
664 int get_ia32_n_res(const ir_node *node) {
665         ia32_attr_t *attr = get_ia32_attr(node);
666         return attr->n_res;
667 }
668
669 /**
670  * Returns the flavour of an ia32 node,
671  */
672 ia32_op_flavour_t get_ia32_flavour(const ir_node *node) {
673         ia32_attr_t *attr = get_ia32_attr(node);
674         return attr->op_flav;
675 }
676
677 /**
678  * Sets the flavour of an ia32 node to flavour_Div/Mod/DivMod/Mul/Mulh.
679  */
680 void set_ia32_flavour(ir_node *node, ia32_op_flavour_t op_flav) {
681         ia32_attr_t *attr = get_ia32_attr(node);
682         attr->op_flav     = op_flav;
683 }
684
685 /**
686  * Returns the projnum code.
687  */
688 long get_ia32_pncode(const ir_node *node) {
689         ia32_attr_t *attr = get_ia32_attr(node);
690         return attr->pn_code;
691 }
692
693 /**
694  * Sets the projnum code
695  */
696 void set_ia32_pncode(ir_node *node, long code) {
697         ia32_attr_t *attr = get_ia32_attr(node);
698         attr->pn_code     = code;
699 }
700
701
702 /******************************************************************************************************
703  *                      _       _         _   _           __                  _   _
704  *                     (_)     | |       | | | |         / _|                | | (_)
705  *  ___ _ __   ___  ___ _  __ _| |   __ _| |_| |_ _ __  | |_ _   _ _ __   ___| |_ _  ___  _ __    ___
706  * / __| '_ \ / _ \/ __| |/ _` | |  / _` | __| __| '__| |  _| | | | '_ \ / __| __| |/ _ \| '_ \  / __|
707  * \__ \ |_) |  __/ (__| | (_| | | | (_| | |_| |_| |    | | | |_| | | | | (__| |_| | (_) | | | | \__ \
708  * |___/ .__/ \___|\___|_|\__,_|_|  \__,_|\__|\__|_|    |_|  \__,_|_| |_|\___|\__|_|\___/|_| |_| |___/
709  *     | |
710  *     |_|
711  ******************************************************************************************************/
712
713 /**
714  * Gets the type of an ia32_Const.
715  */
716 unsigned get_ia32_Const_type(ir_node *node) {
717         ia32_attr_t *attr = get_ia32_attr(node);
718
719         assert((is_ia32_Const(node) || is_ia32_fConst(node)) && "Need ia32_Const to get type");
720
721         return attr->tp;
722 }
723
724 /**
725  * Sets the type of an ia32_Const.
726  */
727 void set_ia32_Const_type(ir_node *node, int type) {
728         ia32_attr_t *attr = get_ia32_attr(node);
729
730         assert((is_ia32_Const(node) || is_ia32_fConst(node)) && "Need ia32_Const to set type");
731         assert((type == ia32_Const || type == ia32_SymConst) && "Unsupported ia32_Const type");
732
733         attr->tp = type;
734 }
735
736 /**
737  * Copy the attributes from an ia32_Const to an Immop (Add_i, Sub_i, ...) node
738  */
739 void set_ia32_Immop_attr(ir_node *node, ir_node *cnst) {
740         ia32_attr_t *na = get_ia32_attr(node);
741         ia32_attr_t *ca = get_ia32_attr(cnst);
742
743         assert((is_ia32_Const(cnst) || is_ia32_fConst(cnst)) && "Need ia32_Const to set Immop attr");
744
745         na->tv = ca->tv;
746
747         if (ca->sc) {
748                 na->sc = copy_str(na->sc, ca->sc);
749         }
750         else {
751                 na->cnst = set_cnst_from_tv(na->cnst, na->tv);
752                 na->sc   = NULL;
753         }
754 }
755
756 /**
757  * Copy the attributes from a Const to an ia32_Const
758  */
759 void set_ia32_Const_attr(ir_node *ia32_cnst, ir_node *cnst) {
760         ia32_attr_t *attr = get_ia32_attr(ia32_cnst);
761
762         assert((is_ia32_Const(ia32_cnst) || is_ia32_fConst(ia32_cnst)) && "Need ia32_Const to set Const attr");
763
764         switch (get_irn_opcode(cnst)) {
765                 case iro_Const:
766                         attr->tp   = ia32_Const;
767                         attr->tv   = get_Const_tarval(cnst);
768                         attr->cnst = set_cnst_from_tv(attr->cnst, attr->tv);
769                         break;
770                 case iro_SymConst:
771                         attr->tp   = ia32_SymConst;
772                         attr->tv   = NULL;
773                         attr->sc   = copy_str(attr->sc, get_sc_name(cnst));
774                         attr->cnst = attr->sc;
775                         break;
776                 case iro_Unknown:
777                         assert(0 && "Unknown Const NYI");
778                         break;
779                 default:
780                         assert(0 && "Cannot create ia32_Const for this opcode");
781         }
782 }
783
784 /**
785  * Sets the AddrMode(S|D) attribute
786  */
787 void set_ia32_AddrMode(ir_node *node, char direction) {
788         ia32_attr_t *attr = get_ia32_attr(node);
789
790         switch (direction) {
791                 case 'D':
792                         attr->tp = ia32_AddrModeD;
793                         break;
794                 case 'S':
795                         attr->tp = ia32_AddrModeS;
796                         break;
797                 default:
798                         assert(0 && "wrong AM type");
799         }
800 }
801
802 /**
803  * Returns whether or not the node is an AddrModeS node.
804  */
805 int is_ia32_AddrModeS(ir_node *node) {
806         ia32_attr_t *attr = get_ia32_attr(node);
807         return (attr->tp == ia32_AddrModeS);
808 }
809
810 /**
811  * Returns whether or not the node is an AddrModeD node.
812  */
813 int is_ia32_AddrModeD(ir_node *node) {
814         ia32_attr_t *attr = get_ia32_attr(node);
815         return (attr->tp == ia32_AddrModeD);
816 }
817
818
819
820 /***************************************************************************************
821  *                  _                            _                   _
822  *                 | |                          | |                 | |
823  *  _ __   ___   __| | ___    ___ ___  _ __  ___| |_ _ __ _   _  ___| |_ ___  _ __ ___
824  * | '_ \ / _ \ / _` |/ _ \  / __/ _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__/ __|
825  * | | | | (_) | (_| |  __/ | (_| (_) | | | \__ \ |_| |  | |_| | (__| || (_) | |  \__ \
826  * |_| |_|\___/ \__,_|\___|  \___\___/|_| |_|___/\__|_|   \__,_|\___|\__\___/|_|  |___/
827  *
828  ***************************************************************************************/
829
830 /* Include the generated constructor functions */
831 #include "gen_ia32_new_nodes.c.inl"