Skip to content

Commit ca6d709

Browse files
committed
Emitter Plugin for Edger8r.
CodeGen.ml checks whether a plugin is available and if so, invoked the plugin to emit edge routines. Signed-off-by: Anand Krishnamoorthi <[email protected]>
1 parent a169a69 commit ca6d709

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

sdk/edger8r/linux/Ast.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ type enclave = {
191191
eexpr : expr list; (* expressions inside enclave. *)
192192
}
193193

194+
(*
195+
Plugin.ml operates on an enclave_content instance.
196+
CodeGen.ml calls Plugin.ml if a plugin is installed and hence
197+
depends on Plugin.ml.
198+
To prevent cyclic dependency between Plugin.ml and Codegen.ml,
199+
enclave_content is defined here. Additionally, the enclave_content
200+
type in CodeGen.ml is defined to be equivalent to the enclave_content
201+
type defined here.
202+
*)
203+
type enclave_content = {
204+
file_shortnm : string; (* the short name of original EDL file *)
205+
enclave_name : string; (* the normalized C identifier *)
206+
207+
include_list : string list;
208+
import_exprs : import_decl list;
209+
comp_defs : composite_type list;
210+
tfunc_decls : trusted_func list;
211+
ufunc_decls : untrusted_func list;
212+
}
213+
194214
(* -------------------------------------------------------------------
195215
* Some utility function to manupulate types defined in AST.
196216
* -------------------------------------------------------------------

sdk/edger8r/linux/CodeGen.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ open Util (* for failwithf *)
3939
*)
4040

4141
(* This record type is used to better organize a value of Ast.enclave *)
42-
type enclave_content = {
42+
type enclave_content = Ast.enclave_content = {
4343
file_shortnm : string; (* the short name of original EDL file *)
4444
enclave_name : string; (* the normalized C identifier *)
4545

@@ -1714,5 +1714,9 @@ let gen_enclave_code (e: Ast.enclave) (ep: edger8r_params) =
17141714
check_duplication ec;
17151715
check_allow_list ec;
17161716
(if not ep.header_only then check_priv_funcs ec);
1717-
(if ep.gen_untrusted then (gen_untrusted_header ec; if not ep.header_only then gen_untrusted_source ec));
1718-
(if ep.gen_trusted then (gen_trusted_header ec; if not ep.header_only then gen_trusted_source ec))
1717+
if Plugin.available() then
1718+
Plugin.gen_edge_routines ec ep
1719+
else (
1720+
(if ep.gen_untrusted then (gen_untrusted_header ec; if not ep.header_only then gen_untrusted_source ec));
1721+
(if ep.gen_trusted then (gen_trusted_header ec; if not ep.header_only then gen_trusted_source ec))
1722+
)

sdk/edger8r/linux/Plugin.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(*
2+
Dependency injection plugin to allow custom code generation
3+
from EDL. CodeGen.ml calls into Plugin.available to check
4+
if a plugin available. If a plugin is available, then it calls
5+
Plugin.gen_edge_routines to generate custom code.
6+
Otherwise, it generates code for Intel(R) SGX SDK.
7+
*)
8+
9+
type plugin = {
10+
mutable available: bool;
11+
mutable gen_edge_routines:
12+
Ast.enclave_content -> Util.edger8r_params -> unit;
13+
}
14+
15+
(* Instance fields will be populated by Open Enclave *)
16+
let instance = {
17+
available = false;
18+
gen_edge_routines = fun ec ep -> Printf.printf "Plugin not loaded.\n"
19+
}
20+
21+
let available () = instance.available
22+
let gen_edge_routines ec ep = instance.gen_edge_routines ec ep

0 commit comments

Comments
 (0)