Project

General

Profile

Revision 80f93e0a src/backends/C/c_backend_src.ml

View differences:

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