Skip to content

Commit 187c175

Browse files
committed
---
yaml --- r: 687 b: refs/heads/master c: 5536af3 h: refs/heads/master i: 685: 53f7ad4 683: 815222d 679: da14c95 671: bb43bf5 v: v3
1 parent a6ceaf6 commit 187c175

File tree

6 files changed

+119
-3
lines changed

6 files changed

+119
-3
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: bc03c82c79f4f970eb183cc40eb89f687f8853f5
2+
refs/heads/master: 5536af3d48da5176bf4b473b54cb6b060c6eee68

trunk/src/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ BE_MLS := $(addprefix boot/be/, x86.ml ra.ml pe.ml elf.ml \
233233
macho.ml)
234234
IL_MLS := $(addprefix boot/be/, asm.ml il.ml abi.ml)
235235
ME_MLS := $(addprefix boot/me/, walk.ml semant.ml resolve.ml alias.ml \
236-
type.ml dead.ml effect.ml typestate.ml loop.ml layout.ml \
237-
transutil.ml trans.ml dwarf.ml)
236+
simplify.ml type.ml dead.ml effect.ml typestate.ml loop.ml \
237+
layout.ml transutil.ml trans.ml dwarf.ml)
238238
FE_MLS := $(addprefix boot/fe/, ast.ml token.ml lexer.ml parser.ml pexp.ml \
239239
item.ml cexp.ml fuzz.ml)
240240
DRIVER_TOP_MLS := $(addprefix boot/driver/, lib.ml $(VARIANT)/glue.ml main.ml)

trunk/src/boot/driver/llvm/glue.ml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let alt_pipeline sess sem_cx crate =
1515
Array.iter process
1616
[|
1717
Resolve.process_crate;
18+
Simplify.process_crate;
1819
Type.process_crate;
1920
Typestate.process_crate;
2021
Effect.process_crate;

trunk/src/boot/driver/main.ml

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let (sess:Session.sess) =
3434
Session.sess_log_ast = false;
3535
Session.sess_log_resolve = false;
3636
Session.sess_log_type = false;
37+
Session.sess_log_simplify = false;
3738
Session.sess_log_effect = false;
3839
Session.sess_log_typestate = false;
3940
Session.sess_log_loop = false;
@@ -162,6 +163,8 @@ let argspecs =
162163
"-lresolve" "log resolution");
163164
(flag (fun _ -> sess.Session.sess_log_type <- true)
164165
"-ltype" "log type checking");
166+
(flag (fun _ -> sess.Session.sess_log_simplify <- true)
167+
"-lsimplify" "log simplification");
165168
(flag (fun _ -> sess.Session.sess_log_effect <- true)
166169
"-leffect" "log effect checking");
167170
(flag (fun _ -> sess.Session.sess_log_typestate <- true)
@@ -352,6 +355,7 @@ let main_pipeline _ =
352355
proc sem_cx crate;
353356
exit_if_failed ())
354357
[| Resolve.process_crate;
358+
Simplify.process_crate;
355359
Type.process_crate;
356360
Typestate.process_crate;
357361
Effect.process_crate;

trunk/src/boot/driver/session.ml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type sess =
2020
mutable sess_log_ast: bool;
2121
mutable sess_log_resolve: bool;
2222
mutable sess_log_type: bool;
23+
mutable sess_log_simplify: bool;
2324
mutable sess_log_effect: bool;
2425
mutable sess_log_typestate: bool;
2526
mutable sess_log_dead: bool;

trunk/src/boot/me/simplify.ml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
open Common;;
2+
open Semant;;
3+
4+
let log cx =
5+
Session.log
6+
"simplify"
7+
cx.Semant.ctxt_sess.Session.sess_log_simplify
8+
cx.Semant.ctxt_sess.Session.sess_log_out
9+
10+
let iflog cx thunk =
11+
if cx.Semant.ctxt_sess.Session.sess_log_simplify
12+
then thunk ()
13+
else ()
14+
;;
15+
16+
17+
let plval_const_marking_visitor
18+
(cx:Semant.ctxt)
19+
(inner:Walk.visitor)
20+
: Walk.visitor =
21+
let visit_pexp_pre pexp =
22+
begin
23+
match pexp.node with
24+
Ast.PEXP_lval pl ->
25+
begin
26+
let id = lval_base_id_to_defn_base_id cx pexp.id in
27+
let is_const =
28+
if defn_id_is_item cx id
29+
then match (get_item cx id).Ast.decl_item with
30+
Ast.MOD_ITEM_const _ -> true
31+
| _ -> false
32+
else false
33+
in
34+
iflog cx (fun _ -> log cx "plval %a refers to %s"
35+
Ast.sprintf_plval pl
36+
(if is_const then "const item" else "non-const"));
37+
htab_put cx.ctxt_plval_const pexp.id is_const
38+
end
39+
| _ -> ()
40+
end;
41+
inner.Walk.visit_pexp_pre pexp
42+
in
43+
44+
let visit_pexp_post p =
45+
inner.Walk.visit_pexp_post p;
46+
iflog cx (fun _ -> log cx "pexp %a is %s"
47+
Ast.sprintf_pexp p
48+
(if pexp_is_const cx p
49+
then "constant"
50+
else "non-constant"))
51+
in
52+
53+
{ inner with
54+
Walk.visit_pexp_pre = visit_pexp_pre;
55+
Walk.visit_pexp_post = visit_pexp_post;
56+
}
57+
;;
58+
59+
60+
let pexp_simplifying_visitor
61+
(_:Semant.ctxt)
62+
(inner:Walk.visitor)
63+
: Walk.visitor =
64+
65+
let walk_atom at =
66+
match at with
67+
Ast.ATOM_pexp _ ->
68+
begin
69+
(* FIXME: move desugaring code from frontend to here. *)
70+
()
71+
end
72+
| _ -> ()
73+
in
74+
75+
let visit_stmt_pre s =
76+
begin
77+
match s.node with
78+
Ast.STMT_copy (_, Ast.EXPR_atom a) -> walk_atom a
79+
| _ -> ()
80+
end;
81+
inner.Walk.visit_stmt_pre s;
82+
in
83+
{ inner with
84+
Walk.visit_stmt_pre = visit_stmt_pre;
85+
}
86+
;;
87+
88+
89+
let process_crate (cx:Semant.ctxt) (crate:Ast.crate) : unit =
90+
let path = Stack.create () in
91+
92+
let passes =
93+
[|
94+
(plval_const_marking_visitor cx Walk.empty_visitor);
95+
(pexp_simplifying_visitor cx Walk.empty_visitor)
96+
|]
97+
in
98+
let log_flag = cx.Semant.ctxt_sess.Session.sess_log_simplify in
99+
Semant.run_passes cx "simplify" path passes log_flag log crate
100+
;;
101+
102+
(*
103+
* Local Variables:
104+
* fill-column: 78;
105+
* indent-tabs-mode: nil
106+
* buffer-file-coding-system: utf-8-unix
107+
* compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
108+
* End:
109+
*)
110+

0 commit comments

Comments
 (0)