Project

General

Profile

« Previous | Next » 

Revision 9bdfc99f

Added by Xavier Thirioux over 10 years ago

corrected bug in arrow macros names, added storage attribute for static alloc macros, option -d now creates the destination directory if needed, with current dir as file permissions

View differences:

src/c_backend.ml
36 36
  Format.fprintf fmt "/* @[<v>C code generated by %s@,SVN version number %s@,Code is %s compliant */@,@]@."
37 37
    (Filename.basename Sys.executable_name) Version.number (if !Options.ansi then "ANSI C90" else "C99")
38 38

  
39
(* Generation of a non-clashing name for the self memory variable (for step and reset functions) *)
39 40
let mk_self m =
40 41
  mk_new_name (m.mstep.step_inputs@m.mstep.step_outputs@m.mstep.step_locals@m.mmemory) "self"
41 42

  
43
(* Generation of a non-clashing name for the instance variable of static allocation macro *)
44
let mk_instance m =
45
  mk_new_name (m.mstep.step_inputs@m.mmemory) "inst"
46

  
47
(* Generation of a non-clashing name for the attribute variable of static allocation macro *)
48
let mk_attribute m =
49
  mk_new_name (m.mstep.step_inputs@m.mmemory) "attr"
50

  
42 51
let mk_call_var_decl loc id =
43 52
  { var_id = id;
44 53
    var_dec_type = mktyp Location.dummy_loc Tydec_any;
......
580 589
let pp_static_array_instance fmt m (v, m) =
581 590
 fprintf fmt "%s" (mk_addr_var m v)
582 591
*)
583
let print_static_declare_instance fmt (i, (m, static)) =
584
  fprintf fmt "%a(%a%t%s)"
592
let print_static_declare_instance attr fmt (i, (m, static)) =
593
  fprintf fmt "%a(%s, %a%t%s)"
585 594
    pp_machine_static_declare_name (node_name m)
595
    attr
586 596
    (Utils.fprintf_list ~sep:", " Dimension.pp_dimension) static
587 597
    (Utils.pp_final_char_if_non_empty ", " static)
588 598
    i
589 599

  
590 600
let print_static_declare_macro fmt m =
591 601
  let array_mem = List.filter (fun v -> Types.is_array_type v.var_type) m.mmemory in
592
  fprintf fmt "@[<v 2>#define %a(%a%tinst)\\@,%a inst;\\@,%a%t%a;@,@]"
602
  let inst = mk_instance m in
603
  let attr = mk_attribute m in
604
  fprintf fmt "@[<v 2>#define %a(%s, %a%tinst)\\@,%s %a inst;\\@,%a%t%a;@,@]"
593 605
    pp_machine_static_declare_name m.mname.node_id
606
    attr
594 607
    (Utils.fprintf_list ~sep:", " (pp_c_var_read m)) m.mstatic
595 608
    (Utils.pp_final_char_if_non_empty ", " m.mstatic)
609
    attr
596 610
    pp_machine_memtype_name m.mname.node_id
597 611
    (Utils.fprintf_list ~sep:";\\@," pp_c_decl_local_var) array_mem
598 612
    (Utils.pp_final_char_if_non_empty ";\\@," array_mem)
......
600 614
       (fun fmt (i',m') ->
601 615
	 let path = sprintf "inst ## _%s" i' in
602 616
	 fprintf fmt "%a"
603
	   print_static_declare_instance (path,m')
617
	   (print_static_declare_instance attr) (path,m')
604 618
       )) m.minstances
605 619

  
606 620
      
......
628 642
       )) m.minstances
629 643
      
630 644
let print_static_alloc_macro fmt m =
631
  fprintf fmt "@[<v>@[<v 2>#define %a(%a%tinst)\\@,%a(%a%tinst);\\@,%a(inst);@]@,@]@."
645
  fprintf fmt "@[<v>@[<v 2>#define %a(attr,%a%tinst)\\@,%a(attr,%a%tinst);\\@,%a(inst);@]@,@]@."
632 646
    pp_machine_static_alloc_name m.mname.node_id
633 647
    (Utils.fprintf_list ~sep:", " (pp_c_var_read m)) m.mstatic
634 648
    (Utils.pp_final_char_if_non_empty ", " m.mstatic)
......
798 812
    ) m.mstep.step_outputs;
799 813
  fprintf fmt "@ /* Main memory allocation */@ ";
800 814
  if (!Options.static_mem && !Options.main_node <> "")
801
  then (fprintf fmt "%a(main_mem);@ " pp_machine_static_alloc_name mname)
815
  then (fprintf fmt "%a(static,main_mem);@ " pp_machine_static_alloc_name mname)
802 816
  else (fprintf fmt "%a *main_mem = %a();@ " pp_machine_memtype_name mname pp_machine_alloc_name mname);
803 817
  fprintf fmt "@ /* Initialize the main memory */@ ";
804 818
  fprintf fmt "%a(%s);@ " pp_machine_reset_name mname main_mem;

Also available in: Unified diff