PIPS
array.c File Reference
#include <stdlib.h>
#include "genC.h"
#include "newgen_include.h"
+ Include dependency graph for array.c:

Go to the source code of this file.

Data Structures

struct  _gen_array_chunk_t
 

Macros

#define GEN_ARRAY_SIZE_INCREMENT   (50)
 

Functions

gen_array_t gen_array_make (size_t size)
 declarations... More...
 
static void gen_array_resize (gen_array_t a, int min)
 
void gen_array_free (gen_array_t a)
 
void gen_array_full_free (gen_array_t a)
 
void gen_array_addto (gen_array_t a, size_t i, void *what)
 
void gen_array_remove (gen_array_t a, size_t i)
 
void gen_array_append (gen_array_t a, void *what)
 
void gen_array_dupaddto (gen_array_t a, size_t i, void *what)
 
void gen_array_dupappend (gen_array_t a, void *what)
 
void ** gen_array_pointer (const gen_array_t a)
 Observers... More...
 
size_t gen_array_nitems (const gen_array_t a)
 
size_t gen_array_size (const gen_array_t a)
 
void * gen_array_item (const gen_array_t a, size_t i)
 
static int gen_array_cmp (const void *a1, const void *a2)
 Sort: assumes that the items are the first ones. More...
 
void gen_array_sort_with_cmp (gen_array_t a, int(*cmp)(const void *, const void *))
 
void gen_array_sort (gen_array_t a)
 
gen_array_t gen_array_from_list (list ls)
 
list list_from_gen_array (gen_array_t a)
 
string string_array_join (gen_array_t array, string separator)
 Join a string array with a string separator. More...
 

Macro Definition Documentation

◆ GEN_ARRAY_SIZE_INCREMENT

#define GEN_ARRAY_SIZE_INCREMENT   (50)

Definition at line 31 of file array.c.

Function Documentation

◆ gen_array_addto()

void gen_array_addto ( gen_array_t  a,
size_t  i,
void *  what 
)

0<=i &&

Definition at line 87 of file array.c.

88 {
89  if (i>=a->size) gen_array_resize(a,i+1);
90  message_assert("valid index", /* 0<=i && */ i < a->size);
91  if (a->array[i]!=(void *)NULL) a->nitems--;
92  a->array[i] = what;
93  if (a->array[i]!=(void *)NULL) a->nitems++;
94 }
static void gen_array_resize(gen_array_t a, int min)
Definition: array.c:56
#define message_assert(msg, ex)
Definition: newgen_assert.h:47
void ** array
Definition: array.c:36
size_t size
Definition: array.c:34

References _gen_array_chunk_t::array, gen_array_resize(), message_assert, _gen_array_chunk_t::nitems, and _gen_array_chunk_t::size.

Referenced by allocate_task_to_cluster(), atomize_or_associate_for_level(), bottom_level(), cancel_schedule(), DSC(), eov_add_entity_to_eliminate(), gen_array_append(), gen_array_dupaddto(), group_expr_by_level(), initialization(), initialization_clusters(), list_to_array(), move_task_to_cluster(), parse_instrumented_file(), priorities(), schedule_failsafe(), t_level(), topological_sort(), and zeroing_multiple_edges().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_array_append()

void gen_array_append ( gen_array_t  a,
void *  what 
)

Definition at line 105 of file array.c.

106 {
107  gen_array_addto(a, a->nitems, what);
108 }
void gen_array_addto(gen_array_t a, size_t i, void *what)
Definition: array.c:87

References gen_array_addto(), and _gen_array_chunk_t::nitems.

Referenced by add_a_file(), capply(), create(), gen_array_dupappend(), get_main(), gpips_parse_arguments(), pips_parse_arguments(), store_call_context(), wpips_parse_arguments(), xml_dim_string(), xml_loop_from_loop(), and xml_loop_from_sequence().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_array_cmp()

static int gen_array_cmp ( const void *  a1,
const void *  a2 
)
static

Sort: assumes that the items are the first ones.

Definition at line 152 of file array.c.

153 {
154  return strcmp(* (char **) a1, * (char **) a2);
155 }

Referenced by gen_array_sort().

+ Here is the caller graph for this function:

◆ gen_array_dupaddto()

void gen_array_dupaddto ( gen_array_t  a,
size_t  i,
void *  what 
)

Definition at line 111 of file array.c.

112 {
113  gen_array_addto(a, i, strdup(what));
114 }
char * strdup()

References gen_array_addto(), and strdup().

Referenced by get_help_topic(), get_help_topics(), mchoose_ok_notify(), and safe_list_files_in_directory().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_array_dupappend()

void gen_array_dupappend ( gen_array_t  a,
void *  what 
)

Definition at line 117 of file array.c.

118 {
119  gen_array_append(a, strdup(what));
120 }
void gen_array_append(gen_array_t a, void *what)
Definition: array.c:105

References gen_array_append(), and strdup().

Referenced by db_get_module_list_initial_order(), db_get_module_or_function_list(), gen_array_from_list(), and get_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_array_free()

◆ gen_array_from_list()

gen_array_t gen_array_from_list ( list  ls)
Parameters
lsof string

Definition at line 170 of file array.c.

171 {
173  MAP(STRING, s, gen_array_dupappend(a, s), ls);
174  return a;
175 }
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
void gen_array_dupappend(gen_array_t a, void *what)
Definition: array.c:117
#define STRING(x)
Definition: genC.h:87
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226

References gen_array_dupappend(), gen_array_make(), MAP, and STRING.

Referenced by get_callees(), get_callers(), and get_stubs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_array_full_free()

◆ gen_array_item()

void* gen_array_item ( const gen_array_t  a,
size_t  i 
)

0<=i &&

Definition at line 143 of file array.c.

144 {
145  message_assert("valid index", /* 0<=i && */ i < a->size);
146  return a->array[i];
147 }

References _gen_array_chunk_t::array, and message_assert.

Referenced by allocate_task_to_cluster(), atomize_or_associate_for_level(), BDSC(), bootstrap(), bottom_level(), callgraph(), cancel_schedule(), continue_create_workspace_notify(), create_workspace(), critical_path_length(), display_help(), DSC(), DSRW(), end_idle_clusters(), end_select_module_callback(), end_select_module_notify(), eov_get_replaced_enity(), epips_select_module(), full_graph_of_calls(), gen_array_index(), generate_a_directory_menu(), generate_a_menu_with_HPF_output_files(), generate_module_menu(), generate_workspace_menu(), generic_program_pointer_values(), get_main_entity_name(), get_module_names(), group_expr_by_level(), hierarchical_schedule(), hierarchical_schedule_step(), info(), initialization_clusters(), max_start_time_cluster(), mchoose(), MCW(), min_start_time_cluster(), move_task_to_cluster(), open_module_if_unique(), open_or_create_workspace(), open_workspace_notify(), parse_instrumented_file(), pips_get_workspace_list(), print_sdg_task(), print_SDGs(), priorities(), process_file_list(), program_points_to(), program_precondition(), ready_node(), remove_module_entity(), schedule_failsafe(), schoose(), select_task_with_highest_priority(), send_the_names_of_the_available_modules_to_emacs(), step_compile_generated_module(), step_install(), t_level(), tlevel_decrease(), topological_sort(), tp_some_info(), update_list_from_array(), update_parallel_task(), update_priority_values(), workspace_language(), xml_array_in_task(), xml_Boxes(), xml_Call(), xml_Chain_Graph(), xml_loop_from_sequence(), xml_Task(), xml_task(), xml_tasks_with_motif(), and zeroing_multiple_edges().

◆ gen_array_make()

gen_array_t gen_array_make ( size_t  size)

declarations...

default size

number of items stored

Definition at line 40 of file array.c.

41 {
42  gen_array_t a;
43  size_t i;
44  if (size<=0) size= GEN_ARRAY_SIZE_INCREMENT; /* default size */
45  a = (gen_array_t) malloc(sizeof(struct _gen_array_chunk_t));
46  message_assert("array ok", a);
47  a->size = size;
48  a->nitems = 0; /* number of items stored */
49  a->array = (void**) malloc(size*sizeof(void*));
50  message_assert("malloc ok", a->array);
51  for (i=0; i<size; i++) a->array[i] = (void*) NULL;
52  return a;
53 }
#define GEN_ARRAY_SIZE_INCREMENT
Definition: array.c:31
void * malloc(YYSIZE_T)
struct _gen_array_chunk_t * gen_array_t
Definition: newgen_array.h:24

References _gen_array_chunk_t::array, GEN_ARRAY_SIZE_INCREMENT, malloc(), message_assert, _gen_array_chunk_t::nitems, and _gen_array_chunk_t::size.

Referenced by add_a_file(), capply(), continue_create_workspace_notify(), create(), db_get_module_list(), db_get_module_list_initial_order(), db_get_module_or_function_list(), display_help(), dsc_code_parallelization(), eov_add_entity_to_eliminate(), gen_array_from_list(), generate_a_directory_menu(), generate_a_menu_with_HPF_output_files(), generate_workspace_menu(), get_main(), gpips_parse_arguments(), group_expr_by_level(), hbdsc_parallelization(), initialization(), mchoose_ok_notify(), open_or_create_workspace(), open_workspace_notify(), parse_instrumented_file(), pips_parse_arguments(), prettyprint_dependence_graph(), prettyprint_dependence_graph_view(), print_xml_code_with_explicit_motif(), schedule_failsafe(), sequence_dependence_graph(), sort_list_of_strings(), start_delete_workspace_notify(), topological_sort(), wpips_parse_arguments(), xml_Boxes(), xml_Chain_Graph(), xml_loop_from_sequence(), xml_Task(), xml_tasks(), xml_tasks_with_motif(), and zeroing_multiple_edges().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_array_nitems()

◆ gen_array_pointer()

void** gen_array_pointer ( const gen_array_t  a)

Observers...

Definition at line 125 of file array.c.

126 {
127  return a->array;
128 }

References _gen_array_chunk_t::array.

Referenced by prettyprint_dependence_graph(), prettyprint_dependence_graph_view(), and xml_Chain_Graph().

+ Here is the caller graph for this function:

◆ gen_array_remove()

void gen_array_remove ( gen_array_t  a,
size_t  i 
)

0<=i &&

Definition at line 97 of file array.c.

98 {
99  message_assert("valid index", /* 0<=i && */ i < a->size);
100  if (a->array[i]!=(void *)NULL) a->nitems--;
101  a->array[i] = (void *)NULL;
102 }

References _gen_array_chunk_t::array, message_assert, and _gen_array_chunk_t::nitems.

◆ gen_array_resize()

static void gen_array_resize ( gen_array_t  a,
int  min 
)
static

int nsize = a->size+GEN_ARRAY_SIZE_INCREMENT, i;

Definition at line 56 of file array.c.

57 {
59  size_t nsize = ((min%N)==0)?min:((int)(min/N) +1)*N;
60  size_t i;
61  /* int nsize = a->size+GEN_ARRAY_SIZE_INCREMENT, i;*/
62  a->array = (void**) realloc(a->array, nsize*sizeof(void*));
63  message_assert("realloc ok", a->array);
64  for (i=a->size; i<nsize; i++)
65  a->array[i] = (void*) NULL;
66  a->size = nsize;
67 }
void const char const char const int
#define min(a, b)

References _gen_array_chunk_t::array, GEN_ARRAY_SIZE_INCREMENT, int, message_assert, min, and _gen_array_chunk_t::size.

Referenced by gen_array_addto().

+ Here is the caller graph for this function:

◆ gen_array_size()

size_t gen_array_size ( const gen_array_t  a)

Definition at line 137 of file array.c.

138 {
139  return a->size;
140 }

References _gen_array_chunk_t::size.

Referenced by t_level().

+ Here is the caller graph for this function:

◆ gen_array_sort()

void gen_array_sort ( gen_array_t  a)

Definition at line 164 of file array.c.

165 {
167 }
void gen_array_sort_with_cmp(gen_array_t a, int(*cmp)(const void *, const void *))
Definition: array.c:158
static int gen_array_cmp(const void *a1, const void *a2)
Sort: assumes that the items are the first ones.
Definition: array.c:152

References gen_array_cmp(), and gen_array_sort_with_cmp().

Referenced by db_get_module_or_function_list(), safe_list_files_in_directory(), and sort_list_of_strings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gen_array_sort_with_cmp()

void gen_array_sort_with_cmp ( gen_array_t  a,
int(*)(const void *, const void *)  cmp 
)

Definition at line 158 of file array.c.

159 {
160  qsort(a->array, a->nitems, sizeof(void *), cmp);
161 }

References _gen_array_chunk_t::array, and _gen_array_chunk_t::nitems.

Referenced by gen_array_sort().

+ Here is the caller graph for this function:

◆ list_from_gen_array()

list list_from_gen_array ( gen_array_t  a)

Definition at line 178 of file array.c.

179 {
180  list ls = NIL;
181  GEN_ARRAY_FOREACH(string, s, a)
182  ls = CONS(string, strdup(s), ls);
183  return ls;
184 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define GEN_ARRAY_FOREACH(type, s, array)
Definition: newgen_array.h:50
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CONS, GEN_ARRAY_FOREACH, NIL, and strdup().

+ Here is the call graph for this function:

◆ string_array_join()

string string_array_join ( gen_array_t  array,
string  separator 
)

Join a string array with a string separator.

Parameters
arrayis the string array
separatoris the string separator
Returns
a string in a concatenate buffer, so it needs to be strdup()ed quickly if it is expected to last some time in the caller...

It is similar to the join() string method in Python. Using the function with ["foo", "bar", "daurade"] and "," should return the string "foo,bar,daurade".

Definition at line 198 of file array.c.

199 {
200  string join = "";
201  bool first_iteration = true;
202 
203  GEN_ARRAY_FOREACH(string, s, array)
204  {
205  if (! first_iteration)
206  join = concatenate(join, separator, NULL);
207  else
208  first_iteration = false;
209  join = concatenate(join, s, NULL);
210  }
211 
212  return join;
213 }
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
static entity array

References array, concatenate(), and GEN_ARRAY_FOREACH.

Referenced by get_callees_of(), get_callers_of(), info(), pyps_get_stubs(), and safe_concurrent_apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: