X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=testprograms%2Farray-heap_example.c;h=c22621229cf1db30e5062c33ec4506de8b1b70f8;hb=8a828c064c24643f30d68b67808a62e8a7ae1d80;hp=9c07f244c9789906dc61b393c8a7de1497518a93;hpb=6ed168c29789db8edf25c87f2da9164c49a5512c;p=libfirm diff --git a/testprograms/array-heap_example.c b/testprograms/array-heap_example.c index 9c07f244c..c22621229 100644 --- a/testprograms/array-heap_example.c +++ b/testprograms/array-heap_example.c @@ -1,9 +1,9 @@ /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe -** All rights reserved. -** -** Authors: Goetz Lindenmaier -** -** testprogram. +* All rights reserved. +* +* Authors: Goetz Lindenmaier +* +* testprogram. */ # include @@ -13,33 +13,33 @@ # include "irdump.h" # include "firm.h" -/** This example describes a possible representation of heap allocated -*** variables of imperative programs. -*** It constructs the IR for the following program: -*** -*** -*** main(): int -*** int *a[10]; -*** -*** a = malloc(sizeof(a[10])); -*** return (a[3]); -*** end; -*** -*** The array is placed on the heap. The pointer to the array that -*** is a local variable is represented as a dataflow edge. -*** There are two ways to model allocation to the heap in programs with -*** explicit memory allocation: -*** 1. Model the calls to malloc and free as simple procedure (of compiler -*** known procedures returning a pointer. This is the simpler way of -*** generating FIRM, but restricts the information that can be deduced -*** for the call. -*** 2. Insert an Alloc node. A later pass can lower this to the compiler -*** known function. This makes the allocation explicit in FIRM, supporting -*** optimization. -*** A problem is modeling free. There is no free node in FIRM. Is this -*** a necessary extension? -*** This example shows the second alternative, where the size of the array -*** is explicitly computed. +/** +* variables of imperative programs. +* It constructs the IR for the following program: +* +* +* main(): int +* int *a[10]; +* +* a = malloc(sizeof(a[10])); +* return (a[3]); +* end; +* +* The array is placed on the heap. The pointer to the array that +* is a local variable is represented as a dataflow edge. +* There are two ways to model allocation to the heap in programs with +* explicit memory allocation: +* 1. Model the calls to malloc and free as simple procedure (of compiler +* known procedures returning a pointer. This is the simpler way of +* generating FIRM, but restricts the information that can be deduced +* for the call. +* 2. Insert an Alloc node. A later pass can lower this to the compiler +* known function. This makes the allocation explicit in FIRM, supporting +* optimization. +* A problem is modeling free. There is no free node in FIRM. Is this +* a necessary extension? +* This example shows the second alternative, where the size of the array +* is explicitly computed. **/ #define OPTIMIZE_NODE 0 @@ -82,9 +82,9 @@ main(void) /* first build procedure main */ owner = get_glob_type(); - proc_main = new_type_method(id_from_str("main", 4), 0, 1); + proc_main = new_type_method(id_from_str("ARRAY-HEAP_EXAMPLE_main", 23), 0, 1); set_method_res_type(proc_main, 0, (type *)prim_t_int); - proc_main_e = new_entity ((type*)owner, id_from_str ("main", 4), (type *)proc_main); + proc_main_e = new_entity ((type*)owner, id_from_str ("ARRAY-HEAP_EXAMPLE_main", 23), (type *)proc_main); main_irg = new_ir_graph (proc_main_e, 4); /* make type information for the array and set the bounds */