From 723a99b56c54f8c365310bd3a94c56a08f6f68ed Mon Sep 17 00:00:00 2001 From: Eric Lippert Date: Tue, 21 Feb 2017 15:38:35 -0800 Subject: [PATCH] Codegen: use CGetL2 in binary operations Summary: Make use of the instruction `CGetL2` that pulls a local into the stack just below the top-of-stack. Also fix output of function names Reviewed By: oulgen Differential Revision: D4575856 fbshipit-source-id: 1cc33b7693df0841f9c2cfefa199bdc959b1f956 --- hphp/hack/src/hhbc/hhbc_from_nast.ml | 5 ++++- hphp/hack/src/hhbc/hhbc_hhas.ml | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hphp/hack/src/hhbc/hhbc_from_nast.ml b/hphp/hack/src/hhbc/hhbc_from_nast.ml index 41bc90bbdc5..dea007e1101 100644 --- a/hphp/hack/src/hhbc/hhbc_from_nast.ml +++ b/hphp/hack/src/hhbc/hhbc_from_nast.ml @@ -110,6 +110,9 @@ let rec from_expr expr = emit_unop op e | A.Binop (A.Eq obop, e1, e2) -> emit_assignment obop e1 e2 + (* Special case to make use of CGetL2 *) + | A.Binop (op, (_, A.Lvar (_, x)), e) -> + gather [from_expr e; instr (IGet (CGetL2 (Local_named x))); from_binop op] | A.Binop (op, e1, e2) -> gather [from_expr e2; from_expr e1; from_binop op] | A.Eif (etest, Some etrue, efalse) -> @@ -137,7 +140,7 @@ let rec from_expr expr = | A.Call ((_, A.Id (_, id)), el, []) when id = "echo" -> gather [ from_exprs el; - instr H.(IOp Print); + instr (IOp Print); ] (* TODO: emit warning *) | _ -> empty diff --git a/hphp/hack/src/hhbc/hhbc_hhas.ml b/hphp/hack/src/hhbc/hhbc_hhas.ml index 7cd11abb329..a8274fd88c6 100644 --- a/hphp/hack/src/hhbc/hhbc_hhas.ml +++ b/hphp/hack/src/hhbc/hhbc_hhas.ml @@ -258,8 +258,18 @@ let string_of_param p = let string_of_params ps = "(" ^ String.concat ", " (List.map string_of_param ps) ^ ")" +(* Taken from emitter/emitter_core.ml *) +let fix_xhp_name s = + if String.length s = 0 || s.[0] <> ':' then s else + "xhp_" ^ + String_utils.lstrip s ":" |> + Str.global_replace (Str.regexp ":") "__" |> + Str.global_replace (Str.regexp "-") "_" + +let fmt_name s = fix_xhp_name (Utils.strip_ns s) + let add_fun_def buf fun_def = - let function_name = Hhas_function.name fun_def in + let function_name = fmt_name (Hhas_function.name fun_def) in let function_return_type = Hhas_function.return_type fun_def in let function_params = Hhas_function.params fun_def in let function_body = Hhas_function.body fun_def in -- 2.11.4.GIT