Skip to content
Snippets Groups Projects
Commit 926ed3c7 authored by Nishant Kumar's avatar Nishant Kumar
Browse files

Updated ezpc.h for output queue elements.

parent 87212653
No related branches found
No related tags found
No related merge requests found
......@@ -67,11 +67,15 @@ share* arithmetic_right_shift(Circuit* c, share* val, uint32_t shift_factor) {
* and adds the returned share to this queue
* this queue is then flushed at the end after we have done exec
*/
struct output_queue_elmt {
share *ptr;
e_role role; //who should we output the clear value to
ostream& os; //output stream to which we will output (cout or files), can this be a reference to prevent copying?
e_role role; //who should we output the clear value to
enum {PrintMsg, PrintValue } kind;
string msg;
share *ptr;
};
typedef vector<output_queue_elmt> output_queue;
/*
* called from the EzPC generated code
......@@ -81,9 +85,16 @@ void add_to_output_queue(output_queue &q,
e_role role,
ostream &os)
{
struct output_queue_elmt elmt { ptr, role, os };
struct output_queue_elmt elmt { os, role, output_queue_elmt::PrintValue, "", ptr };
q.push_back(elmt);
}
void add_print_msg_to_output_queue (output_queue &q, string msg, e_role role, ostream &os)
{
struct output_queue_elmt elmt { os, role, output_queue_elmt::PrintMsg, msg, NULL };
q.push_back(elmt);
}
/*
* flush the queue
* both parties call this function with their role
......@@ -92,11 +103,17 @@ void add_to_output_queue(output_queue &q,
void flush_output_queue(output_queue &q, e_role role, uint32_t bitlen)
{
for(output_queue::iterator it = q.begin(); it != q.end(); ++it) { //iterate over the queue
if(it->role == ALL || it->role == role) { //if the queue element role is same as mine
if(bitlen == 32) { //output to the stream
it->os << it->ptr->get_clear_value<uint32_t>() << endl;
} else {
it->os << it->ptr->get_clear_value<uint64_t>() << endl;
if (it->kind == output_queue_elmt::PrintValue) {
if(it->role == ALL || it->role == role) { //if the queue element role is same as mine
if(bitlen == 32) { //output to the stream
it->os << it->ptr->get_clear_value<uint32_t>() << endl;
} else {
it->os << it->ptr->get_clear_value<uint64_t>() << endl;
}
}
} else {
if(it->role == ALL || it->role == role) { //if the queue element role is same as mine
it->os << it->msg << endl;
}
}
}
......
......@@ -422,8 +422,22 @@ let rec o_stmt (g:gamma) (s:stmt) :comp * gamma =
| Output (e_role, e, Some t) when is_role e_role ->
let r = get_role e_role in
let bt, l = get_bt_and_label t in
if not (l |> get_opt |> is_secret_label) then o_codegen_stmt g (Cout ("cout", Base_e e, bt))
if not (l |> get_opt |> is_secret_label) then
let print_output_msg =
let msg = Var { name = "\"Value of " ^ (expr_to_string e) ^ ":\""; index = 0 } |> mk_dsyntax "" in
Cout ("cout", Base_e msg, bt)
in
o_codegen_stmt g (Seq_codegen (print_output_msg, Cout ("cout", Base_e e, bt)))
else
let print_output_msg =
let msg = Var { name = "\"Value of " ^ (expr_to_string e) ^ ":\""; index = 0 } |> mk_dsyntax "" in
App_codegen ("add_print_msg_to_output_queue", [Base_e (Var { name = "out_q"; index = 0 } |> mk_dsyntax "");
Base_e msg;
Base_e e_role;
Base_e (Var { name = "cout"; index = 0 } |> mk_dsyntax "")])
in
let is_arr = is_array_typ t in
(* bt is the base type and sl is the secret label *)
......@@ -462,7 +476,7 @@ let rec o_stmt (g:gamma) (s:stmt) :comp * gamma =
Base_e (Var { name = "cout"; index = 0 } |> mk_dsyntax "")]))
in
o_codegen_stmt g output_gate_loops
o_codegen_stmt g (Seq_codegen (print_output_msg, output_gate_loops))
| Skip s -> (if s = "" then o_null else seq o_newline (seq (o_comment s) o_newline)), g
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment