Changeset 1649


Ignore:
Timestamp:
Jan 18, 2012, 6:17:37 PM (6 years ago)
Author:
boender
Message:
  • changes to Assembly for integration with Policy and easier use of _safe functions (with CSC)
Location:
src/ASM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ASM/Assembly.ma

    r1615 r1649  
    1414  | medium_jump: jump_length
    1515  | long_jump: jump_length.
    16 
    17 definition policy_type ≝ Word → jump_length.
    1816
    1917definition assembly_preinstruction ≝
     
    420418qed.
    421419
    422 definition expand_relative_jump_internal:
    423  (Identifier → Word) → jump_length → Identifier → Word → ([[relative]] → preinstruction [[relative]]) →
     420definition expand_relative_jump_internal_safe:
     421 Word → jump_length → Word → ([[relative]] → preinstruction [[relative]]) →
    424422 option (list instruction)
    425423 ≝
    426   λlookup_labels,jmp_len.λjmp:Identifier.λpc,i.
     424  λlookup_address,jmp_len.λpc,i.
    427425  match jmp_len with
    428426  [ short_jump ⇒
    429      let lookup_address ≝ lookup_labels jmp in
    430427     let 〈result, flags〉 ≝ sub_16_with_carry pc lookup_address false in
    431428     let 〈upper, lower〉 ≝ split ? 8 8 result in
     
    440437    [ RealInstruction (i (RELATIVE (bitvector_of_nat ? 2)));
    441438      SJMP (RELATIVE (bitvector_of_nat ? 3)); (* LJMP size? *)
    442       LJMP (ADDR16 (lookup_labels jmp))
     439      LJMP (ADDR16 lookup_address)
    443440    ]
    444441  ].
     
    446443qed.
    447444
    448 definition expand_relative_jump: (Identifier → Word) → jump_length → Word → preinstruction Identifier → option (list instruction) ≝
     445definition rel_jump_length_ok ≝
     446 λlookup_address:Word.
     447 λpc:Word.
     448 Σjump_len:jump_length.
     449  (* CSC,JPB: Cheating here, use Jaap's better definition select_reljump_length *)
     450  ∀(*x,*)y. expand_relative_jump_internal_safe lookup_address jump_len (*x*) pc y ≠ None ?.
     451
     452lemma eject_rel_jump_length: ∀x,y. rel_jump_length_ok x y → jump_length.
     453 #x #y #p @(pi1 … p)
     454qed.
     455
     456coercion eject_rel_jump_length nocomposites:
     457 ∀x,y.∀pol:rel_jump_length_ok x y. jump_length ≝
     458 eject_rel_jump_length on _pol:(rel_jump_length_ok ??) to jump_length.
     459
     460definition expand_relative_jump_internal:
     461 ∀lookup_address:Word. ∀pc:Word. rel_jump_length_ok lookup_address pc →
     462  ([[relative]] → preinstruction [[relative]]) →
     463 list instruction
     464≝ λlookup_address,pc,jump_len,i.
     465   match expand_relative_jump_internal_safe lookup_address jump_len pc i
     466   return λres. res ≠ None ? → ?
     467   with
     468   [ None ⇒ λabs.⊥
     469   | Some res ⇒ λ_.res ] (pi2 … jump_len i).
     470 cases abs /2/
     471qed.
     472
     473definition expand_relative_jump_safe: ∀lookup_labels:Identifier → Word.Word → jump_length → preinstruction Identifier → option (list instruction) ≝
    449474  λlookup_labels.
     475  λpc: Word.
    450476  λjmp_len: jump_length.
    451   λpc.
    452477  λi: preinstruction Identifier.
    453478  let rel_jmp ≝ RELATIVE (bitvector_of_nat ? 2) in
    454479  match i with
    455   [ JC jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (JC ?)
    456   | JNC jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (JNC ?)
    457   | JB baddr jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (JB ? baddr)
    458   | JZ jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (JZ ?)
    459   | JNZ jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (JNZ ?)
    460   | JBC baddr jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (JBC ? baddr)
    461   | JNB baddr jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (JNB ? baddr)
    462   | CJNE addr jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (CJNE ? addr)
    463   | DJNZ addr jmp ⇒ expand_relative_jump_internal lookup_labels jmp_len jmp pc (DJNZ ? addr)
    464   | ADD arg1 arg2 ⇒ Some ? [ ADD ? arg1 arg2 ]
    465   | ADDC arg1 arg2 ⇒ Some ? [ ADDC ? arg1 arg2 ]
    466   | SUBB arg1 arg2 ⇒ Some ? [ SUBB ? arg1 arg2 ]
    467   | INC arg ⇒ Some ? [ INC ? arg ]
    468   | DEC arg ⇒ Some ? [ DEC ? arg ]
    469   | MUL arg1 arg2 ⇒ Some ? [ MUL ? arg1 arg2 ]
    470   | DIV arg1 arg2 ⇒ Some ? [ DIV ? arg1 arg2 ]
    471   | DA arg ⇒ Some ? [ DA ? arg ]
    472   | ANL arg ⇒ Some ? [ ANL ? arg ]
    473   | ORL arg ⇒ Some ? [ ORL ? arg ]
    474   | XRL arg ⇒ Some ? [ XRL ? arg ]
    475   | CLR arg ⇒ Some ? [ CLR ? arg ]
    476   | CPL arg ⇒ Some ? [ CPL ? arg ]
    477   | RL arg ⇒ Some ? [ RL ? arg ]
    478   | RR arg ⇒ Some ? [ RR ? arg ]
    479   | RLC arg ⇒ Some ? [ RLC ? arg ]
    480   | RRC arg ⇒ Some ? [ RRC ? arg ]
    481   | SWAP arg ⇒ Some ? [ SWAP ? arg ]
    482   | MOV arg ⇒ Some ? [ MOV ? arg ]
    483   | MOVX arg ⇒ Some ? [ MOVX ? arg ]
    484   | SETB arg ⇒ Some ? [ SETB ? arg ]
    485   | PUSH arg ⇒ Some ? [ PUSH ? arg ]
    486   | POP arg ⇒ Some ? [ POP ? arg ]
    487   | XCH arg1 arg2 ⇒ Some ? [ XCH ? arg1 arg2 ]
    488   | XCHD arg1 arg2 ⇒ Some ? [ XCHD ? arg1 arg2 ]
    489   | RET ⇒ Some ? [ RET ? ]
    490   | RETI ⇒ Some ? [ RETI ? ]
    491   | NOP ⇒ Some ? [ RealInstruction (NOP ?) ]
     480  [ JC jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (JC ?)
     481  | JNC jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (JNC ?)
     482  | JB baddr jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (JB ? baddr)
     483  | JZ jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (JZ ?)
     484  | JNZ jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (JNZ ?)
     485  | JBC baddr jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (JBC ? baddr)
     486  | JNB baddr jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (JNB ? baddr)
     487  | CJNE addr jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (CJNE ? addr)
     488  | DJNZ addr jmp ⇒ expand_relative_jump_internal_safe (lookup_labels jmp) jmp_len pc (DJNZ ? addr)
     489  | ADD arg1 arg2 ⇒ Some [ ADD ? arg1 arg2 ]
     490  | ADDC arg1 arg2 ⇒ Some [ ADDC ? arg1 arg2 ]
     491  | SUBB arg1 arg2 ⇒ Some [ SUBB ? arg1 arg2 ]
     492  | INC arg ⇒ Some [ INC ? arg ]
     493  | DEC arg ⇒ Some [ DEC ? arg ]
     494  | MUL arg1 arg2 ⇒ Some [ MUL ? arg1 arg2 ]
     495  | DIV arg1 arg2 ⇒  Some … [ DIV ? arg1 arg2 ]
     496  | DA arg ⇒ Some [ DA ? arg ]
     497  | ANL arg ⇒ Some [ ANL ? arg ]
     498  | ORL arg ⇒ Some [ ORL ? arg ]
     499  | XRL arg ⇒ Some [ XRL ? arg ]
     500  | CLR arg ⇒ Some [ CLR ? arg ]
     501  | CPL arg ⇒ Some [ CPL ? arg ]
     502  | RL arg ⇒ Some [ RL ? arg ]
     503  | RR arg ⇒ Some [ RR ? arg ]
     504  | RLC arg ⇒ Some [ RLC ? arg ]
     505  | RRC arg ⇒ Some [ RRC ? arg ]
     506  | SWAP arg ⇒ Some [ SWAP ? arg ]
     507  | MOV arg ⇒ Some [ MOV ? arg ]
     508  | MOVX arg ⇒ Some [ MOVX ? arg ]
     509  | SETB arg ⇒ Some [ SETB ? arg ]
     510  | PUSH arg ⇒ Some [ PUSH ? arg ]
     511  | POP arg ⇒ Some [ POP ? arg ]
     512  | XCH arg1 arg2 ⇒ Some [ XCH ? arg1 arg2 ]
     513  | XCHD arg1 arg2 ⇒ Some [ XCHD ? arg1 arg2 ]
     514  | RET ⇒ Some [ RET ? ]
     515  | RETI ⇒ Some [ RETI ? ]
     516  | NOP ⇒ Some [ RealInstruction (NOP ?) ]
    492517  ].
    493518
    494 
    495 definition expand_pseudo_instruction_safe: ? → ? → Word → jump_length → pseudo_instruction → option (list instruction) ≝
     519definition expand_pseudo_instruction_safe:
     520 ∀lookup_labels,pc. jump_length → ? → pseudo_instruction → option (list instruction) ≝
    496521  λlookup_labels.
    497   λlookup_datalabels.
    498522  λpc.
    499523  λjmp_len.
     524  λlookup_datalabels.
    500525  λi.
    501526  match i with
     
    520545    let address ≝ DATA16 (lookup_datalabels trgt) in
    521546      Some ? [ RealInstruction (MOV ? (inl ? ? (inl ? ? (inr ? ? 〈DPTR, address〉))))]
    522   | Instruction instr ⇒ expand_relative_jump lookup_labels jmp_len pc instr
     547  | Instruction instr ⇒ expand_relative_jump_safe lookup_labels pc jmp_len instr
    523548  | Jmp jmp ⇒
    524549    match jmp_len with
    525550    [ short_jump ⇒
    526       let lookup_address ≝ lookup_labels jmp in
    527       let 〈result, flags〉 ≝ sub_16_with_carry pc lookup_address false in
     551      let 〈result, flags〉 ≝ sub_16_with_carry pc (lookup_labels jmp) false in
    528552      let 〈upper, lower〉 ≝ split ? 8 8 result in
    529553      if eq_bv ? upper (zero 8) then
     
    533557        None ?
    534558    | medium_jump ⇒
    535       let address ≝ lookup_labels jmp in
    536       let 〈fst_5_addr, rest_addr〉 ≝ split ? 5 11 address in
     559      let 〈fst_5_addr, rest_addr〉 ≝ split ? 5 11 (lookup_labels jmp) in
    537560      let 〈fst_5_pc, rest_pc〉 ≝ split ? 5 11 pc in
    538561      if eq_bv ? fst_5_addr fst_5_pc then
     
    542565        None ?
    543566    | long_jump ⇒
    544       let address ≝ ADDR16 (lookup_labels jmp) in
     567        let address ≝ ADDR16 (lookup_labels jmp) in
    545568        Some ? [ LJMP address ]
    546569    ]
     
    549572qed.
    550573
    551 
    552 definition assembly_1_pseudoinstruction_safe ≝
    553   λprogram: pseudo_assembly_program.
    554   λjump_expansion: policy_type.
    555   λppc: Word.
     574definition jump_length_ok ≝
     575 λlookup_labels:Identifier → Word.
     576 λpc:Word.
     577 Σjump_len:jump_length.
     578  (* CSC,JPB: Cheating here, use Jaap's better definition select_reljump_length *)
     579  ∀x,y.expand_pseudo_instruction_safe lookup_labels pc jump_len x y ≠ None ?.
     580
     581lemma eject_jump_length: ∀x,y. jump_length_ok x y → jump_length.
     582 #x #y #p @(pi1 … p)
     583qed.
     584
     585coercion eject_jump_length nocomposites:
     586 ∀x,y.∀pol:jump_length_ok x y. jump_length ≝
     587 eject_jump_length on _pol:(jump_length_ok ??) to jump_length.
     588
     589definition expand_pseudo_instruction:
     590 ∀lookup_labels:Identifier → Word. ∀pc:Word. jump_length_ok lookup_labels pc →
     591 ? → pseudo_instruction → list instruction ≝
     592 λlookup_labels,pc,jump_len,lookup_datalabels,i.
     593   match expand_pseudo_instruction_safe lookup_labels pc jump_len lookup_datalabels i
     594   return λres. res ≠ None ? → ?
     595   with
     596   [ None ⇒ λabs.⊥
     597   | Some res ⇒ λ_.res ] (pi2 … jump_len lookup_datalabels i).
     598 cases abs /2/
     599qed.
     600
     601definition policy_type ≝
     602 λlookup_labels:Identifier → Word.
     603 ∀pc:Word. jump_length_ok lookup_labels pc.
     604
     605definition policy_type2 ≝
     606 ∀lookup_labels.policy_type lookup_labels.
     607 
     608definition assembly_1_pseudoinstruction ≝
     609  λlookup_labels.
     610  λjump_expansion: policy_type lookup_labels.
     611  (*λppc: Word.*)
    556612  λpc: Word.
    557   λlookup_labels.
    558613  λlookup_datalabels.
    559614  λi.
    560   let expansion ≝ jump_expansion ppc in
    561     match expand_pseudo_instruction_safe lookup_labels lookup_datalabels pc expansion i with
    562     [ None ⇒ None ?
    563     | Some pseudos ⇒
    564       let mapped ≝ map ? ? assembly1 pseudos in
    565       let flattened ≝ flatten ? mapped in
    566       let pc_len ≝ length ? flattened in
    567         Some ? (〈pc_len, flattened〉)
    568     ].
     615  let expansion ≝ jump_expansion pc in
     616  let pseudos ≝ expand_pseudo_instruction lookup_labels pc expansion lookup_datalabels i in
     617  let mapped ≝ map ? ? assembly1 pseudos in
     618  let flattened ≝ flatten ? mapped in
     619  let pc_len ≝ length ? flattened in
     620   〈pc_len, flattened〉.
    569621 
    570 definition construct_costs_safe
    571   λprogram.
    572   λjump_expansion: policy_type.
     622definition construct_costs
     623  λprogram_counter: nat.
     624  λjump_expansion: policy_type (λx.bitvector_of_nat ? program_counter).
    573625  λpseudo_program_counter: nat.
    574   λprogram_counter: nat.
    575626  λcosts: BitVectorTrie costlabel 16.
    576627  λi.
     
    578629  [ Cost cost ⇒
    579630    let program_counter_bv ≝ bitvector_of_nat ? program_counter in
    580       Some ? 〈program_counter, (insert … program_counter_bv cost costs)〉
     631     〈program_counter, (insert … program_counter_bv cost costs)〉
    581632  | _ ⇒
    582633    let pc_bv ≝ bitvector_of_nat ? program_counter in
    583     let ppc_bv ≝ bitvector_of_nat ? pseudo_program_counter in
    584     let lookup_labels ≝ λx.pc_bv in
     634    (*let ppc_bv ≝ bitvector_of_nat ? pseudo_program_counter in*)
    585635    let lookup_datalabels ≝ λx.zero ? in
    586636    let pc_delta_assembled ≝
    587       assembly_1_pseudoinstruction_safe program jump_expansion ppc_bv pc_bv
    588         lookup_labels lookup_datalabels i
    589     in
    590     match pc_delta_assembled with
    591     [ None ⇒ None ?
    592     | Some pc_delta_assembled ⇒
    593       let 〈pc_delta, assembled〉 ≝ pc_delta_assembled in
    594         Some ? 〈pc_delta + program_counter, costs〉       
    595     ]
     637      assembly_1_pseudoinstruction (λx.bitvector_of_nat ? program_counter)
     638       jump_expansion (*ppc_bv*) pc_bv lookup_datalabels i in
     639    let 〈pc_delta, assembled〉 ≝ pc_delta_assembled in
     640     〈pc_delta + program_counter, costs〉
    596641  ].
    597642
     
    599644   program counters. It is at the heart of the proof. *)
    600645(*CSC: code taken from build_maps *)
    601 definition sigma00: pseudo_assembly_program → policy_type → list ? → ? → option (nat × (nat × (BitVectorTrie Word 16))) ≝
    602  λinstr_list.
    603  λjump_expansion: policy_type.
     646(*JPB: Here it gets strange because we need a program counter for the jump
     647 *expansion, but we can't give it to the type because we don't have it yet. Argh.
     648 *add a forall type?*)
     649definition sigma00: policy_type2 → list ? → ? → (nat × (nat × (BitVectorTrie Word 16))) ≝
     650 λjump_expansion: policy_type2.
    604651 λl:list labelled_instruction.
    605652 λacc.
    606653  foldl …
    607    (λt,i.
    608        match t with
    609        [ None ⇒ None …
    610        | Some ppc_pc_map ⇒
    611          let 〈ppc,pc_map〉 ≝ ppc_pc_map in
    612          let 〈program_counter, sigma_map〉 ≝ pc_map in
    613          let 〈label, i〉 ≝ i in
    614           match construct_costs_safe instr_list jump_expansion ppc program_counter (Stub …) i with
    615            [ None ⇒ None ?
    616            | Some pc_ignore ⇒
    617               let 〈pc,ignore〉 ≝ pc_ignore in
    618                 Some … 〈S ppc, 〈pc, insert ?? (bitvector_of_nat 16 ppc) (bitvector_of_nat 16 pc) sigma_map〉〉 ]
    619        ]) acc l.
    620 
    621 definition sigma0: pseudo_assembly_program → policy_type → option (nat × (nat × (BitVectorTrie Word 16))) ≝
     654   (λppc_pc_map,i.
     655     let 〈ppc,pc_map〉 ≝ ppc_pc_map in
     656     let 〈program_counter, sigma_map〉 ≝ pc_map in
     657     let 〈label, i〉 ≝ i in
     658      let 〈pc,ignore〉 ≝ construct_costs program_counter (jump_expansion (λx.bitvector_of_nat ? program_counter)) ppc (Stub …) i in
     659         〈S ppc, 〈pc, insert ?? (bitvector_of_nat 16 ppc) (bitvector_of_nat 16 pc) sigma_map〉〉
     660   ) acc l.
     661
     662definition sigma0: pseudo_assembly_program → policy_type2 → (nat × (nat × (BitVectorTrie Word 16))) ≝
    622663  λprog.
    623664  λjump_expansion.
    624     sigma00 prog jump_expansion (\snd prog) (Some ? 〈0, 〈0, Stub …〉〉).
    625 
    626 definition tech_pc_sigma00: pseudo_assembly_program → policy_type → list labelled_instruction → option (nat × nat) ≝
     665    sigma00 jump_expansion (\snd prog) 〈0, 〈0, Stub …〉〉.
     666
     667definition tech_pc_sigma00: pseudo_assembly_program → policy_type2 →
     668 list labelled_instruction → (nat × nat) ≝
    627669 λprogram,jump_expansion,instr_list.
    628   match sigma00 program jump_expansion instr_list (Some ? 〈0, 〈0, (Stub ? ?)〉〉) (* acc copied from sigma0 *) with
    629    [ None ⇒ None …
    630    | Some result ⇒
    631       let 〈ppc,pc_sigma_map〉 ≝ result in
    632       let 〈pc,map〉 ≝ pc_sigma_map in
    633        Some … 〈ppc,pc〉 ].
    634 
    635 definition sigma_safe: pseudo_assembly_program → policy_type → option (Word → Word) ≝
     670   let 〈ppc,pc_sigma_map〉 ≝ sigma00 jump_expansion instr_list 〈0, 〈0, (Stub ? ?)〉〉 in (* acc copied from sigma0 *)
     671   let 〈pc,map〉 ≝ pc_sigma_map in
     672     〈ppc,pc〉.
     673
     674definition sigma_safe: pseudo_assembly_program → policy_type2 →
     675 option (Word → Word) ≝
    636676 λinstr_list,jump_expansion.
    637   match sigma0 instr_list jump_expansion with
    638   [ None ⇒ None ?
    639   | Some result ⇒
    640     let 〈ppc,pc_sigma_map〉 ≝ result in
    641     let 〈pc, sigma_map〉 ≝ pc_sigma_map in
    642       if gtb pc (2^16) then
    643         None ?
    644       else
    645         Some ? (λx. lookup … x sigma_map (zero …)) ].
     677  let 〈ppc,pc_sigma_map〉 ≝ sigma0 instr_list jump_expansion in
     678  let 〈pc, sigma_map〉 ≝ pc_sigma_map in
     679    if gtb pc (2^16) then
     680      None ?
     681    else
     682      Some ? (λx. lookup … x sigma_map (zero …)).
    646683
    647684(* stuff about policy *)
     
    649686definition policy_ok ≝ λjump_expansion,p. sigma_safe p jump_expansion ≠ None ….
    650687
    651 definition policy ≝ λp. Σjump_expansion:policy_type. policy_ok jump_expansion p.
    652 
    653 lemma eject_policy: ∀p. policy p → policy_type.
     688definition policy ≝ λp. Σjump_expansion:policy_type2. policy_ok jump_expansion p.
     689
     690lemma eject_policy: ∀p. policy p → policy_type2.
    654691 #p #pol @(pi1 … pol)
    655692qed.
    656693
    657 coercion eject_policy nocomposites: ∀p.∀pol:policy p. policy_type ≝ eject_policy on _pol:(policy ?) to policy_type.
     694coercion eject_policy nocomposites: ∀p.∀pol:policy p. policy_type2 ≝ eject_policy on _pol:(policy ?) to policy_type2.
    658695
    659696definition sigma: ∀p:pseudo_assembly_program. policy p → Word → Word ≝
     
    675712
    676713lemma sigma00_append:
    677  ∀instr_list,jump_expansion,l1,l2,acc.
    678   sigma00 instr_list jump_expansion (l1@l2) acc =
    679    sigma00 instr_list jump_expansion
    680     l2 (sigma00 instr_list jump_expansion l1 acc).
     714 ∀jump_expansion,l1,l2,acc.
     715  sigma00 jump_expansion (l1@l2) acc =
     716   sigma00 jump_expansion
     717    l2 (sigma00 jump_expansion l1 acc).
    681718 whd in match sigma00; normalize nodelta;
    682  #instr_list #jump_expansion #l1 #l2 #acc @foldl_append
    683 qed.
    684 
    685 lemma sigma00_strict:
    686  ∀instr_list,jump_expansion,l,acc. acc = None ? →
    687   sigma00 instr_list jump_expansion l acc = None ….
    688  #instr_list #jump_expansion #l elim l
     719 #jump_expansion #l1 #l2 #acc @foldl_append
     720qed.
     721
     722(* lemma sigma00_strict:
     723 ∀jump_expansion,l,acc. acc = None ? →
     724  sigma00 jump_expansion l acc = None ….
     725 #jump_expansion #l elim l
    689726  [ #acc #H >H %
    690   | #hd #tl #IH #acc #H >H change with (sigma00 ?? tl ? = ?) @IH % ]
     727  | #hd #tl #IH #acc #H >H change with (sigma00 ? tl ? = ?) @IH % ]
    691728qed.
    692729
     
    702739  [2: #x #_ % #abs destruct(abs)
    703740  | * #abs @⊥ @abs >sigma00_strict % ]
    704 qed.
     741qed. 
    705742
    706743lemma policy_ok_prefix_hd_ok:
     
    720757 cases (construct_costs_safe ??????) normalize
    721758  [* #abs @⊥ @abs % | #X #_ % #abs destruct(abs)]
    722 qed.
    723 
     759qed. *)
     760
     761(* JPB,CSC: this definition is now replaced by the expand_pseudo_instruction higher up
    724762definition expand_pseudo_instruction:
    725763 ∀program:pseudo_assembly_program.∀pol: policy program.
     
    729767  let pi ≝ \fst (fetch_pseudo_instruction (\snd program) ppc) in
    730768  pc = sigma program pol ppc →
    731   Σres:list instruction. Some … res = expand_pseudo_instruction_safe lookup_labels lookup_datalabels pc (pol ppc) pi
     769  Σres:list instruction. Some … res = expand_pseudo_instruction_safe pc (lookup_labels pi) lookup_datalabels (pol ppc) pi
    732770≝ λprogram,pol,ppc,lookup_labels,lookup_datalabels,pc,prf1,prf2,prf3.
    733771   match expand_pseudo_instruction_safe lookup_labels lookup_datalabels pc (pol ppc) (\fst (fetch_pseudo_instruction (\snd program) ppc)) with
     
    753791   per concludere construct_costs_safe ≠ None *)
    754792 | >p %]
    755 qed.
     793qed. *)
    756794
    757795(* MAIN AXIOM HERE, HIDDEN USING cases daemon *)
    758 definition assembly_1_pseudoinstruction':
     796(* definition assembly_1_pseudoinstruction':
    759797 ∀program:pseudo_assembly_program.∀pol: policy program.
    760798  ∀ppc:Word.∀lookup_labels,lookup_datalabels,pi.
     
    763801  \fst (fetch_pseudo_instruction (\snd program) ppc) = pi →
    764802  Σres:(nat × (list Byte)).
    765    Some … res = assembly_1_pseudoinstruction_safe program pol ppc (sigma program pol ppc) lookup_labels lookup_datalabels pi ∧
     803   res = assembly_1_pseudoinstruction program pol ppc (sigma program pol ppc) lookup_labels lookup_datalabels pi ∧
    766804   let 〈len,code〉 ≝ res in
    767805    sigma program pol (\snd (half_add ? ppc (bitvector_of_nat ? 1))) =
     
    774812  λpi.
    775813  λprf1,prf2,prf3.
    776    match assembly_1_pseudoinstruction_safe program pol ppc (sigma program pol ppc) lookup_labels lookup_datalabels pi with
    777     [ None ⇒ let dummy ≝ 〈0,[ ]〉 in dummy
    778     | Some res ⇒ res ].
     814   assembly_1_pseudoinstruction program pol ppc (sigma program pol ppc) lookup_labels lookup_datalabels pi.
    779815 [ @⊥ elim pi in p; [*]
    780816   try (#ARG1 #ARG2 #ARG3 #abs) try (#ARG1 #ARG2 #abs) try (#ARG1 #abs) try #abs
     
    787823   (* THIS SHOULD BE TRUE INSTEAD *)
    788824   cases daemon]
    789 qed.
     825qed. 
    790826
    791827definition assembly_1_pseudoinstruction:
     
    811847 cases (pi2 … (assembly_1_pseudoinstruction' program pol ppc lookup_labels lookup_datalabels pi prf1 prf2 prf3))
    812848 #H1 #_ @H1
    813 qed.
     849qed. *)
    814850
    815851(* MAIN AXIOM HERE, HIDDEN USING cases daemon *)
    816 definition construct_costs':
     852(* definition construct_costs':
    817853 ∀program. ∀pol:policy program. ∀ppc,pc,costs,i.
    818854  Σres:(nat × (BitVectorTrie costlabel 16)). Some … res = construct_costs_safe program pol ppc pc costs i
     
    827863
    828864definition construct_costs ≝
    829  λprogram,pol,ppc,pc,costs,i. pi1 … (construct_costs' program pol ppc pc costs i).
     865 λprogram,pol,ppc,pc,costs,i. pi1 … (construct_costs' program pol ppc pc costs i). *)
    830866
    831867(*
     
    902938*)
    903939
    904 axiom construct_costs_sigma:
     940(* axiom construct_costs_sigma:
    905941 ∀p.∀pol:policy p.∀ppc,pc,costs,i.
    906942  bitvector_of_nat ? pc = sigma p pol (bitvector_of_nat ? ppc) →
     
    910946 ∀program.∀pol:policy program.∀prefix,costs,label,i,ppc,pc.
    911947  tech_pc_sigma00 program pol prefix = Some … 〈ppc,pc〉 →
    912    tech_pc_sigma00 program pol (prefix@[〈label,i〉]) = Some … 〈S ppc,\fst (construct_costs program pol … ppc pc costs i)〉.
     948   tech_pc_sigma00 program pol (prefix@[〈label,i〉]) = Some … 〈S ppc,\fst (construct_costs program pol … ppc pc costs i)〉. *)
    913949
    914950axiom eq_identifier_eq:
     
    941977              And (bitvector_of_nat ? pc' = sigma pseudo_program pol (bitvector_of_nat ? ppc')) (*∧*)
    942978                (ppc' = length … pre)) (*∧ *)
    943                 (tech_pc_sigma00 pseudo_program (pi1 … pol) pre = Some ? 〈ppc',pc'〉)) (*∧*)
     979                (tech_pc_sigma00 pseudo_program (pi1 … pol) pre = 〈ppc',pc'〉)) (*∧*)
    944980                (∀id. occurs_exactly_once id pre →
    945981                  lookup_def … labels id (zero …) = sigma pseudo_program pol (address_of_word_labels_code_mem pre id)))
     
    958994            ]
    959995          in
    960             let construct ≝ construct_costs pseudo_program pol ppc pc costs i' in
     996            let construct ≝ construct_costs pc (pol (λx.bitvector_of_nat ? pc)) ppc costs i' in
    961997              〈labels, 〈S ppc,construct〉〉) 〈empty_map …, 〈0, 〈0, Stub ? ?〉〉〉
    962998    in
     
    9651001      let 〈pc, costs〉 ≝ pc_costs in
    9661002        〈labels, costs〉.
    967  [2: whd generalize in match (pi2 … t); >p >p1 >p2 >p3 * * * #IHn1 #IH0 #IH1 #IH2
     1003(* [2: whd generalize in match (pi2 … t); >p >p1 >p2 >p3 * * * #IHn1 #IH0 #IH1 #IH2
    9681004   generalize in match (refl … construct); cases construct in ⊢ (???% → %); #PC #CODE #JMEQ % [% [%]]
    9691005   [ <(construct_costs_sigma … costs i1 IHn1) change with (? = ?(\fst construct)) >JMEQ %
     
    9831019 | generalize in match (pi2 … result) in ⊢ ?;
    9841020   normalize nodelta in p ⊢ %; -result; >p in ⊢ (match % with [_ ⇒ ?] → ?);
    985    normalize nodelta; >p1 normalize nodelta; >p2; normalize nodelta; * #_; #H @H]
     1021   normalize nodelta; >p1 normalize nodelta; >p2; normalize nodelta; * #_; #H @H] *)
     1022 cases daemon
    9861023qed.
    9871024
     
    10031040          let 〈pi,newppc〉 ≝ fetch_pseudo_instruction instr_list ppc' in
    10041041          let 〈len,assembledi〉 ≝
    1005            assembly_1_pseudoinstruction 〈preamble,instr_list〉 pol ppc' lookup_labels lookup_datalabels pi ??? in
     1042           assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) ppc' lookup_datalabels pi in
    10061043           True)
    10071044      instr_list
     
    10091046        let 〈pc, ppc_code〉 ≝ pc_ppc_code in
    10101047        let 〈ppc, code〉 ≝ ppc_code in
    1011         let 〈pc_delta, program〉 ≝ assembly_1_pseudoinstruction 〈preamble,instr_list〉 pol ppc lookup_labels lookup_datalabels (\snd hd) ??? in
     1048        let 〈pc_delta, program〉 ≝ assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) ppc lookup_datalabels (\snd hd) in
    10121049        let 〈new_pc, flags〉 ≝ add_16_with_carry pc (bitvector_of_nat ? pc_delta) false in
    10131050        let new_ppc ≝ \snd (half_add ? ppc (bitvector_of_nat ? 1)) in
     
    10161053    in
    10171054     〈\snd (\snd result), costs〉.
    1018  [2,5: %
    1019  |*: cases daemon ]
     1055 cases daemon
    10201056qed.
    10211057
  • src/ASM/AssemblyProof.ma

    r1616 r1649  
    12881288 #H >H * #H1 try (whd in ⊢ (% → ?); * #H2)
    12891289 try (whd in ⊢ (% → ?); * #H3) whd in ⊢ (% → ?); #H4
    1290  [ whd in match fetch; normalize nodelta <H1 (*XXX
     1290 [ whd in match fetch; normalize nodelta <H1 ] cases daemon
     1291 (*XXX
    12911292   
    12921293 whd in ⊢ (let fetched ≝ ??% in ?) <H1 whd in ⊢ (let fetched ≝ % in ?)
     
    13171318               
    13181319lemma fetch_assembly_pseudo':
    1319  ∀program.∀pol:policy program.∀ppc,lookup_labels,lookup_datalabels.
     1320 ∀lookup_labels.∀pol:policy_type lookup_labels.∀ppc,lookup_datalabels.
    13201321  ∀pi,code_memory,len,assembled,instructions,pc.
    13211322   let expansion ≝ pol ppc in
    1322    Some ? instructions = expand_pseudo_instruction_safe lookup_labels lookup_datalabels (bitvector_of_nat ? pc) expansion pi →
    1323     Some … 〈len,assembled〉 = assembly_1_pseudoinstruction_safe program pol ppc (bitvector_of_nat ? pc) lookup_labels lookup_datalabels pi →
     1323   instructions = expand_pseudo_instruction lookup_labels ppc expansion lookup_datalabels pi →
     1324    〈len,assembled〉 = assembly_1_pseudoinstruction lookup_labels pol ppc lookup_datalabels pi →
    13241325     encoding_check code_memory (bitvector_of_nat … pc) (bitvector_of_nat … (pc + len)) assembled →
    13251326      fetch_many code_memory (bitvector_of_nat … (pc + len)) (bitvector_of_nat … pc) instructions.
    1326  #program #pol #ppc #lookup_labels #lookup_datalabels #pi #code_memory #len #assembled #instructions #pc
    1327  #EQ1 whd in ⊢ (???% → ?) <EQ1 whd in ⊢ (???% → ?) #EQ2
    1328  cases (pair_destruct ?????? (option_destruct_Some … EQ2)) -EQ2; #EQ2a #EQ2b
    1329  >EQ2a >EQ2b -EQ2a EQ2b;
     1327 #lookup_labels #pol #ppc #lookup_datalabels #pi #code_memory #len #assembled #instructions #pc
     1328 #EQ1 whd in ⊢ (???% → ?); <EQ1 whd in ⊢ (???% → ?); #EQ2
     1329 cases (pair_destruct ?????? EQ2) -EQ2; #EQ2a #EQ2b
     1330 >EQ2a >EQ2b -EQ2a -EQ2b;
    13301331  generalize in match (pc + |flatten … (map … assembly1 instructions)|); #final_pc
    1331   generalize in match pc elim instructions
    1332   [ #pc whd in ⊢ (% → %) #H >H @eq_bv_refl
     1332  generalize in match pc; elim instructions
     1333  [ #pc whd in ⊢ (% → %); #H >H @eq_bv_refl
    13331334  | #i #tl #IH #pc #H whd cases (encoding_check_append … H); -H; #H1 #H2 whd
    1334     generalize in match (fetch_assembly pc i code_memory … (refl …) H1)
    1335     cases (fetch code_memory (bitvector_of_nat … pc)) #newi_pc #ticks whd in ⊢ (% → %)
    1336     cases newi_pc #newi #newpc whd in ⊢ (% → %) #K cases (conjunction_true … K) -K; #K1
     1335    generalize in match (fetch_assembly pc i code_memory … (refl …) H1);
     1336    cases (fetch code_memory (bitvector_of_nat … pc)) #newi_pc #ticks whd in ⊢ (% → %);
     1337    cases newi_pc #newi #newpc whd in ⊢ (% → %); #K cases (conjunction_true … K) -K; #K1
    13371338    cases (conjunction_true … K1) -K1; #K1 #K2 #K3 % try %
    13381339    [ @K1 | @eqb_true_to_eq <(eq_instruction_to_eq … K1) @K2 | >(eq_bv_eq … K3) @IH @H2 ]
     
    13451346(* CSC: soo long next one; can we merge with previous one now? *)
    13461347lemma fetch_assembly_pseudo:
    1347  ∀program.∀pol:policy program.∀ppc.
    1348   ∀code_memory.
    1349    let lookup_labels ≝ ? in
    1350    let lookup_datalabels ≝ ? in
    1351    let pc ≝ ? in
    1352    let pi ≝  \fst  (fetch_pseudo_instruction (\snd  program) ppc) in
    1353    let instructions ≝ expand_pseudo_instruction program pol ppc lookup_labels lookup_datalabels pc (refl …) (refl …) (refl …) in
    1354    let 〈len,assembled〉 ≝ assembly_1_pseudoinstruction program pol ppc lookup_labels lookup_datalabels pi (refl …) (refl …) (refl …) in
    1355      encoding_check code_memory pc (bitvector_of_nat … (nat_of_bitvector ? pc + len)) assembled →
    1356       fetch_many code_memory (bitvector_of_nat … (nat_of_bitvector ? pc + len)) pc instructions.
    1357  #program #pol #ppc #code_memory
    1358  letin lookup_labels ≝ (λx:Identifier
    1359     .sigma program pol (address_of_word_labels_code_mem (\snd  program) x))
    1360  letin lookup_datalabels ≝
    1361   (λx:BitVector 16
    1362     .lookup Identifier 16 x (construct_datalabels (\fst  program)) (zero 16))
    1363  letin pc ≝ (sigma program pol ppc)
    1364  letin pi ≝ (\fst  (fetch_pseudo_instruction (\snd  program) ppc))
    1365  letin instructions ≝ (expand_pseudo_instruction program pol ppc lookup_labels lookup_datalabels pc (refl …) (refl …) (refl …))
    1366  @pair_elim' #len #assembled #EQ1 #H
     1348  ∀program:pseudo_assembly_program.
     1349  let lookup_labels ≝ λx:Identifier.(address_of_word_labels_code_mem (\snd  program) x) in
     1350  ∀pol:(policy program).∀ppc.∀code_memory.
     1351  let lookup_datalabels ≝ λx:Identifier.lookup_def … (construct_datalabels (\fst  program)) x (zero 16) in
     1352  let pc ≝ sigma program pol ppc in
     1353  let pi ≝  \fst  (fetch_pseudo_instruction (\snd program) ppc) in
     1354  let instructions ≝ expand_pseudo_instruction lookup_labels ppc (pol lookup_labels ppc) lookup_datalabels pi in
     1355  let 〈len,assembled〉 ≝ assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) ppc lookup_datalabels pi in
     1356    encoding_check code_memory pc (bitvector_of_nat … (nat_of_bitvector ? pc + len)) assembled →
     1357     fetch_many code_memory (bitvector_of_nat … (nat_of_bitvector ? pc + len)) pc instructions.
     1358 #program letin lookup_labels ≝ (λx.?) #pol #ppc #code_memory
     1359 letin lookup_datalabels ≝ (λx.?)
     1360 letin pc ≝ (sigma ???) letin pi ≝ (fst ???) 
     1361 letin instructions ≝ (expand_pseudo_instruction ?????)
     1362 @pair_elim #len #assembled #EQ1 #H
    13671363 generalize in match
    1368   (fetch_assembly_pseudo' program pol ppc lookup_labels lookup_datalabels pi
    1369   code_memory len assembled instructions (nat_of_bitvector ? pc) ???) in ⊢ ?;
    1370  [ >bitvector_of_nat_nat_of_bitvector //
    1371  | >bitvector_of_nat_nat_of_bitvector normalize nodelta >(sig2 ?? (expand_pseudo_instruction …)) %
    1372  | >bitvector_of_nat_nat_of_bitvector <EQ1 @assembly_1_pseudoinstruction_ok1
    1373  | //]
     1364  (fetch_assembly_pseudo' lookup_labels ((pi1 ?? pol) lookup_labels) ppc lookup_datalabels pi code_memory len
     1365   assembled instructions (nat_of_bitvector ? pc)) in ⊢ ?;
     1366  >bitvector_of_nat_nat_of_bitvector >EQ1 normalize nodelta
     1367  #X @X //
    13741368qed.
    13751369
     
    13861380  let preamble ≝ \fst program in
    13871381  let datalabels ≝ construct_datalabels preamble in
    1388   let lookup_labels ≝ λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x) in
    1389   let lookup_datalabels ≝ λx. lookup ?? x datalabels (zero ?) in
     1382  let lookup_labels ≝ λx. address_of_word_labels_code_mem (\snd program) x in
     1383  let lookup_datalabels ≝ λx. lookup_def ?? datalabels x (zero ?) in
    13901384  ∀ppc.
    13911385  let pi_newppc ≝ fetch_pseudo_instruction (\snd program) ppc in
    13921386   ∀len,assembledi.
    1393      〈len,assembledi〉 = assembly_1_pseudoinstruction program pol ppc lookup_labels lookup_datalabels (\fst pi_newppc) (refl …) (refl …) (refl …) →
     1387     〈len,assembledi〉 = assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) ppc lookup_datalabels (\fst pi_newppc) →
    13941388      encoding_check code_memory (sigma program pol ppc) (bitvector_of_nat … (nat_of_bitvector … (sigma program pol ppc) + len)) assembledi ∧
    13951389       sigma program pol (\snd pi_newppc) = bitvector_of_nat … (nat_of_bitvector … (sigma program pol ppc) + len).
     
    14011395  let code_memory ≝ load_code_memory assembled in
    14021396  let data_labels ≝ construct_datalabels (\fst program) in
    1403   let lookup_labels ≝ λx. sigma program pol (address_of_word_labels_code_mem (\snd program) x) in
    1404   let lookup_datalabels ≝ λx. lookup ? ? x data_labels (zero ?) in
     1397  let lookup_labels ≝ λx.address_of_word_labels_code_mem (\snd program) x in
     1398  let lookup_datalabels ≝ λx. lookup_def ? ? data_labels x (zero ?) in
    14051399  let 〈pi,newppc〉 ≝ fetch_pseudo_instruction (\snd program) ppc in
    1406   let instructions ≝ expand_pseudo_instruction program pol ppc lookup_labels lookup_datalabels (sigma program pol ppc) (refl …) (refl …) (refl …) in
     1400  let instructions ≝ expand_pseudo_instruction lookup_labels ppc (pol lookup_labels ppc) lookup_datalabels pi in
    14071401   fetch_many code_memory (sigma program pol newppc) (sigma program pol ppc) instructions.
    14081402 * #preamble #instr_list #pol #ppc
     
    14101404 letin code_memory ≝ (load_code_memory assembled)
    14111405 letin data_labels ≝ (construct_datalabels preamble)
    1412  letin lookup_labels ≝ (λx. sigma … pol (address_of_word_labels_code_mem instr_list x))
    1413  letin lookup_datalabels ≝ (λx. lookup ? ? x data_labels (zero ?))
    1414  @pair_elim' #pi #newppc #EQ1 change in EQ1 with (fetch_pseudo_instruction instr_list ? = ?)
    1415  generalize in match (assembly_ok ? pol assembled (\snd (assembly 〈preamble,instr_list〉 pol)))
    1416  @pair_elim' #labels #costs #EQ2 <eq_pair_fst_snd
     1406 letin lookup_labels ≝ (λx. address_of_word_labels_code_mem instr_list x)
     1407 letin lookup_datalabels ≝ (λx. lookup_def ? ? data_labels x (zero ?))
     1408 @pair_elim #pi #newppc #EQ1 change with (fetch_pseudo_instruction instr_list ? = ?) in EQ1;
     1409 generalize in match (assembly_ok ? pol assembled (\snd (assembly 〈preamble,instr_list〉 pol)));
     1410 @pair_elim #labels #costs #EQ2 <eq_pair_fst_snd
    14171411 #H cases (H (refl \ldots)) -H; #EQ3
    1418  generalize in match (refl … (assembly_1_pseudoinstruction … pol ppc lookup_labels lookup_datalabels ? (refl …) (refl …) (refl …)))
    1419  cases (assembly_1_pseudoinstruction ?????????) in ⊢ (???% → ?) #len #assembledi #EQ4
    1420  #H cases (H ppc len assembledi ?) [2: <EQ4 %] -H; #H1 #H2
    1421  generalize in match (fetch_assembly_pseudo … pol ppc (load_code_memory assembled)) in ⊢ ?
    1422  >EQ4 #H generalize in match (H H1) in ⊢ ? -H; >(pair_destruct_2 ????? (sym_eq … EQ1))
    1423  >H2 #K @K
     1412 generalize in match (refl … (assembly_1_pseudoinstruction lookup_labels (pol lookup_labels) ppc lookup_datalabels ?));
     1413 [ cases (assembly_1_pseudoinstruction ?????) in ⊢ (???% → ?); #len #assembledi #EQ4
     1414   #H cases (H ppc len assembledi ?) [2: <EQ4 %] -H; #H1 #H2
     1415   (* XXX JPB: attention to lookup_labels *)
     1416   generalize in match (fetch_assembly_pseudo 〈preamble,instr_list〉 pol ppc (load_code_memory assembled)) in ⊢ ?;
     1417   >EQ4; #H generalize in match (H H1) in ⊢ ?; -H >(pair_destruct_2 ????? (sym_eq … EQ1))
     1418   >H2 >EQ1 #K @K
    14241419qed.
    14251420
     
    17071702*)
    17081703
    1709 definition ticks_of0: ∀p:pseudo_assembly_program. policy p → Word → ? → nat × nat ≝
    1710   λprogram: pseudo_assembly_program.λpol.
     1704definition ticks_of0: ∀p:pseudo_assembly_program. policy p → (Identifier→Word) → Word → ? → nat × nat ≝
     1705  λprogram: pseudo_assembly_program.λpol.λlookup_labels.
    17111706  λppc: Word.
    17121707  λfetched.
     
    17151710      match instr with
    17161711      [ JC lbl ⇒
    1717         match pol ppc with
     1712        match pol lookup_labels ppc with
    17181713        [ short_jump ⇒ 〈2, 2〉
    17191714        | medium_jump ⇒ ?
     
    17211716        ]
    17221717      | JNC lbl ⇒
    1723         match pol ppc with
     1718        match pol lookup_labels ppc with
    17241719        [ short_jump ⇒ 〈2, 2〉
    17251720        | medium_jump ⇒ ?
     
    17271722        ]
    17281723      | JB bit lbl ⇒
    1729         match pol ppc with
     1724        match pol lookup_labels ppc with
    17301725        [ short_jump ⇒ 〈2, 2〉
    17311726        | medium_jump ⇒ ?
     
    17331728        ]
    17341729      | JNB bit lbl ⇒
    1735         match pol ppc with
     1730        match pol lookup_labels ppc with
    17361731        [ short_jump ⇒ 〈2, 2〉
    17371732        | medium_jump ⇒ ?
     
    17391734        ]
    17401735      | JBC bit lbl ⇒
    1741         match pol ppc with
     1736        match pol lookup_labels ppc with
    17421737        [ short_jump ⇒ 〈2, 2〉
    17431738        | medium_jump ⇒ ?
     
    17451740        ]
    17461741      | JZ lbl ⇒
    1747         match pol ppc with
     1742        match pol lookup_labels ppc with
    17481743        [ short_jump ⇒ 〈2, 2〉
    17491744        | medium_jump ⇒ ?
     
    17511746        ]
    17521747      | JNZ lbl ⇒
    1753         match pol ppc with
     1748        match pol lookup_labels  ppc with
    17541749        [ short_jump ⇒ 〈2, 2〉
    17551750        | medium_jump ⇒ ?
     
    17571752        ]
    17581753      | CJNE arg lbl ⇒
    1759         match pol ppc with
     1754        match pol lookup_labels ppc with
    17601755        [ short_jump ⇒ 〈2, 2〉
    17611756        | medium_jump ⇒ ?
     
    17631758        ]
    17641759      | DJNZ arg lbl ⇒
    1765         match pol ppc with
     1760        match pol lookup_labels ppc with
    17661761        [ short_jump ⇒ 〈2, 2〉
    17671762        | medium_jump ⇒ ?
     
    18621857qed.
    18631858
    1864 definition ticks_of: ∀p:pseudo_assembly_program. policy p → Word → nat × nat ≝
    1865   λprogram: pseudo_assembly_program.λpol.
     1859definition ticks_of: ∀p:pseudo_assembly_program. policy p → (Identifier→Word) → Word → nat × nat ≝
     1860  λprogram: pseudo_assembly_program.λpol.λlookup_labels.
    18661861  λppc: Word.
    18671862    let 〈preamble, pseudo〉 ≝ program in
    18681863    let 〈fetched, new_ppc〉 ≝ fetch_pseudo_instruction pseudo ppc in
    1869      ticks_of0 program pol ppc fetched.
     1864     ticks_of0 program pol lookup_labels ppc fetched.
    18701865
    18711866lemma eq_rect_Type1_r:
     
    18741869  ∀P: ∀x:A. eq ? x a → Type[1]. P a (refl A a) → ∀x: A.∀p:eq ? x a. P x p.
    18751870  #A #a #P #H #x #p
    1876   generalize in match H
    1877   generalize in match P
     1871  generalize in match H;
     1872  generalize in match P;
    18781873  cases p
    18791874  //
     
    20342029
    20352030theorem main_thm:
    2036  ∀M,M',ps,pol.
     2031 ∀M,M',ps,pol,lookup_labels.
    20372032  next_internal_pseudo_address_map M ps = Some … M' →
    20382033   ∃n.
    20392034      execute n (status_of_pseudo_status M ps pol)
    2040     = status_of_pseudo_status M' (execute_1_pseudo_instruction (ticks_of (code_memory … ps) pol) ps) ?.
     2035    = status_of_pseudo_status M' (execute_1_pseudo_instruction (ticks_of (code_memory … ps) pol lookup_labels) ps) ?.
    20412036 [2: >execute_1_pseudo_instruction_preserves_code_memory @pol]
    2042  #M #M' #ps #pol #SAFE
     2037 #M #M' #ps #pol #lookup_labels #SAFE
    20432038 cut
    20442039  (∀ps'.
    2045     ∀prf:ps'=execute_1_pseudo_instruction (ticks_of (code_memory … ps) pol) ps.
     2040    ∀prf:ps'=execute_1_pseudo_instruction (ticks_of (code_memory … ps) pol lookup_labels) ps.
    20462041    ∃n. execute n (status_of_pseudo_status M ps pol) = status_of_pseudo_status M' ps' ?)
    20472042 [ >prf >execute_1_pseudo_instruction_preserves_code_memory @pol |3: #K @(K ? (refl …))]
    20482043 #ps' #EQ
    2049  whd in ⊢ (??(λ_.??(??%)?))
     2044 whd in ⊢ (??(λ_.??(??%)?));
    20502045 change with
    20512046  (∃n.
     
    20622057        (set_program_counter ?
    20632058          (set_code_memory ?? ? (load_code_memory ?))
    2064          (sigma ???)) ?) ?)
    2065  >EQ whd in match eq_rect_Type0_r normalize nodelta
     2059         (sigma ???)) ?) ?);
     2060 >EQ whd in match eq_rect_Type0_r; normalize nodelta
    20662061 >execute_1_pseudo_instruction_preserves_code_memory normalize nodelta
    2067  generalize in match EQ -EQ;
    2068  generalize in match (refl … (code_memory pseudo_assembly_program ps))
    2069  generalize in match pol -pol; generalize in ⊢ (∀_.??%? → ?)
    2070  * #preamble #instr_list #pol #EQ1 generalize in match pol -pol <EQ1 #pol #EQps' <EQps'
     2062 generalize in match EQ; -EQ;
     2063 generalize in match (refl … (code_memory pseudo_assembly_program ps));
     2064 generalize in match pol; -pol; generalize in ⊢ (∀_.??%? → ?);
     2065 * #preamble #instr_list #pol #EQ1 generalize in match pol; -pol <EQ1 #pol #EQps' <EQps'
    20712066 (* Dependent types madness ends here *)
    20722067 letin ppc ≝ (program_counter … ps)
    2073  generalize in match (fetch_assembly_pseudo2 ? pol ppc) in ⊢ ?
     2068 generalize in match (fetch_assembly_pseudo2 ? pol ppc) in ⊢ ?;
    20742069 letin assembled ≝ (\fst (assembly ? pol))
    2075  letin lookup_labels ≝ (λx. sigma ? pol (address_of_word_labels_code_mem instr_list x))
    2076  letin lookup_datalabels ≝ (λx. lookup … x (construct_datalabels preamble) (zero 16))
    2077  @pair_elim' #pi #newppc #EQ2
     2070 letin lookup_labels ≝ (λx.(address_of_word_labels_code_mem instr_list x))
     2071 letin lookup_datalabels ≝ (λx. lookup_def … (construct_datalabels preamble) x (zero 16))
     2072 @pair_elim #pi #newppc #EQ2
    20782073 letin instructions ≝
    2079   (expand_pseudo_instruction ? pol ppc lookup_labels lookup_datalabels
    2080     (sigma ? pol ppc) (refl …) (refl …) (refl …))
    2081  change with (fetch_many ???? → ?) #H1
    2082  change in EQ2 with (fetch_pseudo_instruction instr_list ppc = ?)
    2083  change in SAFE with (next_internal_pseudo_address_map0 ???? = ?) <EQ1 in SAFE;
    2084  >EQ2 whd in ⊢ (??(??%??)? → ?) #SAFE
     2074  (expand_pseudo_instruction lookup_labels ppc ((pi1 ?? pol) lookup_labels ppc) lookup_datalabels
     2075    pi)
     2076 change with (fetch_many ???? → ?); #H1
     2077 change with (fetch_pseudo_instruction instr_list ppc = ?) in EQ2;
     2078 change with (next_internal_pseudo_address_map0 ???? = ?) in SAFE; <EQ1 in SAFE;
     2079 >EQ2 whd in ⊢ (??(??%??)? → ?); #SAFE
    20852080 whd in EQps':(???%); <EQ1 in EQps'; >EQ2 normalize nodelta
    2086  generalize in match H1; -H1; generalize in match instructions -instructions
    2087  * #instructions >EQ2 change in match (\fst 〈pi,newppc〉) with pi
    2088  whd in match ticks_of normalize nodelta <EQ1 >EQ2
    2089  cases pi in SAFE
    2090   [2,3: (* Comment, Cost *) #ARG whd in ⊢ (??%? → ???% → ?)
     2081 generalize in match H1; -H1; generalize in match instructions; -instructions
     2082 * #instructions >EQ2 change with pi in match (\fst 〈pi,newppc〉);
     2083 whd in match ticks_of; normalize nodelta <EQ1 >EQ2
     2084 cases pi in SAFE;
     2085  [2,3: (* Comment, Cost *) #ARG whd in ⊢ (??%? → ???% → ?);
    20912086   @Some_Some_elim #MAP #EQ3 @(Some_Some_elim ????? EQ3) #EQ3'
    20922087   whd in match eject normalize nodelta >EQ3' in ⊢ (% → ?) whd in ⊢ (% → ?)
Note: See TracChangeset for help on using the changeset viewer.