diff --git a/lib/Constant.ml b/lib/Constant.ml index 7dbe7ec4..89ff139a 100644 --- a/lib/Constant.ml +++ b/lib/Constant.ml @@ -28,6 +28,7 @@ let bytes_of_width (w: width) = type op = (* Arithmetic operations *) | Add | AddW | Sub | SubW | Div | DivW | Mult | MultW | Mod + | Neg (* Bitwise operations *) | BOr | BAnd | BXor | BShiftL | BShiftR | BNot (* Arithmetic comparisons / boolean comparisons *) diff --git a/lib/Helpers.ml b/lib/Helpers.ml index 969f803b..8e14d561 100644 --- a/lib/Helpers.ml +++ b/lib/Helpers.ml @@ -45,7 +45,7 @@ let type_of_op op w = TArrow (TBool, TArrow (TBool, TBool)) | Not -> TArrow (TBool, TBool) - | BNot -> + | BNot | Neg -> TArrow (TInt w, TInt w) | Assign | PreIncr | PreDecr | PostIncr | PostDecr | Comma -> invalid_arg "type_of_op" diff --git a/lib/PrintC.ml b/lib/PrintC.ml index 018a79f6..905c7752 100644 --- a/lib/PrintC.ml +++ b/lib/PrintC.ml @@ -129,7 +129,7 @@ and p_type_name (qs, spec, decl) = | _ -> p_qualifiers_break qs ^^ p_type_spec spec ^^ space ^^ p_type_declarator decl -(* http:/ /en.cppreference.com/w/c/language/operator_precedence *) +(* http://en.cppreference.com/w/c/language/operator_precedence *) and prec_of_op2 op = let open Constant in match op with @@ -151,12 +151,12 @@ and prec_of_op2 op = | Or -> 12, 12, 12 | Assign -> 14, 13, 14 | Comma -> 15, 15, 14 - | PreIncr | PostIncr | PreDecr | PostDecr | Not | BNot -> raise (Invalid_argument "prec_of_op2") + | PreIncr | PostIncr | PreDecr | PostDecr | Not | BNot | Neg -> raise (Invalid_argument "prec_of_op2") and prec_of_op1 op = let open Constant in match op with - | PreDecr | PreIncr | Not | BNot -> 2 + | PreDecr | PreIncr | Not | BNot | Neg -> 2 | PostDecr | PostIncr -> 1 | _ -> raise (Invalid_argument "prec_of_op1") diff --git a/lib/PrintCommon.ml b/lib/PrintCommon.ml index 41b3b6fb..2951a1a3 100644 --- a/lib/PrintCommon.ml +++ b/lib/PrintCommon.ml @@ -69,6 +69,7 @@ let print_op = function | PostDecr | PreDecr -> string "--" | Assign -> string "=" | Comma -> string "," + | Neg -> string "-" let print_cc = function | CDecl -> string "__cdecl"