Changeset 619 for Deliverables/D2.2/8051/src/RTL
- Timestamp:
- Mar 2, 2011, 3:27:41 PM (9 years ago)
- Location:
- Deliverables/D2.2/8051/src/RTL
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Deliverables/D2.2/8051/src/RTL/RTLInterpret.ml
r486 r619 41 41 type state = 42 42 | State of stack_frame list * RTL.graph * Label.t * Val.t (* sp *) * 43 local_env * Val.t (* carry *) * memory * AST.trace43 local_env * Val.t (* carry *) * memory * CostLabel.t list 44 44 | CallState of stack_frame list * RTL.function_def * 45 Val.t list (* args *) * memory * AST.trace45 Val.t list (* args *) * memory * CostLabel.t list 46 46 | ReturnState of stack_frame list * Val.t list (* return values *) * 47 memory * AST.trace47 memory * CostLabel.t list 48 48 49 49 … … 101 101 (mem : memory) 102 102 (stmt : RTL.statement) 103 (t : AST.trace) :103 (t : CostLabel.t list) : 104 104 state = match stmt with 105 105 … … 269 269 (args : Val.t list) 270 270 (mem : memory) 271 (t : AST.trace) :271 (t : CostLabel.t list) : 272 272 state = 273 273 match f_def with … … 286 286 (ret_vals : Val.t list) 287 287 (mem : memory) 288 (t : AST.trace) :288 (t : CostLabel.t list) : 289 289 state = 290 290 let f i lenv r = Register.Map.add r (List.nth ret_vals i) lenv in … … 311 311 (Register.print r) (Val.to_string v)) 312 312 313 let rec iter_small_step st = match small_step st with 313 let compute_result vs = 314 try 315 let v = MiscPottier.last vs in 316 if Val.is_int v then IntValue.Int8.cast (Val.to_int_repr v) 317 else IntValue.Int8.zero 318 with Not_found -> IntValue.Int8.zero 319 320 let rec iter_small_step print_result st = match small_step st with 314 321 (* 322 (* <DEBUG> *) 315 323 | ReturnState ([], vs, mem, t) -> 316 324 Mem.print mem ; … … 331 339 Printf.printf "Carry = %s\n\n%!" (Val.to_string carry) ; 332 340 iter_small_step st' 341 (* </DEBUG> *) 333 342 *) 334 343 | ReturnState ([], vs, mem, t) -> 335 (* 336 Printf.printf "Return: %s\n%!" (print_ret_vals vs) ;337 *) 338 List.rev t339 | st' -> iter_small_step st'344 let (res, cost_labels) as trace = (compute_result vs, List.rev t) in 345 if print_result then 346 Printf.printf "RTL: %s\n%!" (IntValue.Int8.to_string res) ; 347 trace 348 | st' -> iter_small_step print_result st' 340 349 341 350 … … 357 366 (* Interpret the program only if it has a main. *) 358 367 359 let interpret p = match p.RTL.main with360 | None -> []368 let interpret print_result p = match p.RTL.main with 369 | None -> (IntValue.Int8.zero, []) 361 370 | Some main -> 362 371 let mem = init_mem p in 363 372 let main_def = find_function mem main in 364 373 let st = CallState ([], main_def, [], mem, []) in 365 iter_small_step st374 iter_small_step print_result st -
Deliverables/D2.2/8051/src/RTL/RTLInterpret.mli
r486 r619 3 3 and return the trace of cost labels encountered. *) 4 4 5 val interpret : RTL.program -> AST.trace5 val interpret : bool -> RTL.program -> AST.trace -
Deliverables/D2.2/8051/src/RTL/RTLToERTL.ml
r486 r619 171 171 | [] -> [fun start_lbl -> adds_graph [ERTL.St_skip start_lbl] start_lbl] 172 172 | [r] -> 173 [fun start_lbl -> 174 adds_graph [ERTL.St_set_hdw (I8051.st0, r, start_lbl)] start_lbl] 173 [fun start_lbl dest_lbl def -> 174 let (def, r_tmp) = fresh_reg def in 175 adds_graph [ERTL.St_int (r_tmp, 0, start_lbl) ; 176 ERTL.St_set_hdw (I8051.st1, r_tmp, start_lbl) ; 177 ERTL.St_set_hdw (I8051.st0, r, start_lbl)] 178 start_lbl dest_lbl def] 175 179 | r1 :: r2 :: _ -> 176 180 [(fun start_lbl -> 177 adds_graph [ERTL.St_set_hdw (I8051.st1, r1, start_lbl)] start_lbl) ; 178 (fun start_lbl -> 179 adds_graph [ERTL.St_set_hdw (I8051.st0, r2, start_lbl)] start_lbl)] 181 adds_graph [ERTL.St_set_hdw (I8051.st1, r1, start_lbl) ; 182 ERTL.St_set_hdw (I8051.st0, r2, start_lbl)] start_lbl)] 180 183 181 184 let add_epilogue ret_regs srah sral sregs def = … … 267 270 268 271 (* Fetching the result depends on the type of the function, or say, the number 269 of registers that are waiting for a value. *) 272 of registers that are waiting for a value. Temporary non allocatable 273 registers are used. Indeed, moving directly from DPL to a pseudo-register may 274 cause a bug: DPL might be used to compute the address of the 275 pseudo-register. *) 270 276 271 277 let fetch_result ret_regs start_lbl = match ret_regs with 272 278 | [] -> adds_graph [ERTL.St_skip start_lbl] start_lbl 273 279 | [r] -> 274 adds_graph280 adds_graph 275 281 [ERTL.St_hdw_to_hdw (I8051.st0, I8051.dpl, start_lbl) ; 276 282 ERTL.St_get_hdw (r, I8051.st0, start_lbl)] … … 401 407 402 408 409 (* Move the first cost label of each function at the beginning of the 410 function. Indeed, the instructions for calling conventions (stack allocation 411 for example) are added at the very beginning of the function, thus before the 412 first cost label. *) 413 414 let generate stmt def = 415 let entry = Label.Gen.fresh def.ERTL.f_luniverse in 416 let def = 417 { def with ERTL.f_graph = Label.Map.add entry stmt def.ERTL.f_graph } in 418 { def with ERTL.f_entry = entry } 419 420 let find_and_remove_first_cost_label def = 421 let rec aux lbl = match Label.Map.find lbl def.ERTL.f_graph with 422 | ERTL.St_cost (cost_label, next_lbl) -> 423 let graph = Label.Map.add lbl (ERTL.St_skip next_lbl) def.ERTL.f_graph in 424 (cost_label, { def with ERTL.f_graph = graph }) 425 | ERTL.St_skip lbl | ERTL.St_comment (_, lbl) | ERTL.St_get_hdw (_, _, lbl) 426 | ERTL.St_set_hdw (_, _, lbl) | ERTL.St_hdw_to_hdw (_, _, lbl) 427 | ERTL.St_pop (_, lbl) | ERTL.St_push (_, lbl) | ERTL.St_addrH (_, _, lbl) 428 | ERTL.St_addrL (_, _, lbl) | ERTL.St_int (_, _, lbl) 429 | ERTL.St_move (_, _, lbl) | ERTL.St_opaccs (_, _, _, _, lbl) 430 | ERTL.St_op1 (_, _, _, lbl) | ERTL.St_op2 (_, _, _, _, lbl) 431 | ERTL.St_clear_carry lbl | ERTL.St_load (_, _, _, lbl) 432 | ERTL.St_store (_, _, _, lbl) | ERTL.St_call_id (_, _, lbl) 433 | ERTL.St_newframe lbl | ERTL.St_delframe lbl | ERTL.St_framesize (_, lbl) 434 -> 435 aux lbl 436 | ERTL.St_condacc _ | ERTL.St_return _ -> 437 (* Should be impossible: the first cost label is found after some linear 438 instructions. *) 439 assert false in 440 aux def.ERTL.f_entry 441 442 let move_first_cost_label_up_internal def = 443 let (cost_label, def) = find_and_remove_first_cost_label def in 444 generate (ERTL.St_cost (cost_label, def.ERTL.f_entry)) def 445 446 let move_first_cost_label_up (id, def) = 447 let def' = match def with 448 | ERTL.F_int int_fun -> 449 ERTL.F_int (move_first_cost_label_up_internal int_fun) 450 | _ -> def in 451 (id, def') 452 453 403 454 let translate p = 404 455 (* We simplify tail calls as regular calls for now. *) 405 456 let p = RTLtailcall.simplify p in 457 (* The tranformation on each RTL function: create an ERTL function and move 458 its first cost label at the very beginning. *) 459 let f funct = move_first_cost_label_up (translate_funct funct) in 406 460 { ERTL.vars = p.RTL.vars ; 407 ERTL.functs = List.map translate_functp.RTL.functs ;461 ERTL.functs = List.map f p.RTL.functs ; 408 462 ERTL.main = p.RTL.main }
Note: See TracChangeset
for help on using the changeset viewer.