projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*** empty log message ***
[libfirm]
/
testprograms
/
if_example.c
diff --git
a/testprograms/if_example.c
b/testprograms/if_example.c
index
d3ca040
..
38b799a
100644
(file)
--- a/
testprograms/if_example.c
+++ b/
testprograms/if_example.c
@@
-14,14
+14,12
@@
***
*** Doesn't work for some reason!!!!
***
***
*** Doesn't work for some reason!!!!
***
-*** main() {
-*** int a = 0;
+*** int main(int a) {
*** int b = 2;
*** int b = 2;
-*** if ( a == a ) // a constant condition would be eliminated,
-*** // a realistic condition would no more be a small example
+*** if ( a == b )
*** { a := a - 2; }
***
*** { a := a - 2; }
***
-***
// return a, bla; // das ist hier kein korrekter graph
+***
return a;
*** }
**/
*** }
**/
@@
-31,9
+29,9
@@
main(void)
ir_graph *irg;
type_class *owner;
entity *ent;
ir_graph *irg;
type_class *owner;
entity *ent;
- type_method *proc_main; /* typeinformation for the method main */
+ type_method *proc_main; /* type
information for the method main */
type_primitive *typ;
type_primitive *typ;
- ir_node *x, *r, *t, *f, *a;
+ ir_node *x, *r, *t, *f, *a
, *cmp
;
int a_pos, b_pos;
FILE *outfile;
int a_pos, b_pos;
FILE *outfile;
@@
-43,25
+41,20
@@
main(void)
#define CLASSNAME "IF_EXAMPLE"
#define METHODNAME "main"
#define CLASSNAME "IF_EXAMPLE"
#define METHODNAME "main"
-#define NRARGS
0
-#define NRES
2
+#define NRARGS
1
+#define NRES
1
- owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
- proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)), NRARGS, NRES);
+ owner = get_glob_type();
+ proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
+ NRARGS, NRES);
ent = new_entity ((type *)owner,
id_from_str (METHODNAME, strlen(METHODNAME)),
(type *)proc_main);
ent = new_entity ((type *)owner,
id_from_str (METHODNAME, strlen(METHODNAME)),
(type *)proc_main);
-#define RES_NAME "
res1
"
+#define RES_NAME "
int
"
typ = new_type_primitive(ID_FROM_STR(RES_NAME, strlen(RES_NAME)), mode_i);
typ = new_type_primitive(ID_FROM_STR(RES_NAME, strlen(RES_NAME)), mode_i);
+ set_method_param_type(proc_main, 0, (type*)typ);
set_method_res_type(proc_main, 0, (type*)typ);
set_method_res_type(proc_main, 0, (type*)typ);
-#undef RES_NAME
-
-#define RES_NAME "res2"
- typ = new_type_primitive(ID_FROM_STR(RES_NAME, strlen(RES_NAME)), mode_i);
- set_method_res_type(proc_main, 1, (type*)typ);
-#undef RES_NAME
-
/* Generates start and end blocks and nodes and a first, initial block */
irg = new_ir_graph (ent, 1);
/* Generates start and end blocks and nodes and a first, initial block */
irg = new_ir_graph (ent, 1);
@@
-71,21
+64,20
@@
main(void)
b_pos = 1;
/* Generate the constant */
b_pos = 1;
/* Generate the constant */
- set_value (a_pos, new_Const (mode_i, tarval_from_long (mode_i, 0)));
+ set_value (a_pos, new_Proj (get_irg_args(irg), mode_i, 0));
+ /*set_value (a_pos, new_Const (mode_i, tarval_from_long (mode_i, 0)));*/
set_value (b_pos, new_Const (mode_i, tarval_from_long (mode_i, 2)));
mature_block (irg->current_block);
/* Generate a conditional branch */
set_value (b_pos, new_Const (mode_i, tarval_from_long (mode_i, 2)));
mature_block (irg->current_block);
/* Generate a conditional branch */
- x = new_Cond (new_Proj(new_Cmp(get_value(a_pos, mode_i),
- get_value(a_pos, mode_i)),
- mode_b, Eq));
+ cmp = new_Cmp(get_value(a_pos, mode_i), get_value(b_pos, mode_i));
+ x = new_Cond (new_Proj(cmp, mode_b, Eq));
f = new_Proj (x, mode_X, 0);
t = new_Proj (x, mode_X, 1);
/* generate and fill the then block */
r = new_Block ();
add_in_edge (r, t);
f = new_Proj (x, mode_X, 0);
t = new_Proj (x, mode_X, 1);
/* generate and fill the then block */
r = new_Block ();
add_in_edge (r, t);
- // mature_block (r);
a = new_Sub(get_value(a_pos, mode_i),
new_Const (mode_i, tarval_from_long (mode_i, 2)),
mode_i);
a = new_Sub(get_value(a_pos, mode_i),
new_Const (mode_i, tarval_from_long (mode_i, 2)),
mode_i);
@@
-100,26
+92,27
@@
main(void)
add_in_edge (r, x);
mature_block (r);
{
add_in_edge (r, x);
mature_block (r);
{
- ir_node *in[
3
], *store ;
+ ir_node *in[
1
], *store ;
in[0] = get_value (a_pos, mode_i);
in[0] = get_value (a_pos, mode_i);
- in[1] = a;
- in[2] = get_value (b_pos, mode_i);
store = get_store();
store = get_store();
- x = new_Return (store,
2
, in);
+ x = new_Return (store,
1
, in);
}
/* finalize the end block generated in new_ir_graph() */
add_in_edge (irg->end_block, x);
mature_block (irg->end_block);
}
/* finalize the end block generated in new_ir_graph() */
add_in_edge (irg->end_block, x);
mature_block (irg->end_block);
+ /* verify the graph */
+ irg_vrfy(irg);
+
/* output the vcg file */
printf("\nDone building the graph. Dumping it.\n");
dump_ir_block_graph (irg);
printf("use xvcg to view this graph:\n");
/* output the vcg file */
printf("\nDone building the graph. Dumping it.\n");
dump_ir_block_graph (irg);
printf("use xvcg to view this graph:\n");
- printf("/ben/
trapp/bin/i486
/xvcg GRAPHNAME\n");
+ printf("/ben/
goetz/bin
/xvcg GRAPHNAME\n");
return (0);
}
return (0);
}