Project

General

Profile

Revision 80f93e0a

View differences:

include/arrow.c
2 2
#include <assert.h>
3 3
#include "arrow.h"
4 4

  
5
struct _arrow_mem *_arrow_alloc() {
5
struct _arrow_mem * _arrow_alloc () {
6 6
  struct _arrow_mem *_alloc;
7 7
  _alloc = (struct _arrow_mem *) malloc(sizeof(struct _arrow_mem *));
8 8
  assert (_alloc);
9 9
  return _alloc;
10 10
}
11

  
12
void _arrow_dealloc (struct _arrow_mem * _alloc) {
13
  free (_alloc);
14
}
include/arrow.h
6 6

  
7 7
extern struct _arrow_mem *_arrow_alloc ();
8 8

  
9
extern void _arrow_dealloc (struct _arrow_mem *);
10

  
9 11
#define _arrow_DECLARE(attr, inst)\
10 12
  attr struct _arrow_mem inst;
11 13
  
src/backends/C/c_backend_common.ml
94 94
let pp_machine_memtype_name fmt id = fprintf fmt "struct %s_mem" id
95 95
let pp_machine_regtype_name fmt id = fprintf fmt "struct %s_reg" id
96 96
let pp_machine_alloc_name fmt id = fprintf fmt "%s_alloc" id
97
let pp_machine_dealloc_name fmt id = fprintf fmt "%s_dealloc" id
97 98
let pp_machine_static_declare_name fmt id = fprintf fmt "%s_DECLARE" id
98 99
let pp_machine_static_link_name fmt id = fprintf fmt "%s_LINK" id
99 100
let pp_machine_static_alloc_name fmt id = fprintf fmt "%s_ALLOC" id
......
348 349
    pp_machine_alloc_name name
349 350
    (Utils.fprintf_list ~sep:",@ " pp_c_decl_input_var) static
350 351

  
352
let print_dealloc_prototype fmt name =
353
  fprintf fmt "void %a (%a * _alloc)"
354
    pp_machine_dealloc_name name
355
    pp_machine_memtype_name name
356
    
351 357
let print_reset_prototype self fmt (name, static) =
352 358
  fprintf fmt "void %a (@[<v>%a%t%a *%s@])"
353 359
    pp_machine_reset_name name
......
422 428
let print_extern_alloc_prototypes fmt (Dep (_,_, header,_)) =
423 429
  List.iter (fun decl -> match decl.top_decl_desc with
424 430
  | ImportedNode ind when not ind.nodei_stateless ->
425
    let static = List.filter (fun v -> v.var_dec_const) ind.nodei_inputs
426
    in fprintf fmt "extern %a;@." print_alloc_prototype (ind.nodei_id, static)
431
    let static = List.filter (fun v -> v.var_dec_const) ind.nodei_inputs in
432
    begin
433
      fprintf fmt "extern %a;@.@." print_alloc_prototype (ind.nodei_id, static);
434
      fprintf fmt "extern %a;@.@." print_dealloc_prototype ind.nodei_id;
435
    end
427 436
  | _                -> ()
428 437
  ) header
429 438

  
src/backends/C/c_backend_header.ml
177 177
	  begin 
178 178
            (* Dynamic allocation *)
179 179
	    fprintf fmt "extern %a;@.@."
180
	      print_alloc_prototype (m.mname.node_id, m.mstatic)
180
	      print_alloc_prototype (m.mname.node_id, m.mstatic);
181

  
182
	    fprintf fmt "extern %a;@.@."
183
	      print_dealloc_prototype m.mname.node_id;
181 184
	  end;
182 185
	let self = mk_self m in
183 186
	fprintf fmt "extern %a;@.@."
......
219 222
      else
220 223
	begin 
221 224
          (* Dynamic allocation *)
222
	  fprintf fmt "extern %a;@."
223
		  print_alloc_prototype (m.mname.node_id, m.mstatic)
225
	  fprintf fmt "extern %a;@.@."
226
	    print_alloc_prototype (m.mname.node_id, m.mstatic);
227

  
228
	  fprintf fmt "extern %a;@.@."
229
	    print_dealloc_prototype m.mname.node_id
224 230
	end
225 231
    end
226 232

  
src/backends/C/c_backend_src.ml
392 392
    pp_machine_alloc_name (node_name m)
393 393
    (Utils.fprintf_list ~sep:", " Dimension.pp_dimension) static
394 394

  
395
let print_dealloc_instance fmt (i, (m, _)) =
396
  fprintf fmt "%a (_alloc->%s);@,"
397
    pp_machine_dealloc_name (node_name m)
398
    i
399

  
395 400
let print_alloc_const fmt m =
396 401
  let const_locals = List.filter (fun vdecl -> vdecl.var_dec_const) m.mstep.step_locals in
397 402
  fprintf fmt "%a%t"
......
409 414
    (pp_c_type "") base_type
410 415
    vdecl.var_id
411 416

  
417
let print_dealloc_array fmt vdecl =
418
  fprintf fmt "free (_alloc->_reg.%s);@,"
419
    vdecl.var_id
420

  
412 421
let print_alloc_code fmt m =
413 422
  let array_mem = List.filter (fun v -> Types.is_array_type v.var_type) m.mmemory in
414 423
  fprintf fmt "%a *_alloc;@,_alloc = (%a *) malloc(sizeof(%a));@,assert(_alloc);@,%a%areturn _alloc;"
......
418 427
    (Utils.fprintf_list ~sep:"" print_alloc_array) array_mem
419 428
    (Utils.fprintf_list ~sep:"" print_alloc_instance) m.minstances
420 429

  
430
let print_dealloc_code fmt m =
431
  let array_mem = List.filter (fun v -> Types.is_array_type v.var_type) m.mmemory in
432
  fprintf fmt "%a%afree (_alloc);@,return;"
433
    (Utils.fprintf_list ~sep:"" print_dealloc_array) array_mem
434
    (Utils.fprintf_list ~sep:"" print_dealloc_instance) m.minstances
435

  
421 436
let print_stateless_init_code dependencies fmt m self =
422 437
  let minit = List.map (function MReset i -> i | _ -> assert false) m.minit in
423 438
  let array_mems = List.filter (fun v -> Types.is_array_type v.var_type) m.mmemory in
......
615 630
    end
616 631
  else
617 632
    begin
618
      (* Alloc function, only if non static mode *)
633
      (* Alloc functions, only if non static mode *)
619 634
      if (not !Options.static_mem) then  
620 635
	begin
621 636
	  fprintf fmt "@[<v 2>%a {@,%a%a@]@,}@.@."
622 637
	    print_alloc_prototype (m.mname.node_id, m.mstatic)
623 638
	    print_alloc_const m
624 639
	    print_alloc_code m;
640

  
641
	  fprintf fmt "@[<v 2>%a {@,%a%a@]@,}@.@."
642
	    print_dealloc_prototype m.mname.node_id
643
	    print_alloc_const m
644
	    print_dealloc_code m;
625 645
	end;
626 646
      let self = mk_self m in
627 647
      (* Reset function *)
......
682 702
      fprintf source_fmt "@]@.";
683 703
      fprintf source_fmt "/* Node allocation function prototypes */@.";
684 704
      fprintf source_fmt "@[<v>";
685
      List.iter (fun m -> fprintf source_fmt "%a;@." print_alloc_prototype (m.mname.node_id, m.mstatic)) machines;
705
      List.iter
706
	(fun m -> fprintf source_fmt "%a;@.@.%a;@.@."
707
	  print_alloc_prototype (m.mname.node_id, m.mstatic)
708
	  print_dealloc_prototype m.mname.node_id
709
	)
710
	machines;
686 711
      fprintf source_fmt "@]@.";
687 712
    end;
688 713

  

Also available in: Unified diff