diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-01-08 18:31:56 +0100 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2014-01-08 18:31:56 +0100 |
commit | e07508129a81605f77ee410ef4db104a96fc44bf (patch) | |
tree | 670472f86292f07d8930d986727d5e9ce87ff1ad /asm/asmpars.mly | |
parent | 1f228ce77e8a71475930b433fb2c72521203aa99 (diff) | |
parent | 91bc6bd5554bb4267cbaf147e603791e50462242 (diff) | |
download | SystDigit-Projet-e07508129a81605f77ee410ef4db104a96fc44bf.tar.gz SystDigit-Projet-e07508129a81605f77ee410ef4db104a96fc44bf.zip |
Merge branch 'emile' into integration-progressive
Conflicts:
asm/_tags
asm/asmlex.mll
asm/asmpars.mly
asm/assembler.ml
Diffstat (limited to 'asm/asmpars.mly')
-rw-r--r-- | asm/asmpars.mly | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/asm/asmpars.mly b/asm/asmpars.mly index ebc4ae7..46ca7a7 100644 --- a/asm/asmpars.mly +++ b/asm/asmpars.mly @@ -15,27 +15,22 @@ let pc = ref 0 - let ram = ref 0x8000 + let ram = ref 0 let add r i = r := !r + i let lbls2 = ref (Imap.empty) - let li u r = function - | Imm i -> - let c = - if u then i < 1 lsl 8 - else i >= -(1 lsl 7) && i < 1 lsl 7 in - if c then (add pc 2; [Lilz (r,Imm i)]) - else (add pc 4; [Lilz (r,Imm (i land 0x00FF)); Liu (r,Imm ((i land 0xFF00) lsr 8))]) - | Lab id -> - add pc 4; [Lilz (r,Lab id); Liu (r,Labu id)] - | _ -> assert false + let li u r = function + | Imm i -> + let c = + if u then i < 1 lsl 8 + else i >= -(1 lsl 7) && i < 1 lsl 7 in + if c then (add pc 2; [Lilz (r,Imm i)]) + else (add pc 4; [Lilz (r,Imm (i land 0x00FF)); Liu (r,Imm ((i land 0xFF00) lsr 8))]) + | Lab id -> + add pc 4; [Lilz (r,Lab id); Liu (r,Lab id)] - let up = function - | Imm i -> Imm i - | Lab l -> Labu l - | _ -> assert false let explode s = (* string -> char list *) let rec exp i l = @@ -65,23 +60,20 @@ data: DATA d=datas* { d } datas: - | l=label_ram d=datas { d } - | BYTE bs=int* { List.map (fun i -> add ram 1; i,false) bs } - | WORD bs=int* { List.map (fun i -> add ram 2; i,true) bs } - | ASCIIZ s=STR { - add ram 1; - List.map (fun c -> add ram 1; Char.code c, false) (explode s) @ [0, false] - } - -label_ram: - id=ID COLON { lbls2 := Imap.add id !ram !lbls2; id } -label_pc: - id=ID COLON { lbls2 := Imap.add id !pc !lbls2; id } - + | labeld d=datas { d } + | BYTE bs=int* { List.map (fun i -> add ram 1; i,false) bs } + | WORD bs=int* { List.map (fun i -> add ram 2; i,true) bs } + +labeli: + id=ID COLON { lbls2 := Imap.add id (!pc,true) !lbls2 } + +labeld: + id=ID COLON { lbls2 := Imap.add id (!ram,false) !lbls2 } + instr: - | l=label_pc i=instr { i } - | i=_instr { i } - + | labeli i=instr { i } + | i=_instr { i } + _instr: | o=ROP r1=REG r2=REG r3=REG { add pc 2; [R (o,r1,r2,r3)] } | o=RIOP r1=REG r2=REG imm=imm |