Skip to content

Commit e406662

Browse files
committed
-||-
1 parent a6fba3c commit e406662

File tree

1 file changed

+72
-68
lines changed

1 file changed

+72
-68
lines changed

src/X86.ml

+72-68
Original file line numberDiff line numberDiff line change
@@ -344,31 +344,35 @@ let compile cmd env imports code =
344344
( env'#push y,
345345
(* Dynamic check that cmp operators has correct argument types (numbers or pointers) *)
346346
(match op with
347-
| "==" | "!=" -> [ ]
348-
|"<" | "<=" | ">=" | ">" ->
349-
[Push (eax);
350-
Push (edx);
351-
Mov (y, eax);
352-
Binop("&&", L(1), eax);
353-
Mov (x, edx);
354-
Binop("&&", L(1), edx);
355-
Binop("cmp", eax, edx);
356-
CJmp ("nz", "_ERROR2");
357-
Pop (edx);
358-
Pop (eax)]
359-
(* | "+" | "-" | "*" | "/" -> *)
360-
| _ -> (* Forbid pointer arithmetics *)
361-
[Mov (y, eax);
362-
Binop("&&", L(1), eax);
363-
Binop("cmp", L(0), eax);
364-
CJmp ("z", "_ERROR");
365-
Mov (x, eax);
366-
Binop("&&", L(1), eax);
367-
Binop("cmp", L(0), eax);
368-
CJmp ("z", "_ERROR")]
369-
)
370-
(* END: dynamic check *)
371-
@
347+
| "==" | "!=" -> []
348+
| "<" | "<=" | ">=" | ">" ->
349+
[
350+
Push eax;
351+
Push edx;
352+
Mov (y, eax);
353+
Binop ("&&", L 1, eax);
354+
Mov (x, edx);
355+
Binop ("&&", L 1, edx);
356+
Binop ("cmp", eax, edx);
357+
(* CJmp ("nz", "_ERROR2"); *)
358+
Pop edx;
359+
Pop eax;
360+
]
361+
(* | "+" | "-" | "*" | "/" -> *)
362+
| _ ->
363+
(* Forbid pointer arithmetics *)
364+
[
365+
Mov (y, eax);
366+
Binop ("&&", L 1, eax);
367+
Binop ("cmp", L 0, eax);
368+
CJmp ("z", "_ERROR");
369+
Mov (x, eax);
370+
Binop ("&&", L 1, eax);
371+
Binop ("cmp", L 0, eax);
372+
CJmp ("z", "_ERROR");
373+
])
374+
(* END: dynamic check *)
375+
@
372376
match op with
373377
| "/" ->
374378
[
@@ -501,11 +505,11 @@ let compile cmd env imports code =
501505
in
502506
names
503507
@ (if names = [] then []
504-
else
505-
[
506-
Meta
507-
(Printf.sprintf "\t.stabn 192,0,0,%s-%s" scope.blab f);
508-
])
508+
else
509+
[
510+
Meta
511+
(Printf.sprintf "\t.stabn 192,0,0,%s-%s" scope.blab f);
512+
])
509513
@ (List.flatten @@ List.map stabs_scope scope.subs)
510514
@
511515
if names = [] then []
@@ -525,38 +529,38 @@ let compile cmd env imports code =
525529
( env,
526530
[ Meta (Printf.sprintf "\t.type %s, @function" name) ]
527531
@ (if f = "main" then []
528-
else
529-
[
530-
Meta
531-
(Printf.sprintf "\t.stabs \"%s:F1\",36,0,0,%s" name f);
532-
]
533-
@ List.mapi
534-
(fun i a ->
535-
Meta
536-
(Printf.sprintf "\t.stabs \"%s:p1\",160,0,0,%d" a
537-
((i * 4) + 8)))
538-
args
539-
@ List.flatten
540-
@@ List.map stabs_scope scopes)
532+
else
533+
[
534+
Meta
535+
(Printf.sprintf "\t.stabs \"%s:F1\",36,0,0,%s" name f);
536+
]
537+
@ List.mapi
538+
(fun i a ->
539+
Meta
540+
(Printf.sprintf "\t.stabs \"%s:p1\",160,0,0,%d" a
541+
((i * 4) + 8)))
542+
args
543+
@ List.flatten
544+
@@ List.map stabs_scope scopes)
541545
@ [ Meta "\t.cfi_startproc" ]
542546
@ (if has_closure then [ Push edx ] else [])
543547
(* TODO: WTF ?!? *)
544548
@ (if f = cmd#topname then
545-
[
546-
Mov (M "_init", eax);
547-
Binop ("test", eax, eax);
548-
CJmp ("z", "_continue");
549-
Ret;
550-
Label "_ERROR";
551-
Call "Lbinoperror";
552-
Ret;
553-
Label "_ERROR2";
554-
Call "Lbinoperror2";
555-
Ret;
556-
Label "_continue";
557-
Mov (L 1, M "_init");
558-
]
559-
else [])
549+
[
550+
Mov (M "_init", eax);
551+
Binop ("test", eax, eax);
552+
CJmp ("z", "_continue");
553+
Ret;
554+
Label "_ERROR";
555+
Call "Lbinoperror";
556+
Ret;
557+
Label "_ERROR2";
558+
Call "Lbinoperror2";
559+
Ret;
560+
Label "_continue";
561+
Mov (L 1, M "_init");
562+
]
563+
else [])
560564
@ [
561565
Push ebp;
562566
Meta
@@ -574,14 +578,14 @@ let compile cmd env imports code =
574578
Repmovsl;
575579
]
576580
@ (if f = "main" then
577-
[
578-
Call "__gc_init";
579-
Push (I (12, ebp));
580-
Push (I (8, ebp));
581-
Call "set_args";
582-
Binop ("+", L 8, esp);
583-
]
584-
else [])
581+
[
582+
Call "__gc_init";
583+
Push (I (12, ebp));
584+
Push (I (8, ebp));
585+
Call "set_args";
586+
Binop ("+", L 8, esp);
587+
]
588+
else [])
585589
@
586590
if f = cmd#topname then
587591
List.map
@@ -904,8 +908,8 @@ class env prg =
904908
[ Meta (Printf.sprintf "\t.stabn 68,0,%d,%s" line lab); Label lab ]
905909
else
906910
(if first_line then
907-
[ Meta (Printf.sprintf "\t.stabn 68,0,%d,0" line) ]
908-
else [])
911+
[ Meta (Printf.sprintf "\t.stabn 68,0,%d,0" line) ]
912+
else [])
909913
@ [
910914
Meta (Printf.sprintf "\t.stabn 68,0,%d,%s-%s" line lab fname);
911915
Label lab;

0 commit comments

Comments
 (0)