@@ -100,16 +100,26 @@ Definition parse_label : ParserAction string
100
100
(fun '(char, ls) => string_of_list_ascii (char :: ls))
101
101
(([a-zA-Z] || parse_any_ascii "._?$") ;;
102
102
(([a-zA-Z] || parse_any_ascii "0123456789_$#@~.?")* )).
103
+ Definition parse_non_access_size_label : ParserAction string
104
+ := parse_lookahead_not parse_AccessSize ;;R parse_label.
103
105
104
106
Definition parse_MEM : ParserAction MEM
105
- := parse_map
106
- (fun '(access_size, (br (*base reg *) , sr (*scale reg, including z *) , offset, base_label))
107
- => {| mem_bits_access_size := access_size:option AccessSize
108
- ; mem_base_reg := br:option REG
109
- ; mem_base_label := base_label
110
- ; mem_scale_reg := sr:option (Z * REG)
111
- ; mem_offset := offset:option Z |})
107
+ := parse_option_list_map
108
+ (fun '(access_size, (constant_location_label, (br (*base reg *) , sr (*scale reg, including z *) , offset, base_label)))
109
+ => match base_label, constant_location_label with
110
+ | Some _, Some _ => (* invalid? *) None
111
+ | Some _ as lbl, None
112
+ | None, Some _ as lbl
113
+ | None, None as lbl =>
114
+ Some
115
+ {| mem_bits_access_size := access_size:option AccessSize
116
+ ; mem_base_reg := br:option REG
117
+ ; mem_base_label := lbl
118
+ ; mem_scale_reg := sr:option (Z * REG)
119
+ ; mem_offset := offset:option Z |}
120
+ end )
112
121
(((strip_whitespace_after parse_AccessSize)?) ;;
122
+ (parse_non_access_size_label?) ;;
113
123
(parse_option_list_map
114
124
(fun '(offset, vars)
115
125
=> (vars <-- List.map (fun '(c, (v, e), vs) => match vs, e with [], 1%Z => Some (c, v) | _, _ => None end ) vars;
@@ -160,7 +170,8 @@ Definition parse_OpCode_list : list (string * OpCode)
160
170
:= Eval vm_compute in
161
171
List.map
162
172
(fun r => (show r, r))
163
- (list_all OpCode).
173
+ (list_all OpCode)
174
+ ++ [(".quad", dq); (".word", dw); (".byte", db)].
164
175
165
176
Definition parse_OpCode : ParserAction OpCode
166
177
:= parse_strs_case_insensitive parse_OpCode_list.
@@ -254,7 +265,14 @@ Global Instance show_lvl_MEM : ShowLevel MEM
254
265
:= fun m
255
266
=> (match m.(mem_bits_access_size) with
256
267
| Some n
257
- => show_lvl_app (fun 'tt => if n =? 8 then "byte" else if n =? 64 then "QWORD PTR" else "BAD SIZE")%N (* TODO: Fix casing and stuff *)
268
+ => show_lvl_app (fun 'tt => if n =? 8 then "byte"
269
+ else if n =? 16 then "word"
270
+ else if n =? 32 then "dword"
271
+ else if n =? 64 then "QWORD PTR"
272
+ else if n =? 128 then "XMMWORD PTR"
273
+ else if n =? 256 then "YMMWORD PTR"
274
+ else if n =? 512 then "ZMMWORD PTR"
275
+ else "BAD SIZE")%N (* TODO: Fix casing and stuff *)
258
276
| None => show_lvl
259
277
end )
260
278
(fun 'tt
@@ -275,11 +293,21 @@ Global Instance show_lvl_MEM : ShowLevel MEM
275
293
then "0x08 * " ++ Decimal.show_Z (offset / 8)
276
294
else Hex.show_Z offset)
277
295
end %Z) in
278
- "[" ++ match m.(mem_base_label) with
279
- | None => reg_part ++ offset_part
280
- | Some l => "((" ++ l ++ offset_part ++ "))"
281
- end
282
- ++ "]").
296
+ match m.(mem_base_label), m.(mem_base_reg), m.(mem_offset), m.(mem_scale_reg) with
297
+ | Some lbl, Some rip, None, None => lbl ++ "[" ++ reg_part ++ offset_part ++ "]"
298
+ | Some lbl, _, _, _ => let l_offset := lbl ++ offset_part in
299
+ "[" ++
300
+ (if reg_part =? ""
301
+ then "((" ++ l_offset ++ "))"
302
+ else reg_part ++ " + " ++ l_offset)
303
+ ++ "]"
304
+ | None, _, _, _ =>
305
+ "[" ++
306
+ (if reg_part =? ""
307
+ then "((" ++ offset_part ++ "))"
308
+ else reg_part ++ " + " ++ offset_part)
309
+ ++ "]"
310
+ end ).
283
311
Global Instance show_MEM : Show MEM := show_lvl_MEM.
284
312
285
313
Global Instance show_lvl_JUMP_LABEL : ShowLevel JUMP_LABEL
0 commit comments