Changeset 640


Ignore:
Timestamp:
Mar 7, 2011, 11:10:57 AM (9 years ago)
Author:
ayache
Message:

Hex output not too long for mcu anymore. Readable output added.

Location:
Deliverables/D2.2/8051/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/ASM/ASMPrinter.ml

    r619 r640  
    44let print_program p =
    55  let code_memory = ASMInterpret.load_code_memory p.ASM.code in
    6   let intel_hex = IntelHex.pack_exported_code_memory 16 65536 code_memory in
     6  let intel_hex = IntelHex.pack_exported_code_memory 16 65535 code_memory in
    77  IntelHex.string_of_intel_hex_format intel_hex
  • Deliverables/D2.2/8051/src/ASM/Pretty.ml

    r627 r640  
    4444    `Label l -> l ^ ":"
    4545  | `Cost l -> l ^ ":"
    46   | `Jmp j -> "Jmp " ^ j
    47   | `Call j -> "Call " ^ j
     46  | `Jmp j -> "ljmp " ^ j
     47  | `Call j -> "lcall " ^ j
    4848  | `WithLabel i -> pp_jump i
    4949  | `Begin_fun -> "\n; Begin function"
     
    9999
    100100let print_program p =
    101   let f s i = Printf.sprintf "%s%s\n" s (pp_instruction i) in
    102   "Org 0\n\n" ^ (List.fold_left f "" p.ASM.pcode) ^ "\nEND\n"
     101  let mem = ASMInterpret.load_code_memory p.ASM.code in
     102  let f (s, pc) _ =
     103    let (inst, new_pc, _) = ASMInterpret.fetch mem pc in
     104    (Printf.sprintf "%s%s: %s%s\n"
     105       s
     106       (string_of_int (BitVectors.int_of_vect pc))
     107       (pp_instruction inst)
     108       (if BitVectors.WordMap.mem pc p.ASM.cost_labels then
     109           " ;; (" ^ (BitVectors.WordMap.find pc p.ASM.cost_labels) ^ ")"
     110        else ""),
     111     new_pc) in
     112  fst (List.fold_left f ("", BitVectors.zero `Sixteen) p.ASM.code)
  • Deliverables/D2.2/8051/src/ASM/Pretty.mli

    r627 r640  
    2121val pp_instruction: [< ASM.labelled_instruction] -> string
    2222
    23 val print_program : [< ASM.labelled_instruction] ASM.pretty_program -> string
     23val print_program : ASM.program -> string
  • Deliverables/D2.2/8051/src/acc.ml

    r630 r640  
    3939    save final_ast;
    4040    (if Options.annotation_requested () then
    41        let (annotated_input_ast, cost_incr) =
     41       let (annotated_input_ast, cost_id, cost_incr) =
    4242         Languages.annotate input_ast final_ast in
    4343       save annotated_input_ast;
    44        Languages.save_cost_incr output_filename cost_incr);
     44       Languages.save_cost output_filename cost_id cost_incr);
    4545    (if Options.is_debug_enabled () then
    4646      List.iter save intermediate_asts);
  • Deliverables/D2.2/8051/src/clight/clightAnnotator.ml

    r624 r640  
    285285  close_out cout
    286286
    287 (** [instrument prog cost_map] instruments the program [prog]. *)
     287(** [instrument prog cost_map] instruments the program [prog]. First a fresh
     288    global variable --- the so-called cost variable --- is added to the program.
     289    Then, each cost label in the program is replaced by an increment of the cost
     290    variable, following the mapping [cost_map]. The function also returns the
     291    name of the cost variable and the name of the cost increment function. *)
    288292
    289293let instrument p cost_mapping =
     
    318322  let res = ClightParser.process tmp_file in
    319323  Misc.SysExt.safe_remove tmp_file ;
    320   (res, cost_incr)
     324  (res, cost_id, cost_incr)
  • Deliverables/D2.2/8051/src/clight/clightAnnotator.mli

    r619 r640  
    55    global variable --- the so-called cost variable --- is added to the program.
    66    Then, each cost label in the program is replaced by an increment of the cost
    7     variable, following the mapping [cost_map]. The returned string is the name
    8     of the cost increment function. *)
     7    variable, following the mapping [cost_map]. The function also returns the
     8    name of the cost variable and the name of the cost increment function. *)
    99
    1010val instrument : Clight.program -> int CostLabel.Map.t ->
    11                  Clight.program * string
     11                 Clight.program * string * string
    1212
    1313val cost_labels : Clight.program -> CostLabel.Set.t
  • Deliverables/D2.2/8051/src/cminor/cminorAnnotator.ml

    r619 r640  
    131131
    132132
     133(** [instrument prog cost_map] instruments the program [prog]. First a fresh
     134    global variable --- the so-called cost variable --- is added to the program.
     135    Then, each cost label in the program is replaced by an increment of the cost
     136    variable, following the mapping [cost_map]. The function also returns the
     137    name of the cost variable and the name of the cost increment function. *)
     138
    133139let instrument p costs_mapping =
    134140  let cost_id = fresh_cost_id "_cost" p in
     
    140146     Cminor.functs = functs ;
    141147     Cminor.main   = p.Cminor.main },
     148   "" (* TODO *),
    142149   "" (* TODO *))
    143150
  • Deliverables/D2.2/8051/src/cminor/cminorAnnotator.mli

    r619 r640  
    55    global variable --- the so-called cost variable --- is added to the program.
    66    Then, each cost label in the program is replaced by an increment of the cost
    7     variable, following the mapping [cost_map]. The returned string is the name
    8     of the cost increment function. *)
     7    variable, following the mapping [cost_map]. The function also returns the
     8    name of the cost variable and the name of the cost increment function. *)
    99
    1010val instrument : Cminor.program -> int CostLabel.Map.t ->
    11                  Cminor.program * string
     11                 Cminor.program * string * string
    1212
    1313val cost_labels : Cminor.program -> CostLabel.Set.t
  • Deliverables/D2.2/8051/src/languages.ml

    r619 r640  
    4747
    4848let extension = function
    49   | ASM      -> "s"
    50   | Clight   -> "c"
    51   | language -> to_string language
     49  | ASM      -> ["s" ; "hex"]
     50  | Clight   -> ["c"]
     51  | language -> [to_string language]
    5252
    5353let parse = function
     
    200200let instrument costs_mapping = function
    201201  | AstClight p ->
    202     let (p', cost_incr) = ClightAnnotator.instrument p costs_mapping in
    203     (AstClight p', cost_incr)
     202    let (p', cost_id, cost_incr) = ClightAnnotator.instrument p costs_mapping in
     203    (AstClight p', cost_id, cost_incr)
    204204  | AstCminor p ->
    205     let (p', cost_incr) = CminorAnnotator.instrument p costs_mapping in
    206     (AstCminor p', cost_incr)
     205    let (p', cost_id, cost_incr) = CminorAnnotator.instrument p costs_mapping in
     206    (AstCminor p', cost_id, cost_incr)
    207207  | p ->
    208208    Error.warning "during instrumentation"
     
    210210         "Instrumentation is not implemented for source language `%s'."
    211211         (to_string (language_of_ast p)));
    212     (p, "")
     212    (p, "", "")
    213213
    214214let annotate input_ast final =
     
    218218let string_output = function
    219219  | AstClight p ->
    220     ClightPrinter.print_program p
     220    [ClightPrinter.print_program p]
    221221  | AstCminor p ->
    222     CminorPrinter.print_program p
     222    [CminorPrinter.print_program p]
    223223  | AstRTLabs p ->
    224     RTLabsPrinter.print_program p
     224    [RTLabsPrinter.print_program p]
    225225  | AstRTL p ->
    226     RTLPrinter.print_program p
     226    [RTLPrinter.print_program p]
    227227  | AstERTL p ->
    228     ERTLPrinter.print_program p
     228    [ERTLPrinter.print_program p]
    229229  | AstLTL p ->
    230     LTLPrinter.print_program p
     230    [LTLPrinter.print_program p]
    231231  | AstLIN p ->
    232     LINPrinter.print_program p
     232    [LINPrinter.print_program p]
    233233  | AstASM p ->
    234     ASMPrinter.print_program p
     234    [Pretty.print_program p ; ASMPrinter.print_program p]
    235235
    236236let save exact_output filename ast =
     
    240240      try Filename.chop_extension filename
    241241      with Invalid_argument ("Filename.chop_extension") -> filename in
    242   let ext_filename =
    243     ext_chopped_filename ^ "." ^ extension (language_of_ast ast) in
    244   let output_filename =
    245     if exact_output then ext_filename
    246     else Misc.SysExt.alternative ext_filename in
    247   let cout = open_out output_filename in
    248   output_string cout (string_output ast);
    249   flush cout;
    250   close_out cout
    251 
    252 let save_cost_incr filename cost_incr =
     242  let ext_filenames =
     243    List.map (fun ext -> ext_chopped_filename ^ "." ^ ext)
     244      (extension (language_of_ast ast)) in
     245  let output_filenames =
     246    if exact_output then ext_filenames
     247    else List.map Misc.SysExt.alternative ext_filenames in
     248  let output_strings = string_output ast in
     249  let f filename s =
     250    let cout = open_out filename in
     251    output_string cout s;
     252    flush cout;
     253    close_out cout in
     254  List.iter2 f output_filenames output_strings
     255
     256let save_cost filename cost_id cost_incr =
    253257  let cout = open_out (filename ^ ".cerco") in
    254   output_string cout cost_incr;
     258  output_string cout (cost_id ^ "\n");
     259  output_string cout (cost_incr ^ "\n");
    255260  flush cout;
    256261  close_out cout
  • Deliverables/D2.2/8051/src/languages.mli

    r619 r640  
    6262
    6363(** [annotate input_ast target_ast] inserts cost annotations into the input AST
    64     from the (final) target AST. It also returns the name of the cost increment
    65     function *)
    66 val annotate : ast -> ast -> (ast * string)
     64    from the (final) target AST. It also returns the name of the cost variable
     65    and the name of the cost increment function. *)
     66val annotate : ast -> ast -> (ast * string * string)
    6767
    6868(** [interpret print_result ast] runs the program [ast] from the default initial
     
    8080val save : bool -> string -> ast -> unit
    8181
    82 (** [save_cost_incr filename cost_incr] prints the name of the cost increment
    83     function [cost_incr] in the file prefixed by [filename] and extended with
     82(** [save_cost_incr filename cost_id cost_incr] prints the name [cost_id] of the
     83    cost variable and then the name [cost_incr] of the cost increment function
     84    in a seperate line in the file prefixed by [filename] and extended with
    8485    ".cost". If the file already exists, it is overwritten. *)
    85 val save_cost_incr : string -> string -> unit
     86val save_cost : string -> string -> string -> unit
    8687
    8788(** [from_string s] parses [s] as an intermediate language name. *)
Note: See TracChangeset for help on using the changeset viewer.