diff --git a/ocaml/parser/common.ml b/ocaml/parser/common.ml index 36cd03b..228f671 100644 --- a/ocaml/parser/common.ml +++ b/ocaml/parser/common.ml @@ -24,12 +24,13 @@ let rec string_of_type typ = | Char -> "char" | Uchar -> "unsigned char" | Int -> "int" + | Uint -> "unsigned int" | Long -> "long" | Ulong -> "unsigned long" | Llong -> "long long" | Ullong -> "unsigned long long" - | Sint w -> "int" ^ string_of_int w - | Uint w -> "uint" ^ string_of_int w + | Sword w -> "int" ^ string_of_int w + | Uword w -> "uint" ^ string_of_int w | Const t -> "const " ^ string_of_type t | Pointer t -> (string_of_type t) ^ " * " | Vector (d, t) -> "vector[" ^ Z.to_string d ^ "] " ^ string_of_type t @@ -63,10 +64,10 @@ let string_of_instr instr = | Or (l, r0, r1) -> l ^ " = " ^ r0 ^ " | " ^ string_of_operand r1 | Rshift (l, r0, r1) -> l ^ " = " ^ r0 ^ " >> " ^ string_of_operand r1 | Lshift (l, r0, r1) -> l ^ " = " ^ r0 ^ " << " ^ string_of_operand r1 - | Load (l, loc) -> l ^ " = MEM[" ^ (string_of_loc loc) ^ "]" - | Store (loc, r) -> "MEM[" ^ (string_of_loc loc) ^ "] = " ^ r - | Vstore (t, loc, r) -> "MEM <" ^ string_of_type t ^ "> [" ^ string_of_loc loc ^ - "] = " ^ r + | Load (l, t, loc) -> l ^ " = MEM <" ^ string_of_type t ^ "> [" ^ + string_of_loc loc ^ "]" + | Store (loc, t, r) -> "MEM <" ^ string_of_type t ^ "> [" ^ + string_of_loc loc ^ "] = " ^ r | Return -> "return" | Wmadd (l, r0, r1, r2) -> l ^ " = WIDEN_MULT_PLUS_EXPR <" ^ r0 ^ ", " ^ r1 ^ ", " ^ r2 diff --git a/ocaml/parser/gimpleLexer.mll b/ocaml/parser/gimpleLexer.mll index 40c8a57..b0961d2 100644 --- a/ocaml/parser/gimpleLexer.mll +++ b/ocaml/parser/gimpleLexer.mll @@ -12,6 +12,7 @@ "char" , CHAR; "int" , INT; "const" , CONST; + "signed" , SIGNED; "unsigned" , UNSIGNED; "long" , LONG; "vector" , VECTOR; diff --git a/ocaml/parser/gimpleParser.mly b/ocaml/parser/gimpleParser.mly index 5402cf3..574b606 100644 --- a/ocaml/parser/gimpleParser.mly +++ b/ocaml/parser/gimpleParser.mly @@ -20,7 +20,7 @@ %token ADDOP SUBOP MULOP WMULOP ANDOP OROP XOROP LSHIFT RSHIFT EQOP %token WMADDOP /* Types */ -%token CONST VOID CHAR INT UNSIGNED LONG VECTOR +%token CONST VOID CHAR INT SIGNED UNSIGNED LONG VECTOR /* Others */ %token ATTRIBUTE ACCESS MEM EOF RETURN LOCAL COUNT BB @@ -41,6 +41,8 @@ funcs: func: attribute typ ID LPAREN parameters RPAREN LBRACK vars instrs RBRACK { { attr = $1; fty = $2; fname = $3; params = $5; vars = $8; instrs = $9 } } +| typ ID LPAREN parameters RPAREN LBRACK vars instrs RBRACK + { { attr = []; fty = $1; fname = $2; params = $4; vars = $7; instrs = $8 } } ; attribute: @@ -50,9 +52,9 @@ attribute: direct_typ: VOID { Void } -| SINT { Sint $1 } -| UINT { Uint $1 } -| UNSIGNED SINT { Uint $2 } +| SINT { Sword $1 } +| UINT { Uword $1 } +| UNSIGNED SINT { Uword $2 } | CONST direct_typ { Const $2 } ; @@ -87,13 +89,16 @@ var: vtyp: | UNSIGNED CHAR { Uchar } +| SIGNED CHAR { Char } | INT { Int } +| UNSIGNED INT { Uint } +| SIGNED INT { Int } | LONG LONG UNSIGNED INT { Ullong } | LONG LONG INT { Llong } | UNSIGNED LONG { Ulong } -| UINT { Uint $1 } -| SINT { Sint $1 } -| SINT UNSIGNED { Uint $1 } +| UINT { Uword $1 } +| SINT { Sword $1 } +| SINT UNSIGNED { Uword $1 } | VECTOR LPAREN NUM RPAREN vtyp { Vector ($3, $5) } ; @@ -122,12 +127,14 @@ instr: | ID EQOP ID LSHIFT ID SEMICOLON { Lshift ($1, $3, Var $5) } | ID EQOP ID LSHIFT NUM SEMICOLON { Lshift ($1, $3, Const $5) } | LANGLE BB NUM RANGLE LSQUARE LOCAL COUNT COLON NUM RSQUARE COLON { Label $3 } -| ID EQOP MULOP loc SEMICOLON { Load ($1, $4) } -| ID EQOP MEM LSQUARE loc RSQUARE SEMICOLON { Load ($1, $5) } -| MULOP loc EQOP ID SEMICOLON { Store ($2, $4) } -| MEM LSQUARE loc RSQUARE EQOP ID SEMICOLON { Store ($3, $6) } +| ID EQOP MULOP loc SEMICOLON { Load ($1, Void, $4) } +| ID EQOP MEM LSQUARE loc RSQUARE SEMICOLON { Load ($1, Void, $5) } +| ID EQOP MEM LANGLE vtyp RANGLE LSQUARE loc RSQUARE SEMICOLON + { Load ($1, $5, $8) } +| MULOP loc EQOP ID SEMICOLON { Store ($2, Void, $4) } +| MEM LSQUARE loc RSQUARE EQOP ID SEMICOLON { Store ($3, Void, $6) } | MEM LANGLE vtyp RANGLE LSQUARE loc RSQUARE EQOP ID SEMICOLON - { Vstore ($3, $6, $9) } + { Store ($6, $3, $9) } | ID EQOP WMADDOP LANGLE ID COMMA ID COMMA ID RANGLE SEMICOLON { Wmadd ($1, $5, $7, $9) } | RETURN SEMICOLON { Return } diff --git a/ocaml/parser/syntax.ml b/ocaml/parser/syntax.ml index 9db5342..01fc231 100644 --- a/ocaml/parser/syntax.ml +++ b/ocaml/parser/syntax.ml @@ -3,8 +3,8 @@ type access_t = string type attribute_t = access_t list -type type_t = Void | Char | Uchar | Int | Long | Ulong | Llong | Ullong - | Sint of int | Uint of int +type type_t = Void | Char | Uchar | Int | Uint | Long | Ulong | Llong | Ullong + | Sword of int | Uword of int | Const of type_t | Pointer of type_t | Vector of Z.t * type_t @@ -29,9 +29,8 @@ type instr_t = Label of Z.t | Or of id_t * id_t * operand_t | Rshift of id_t * id_t * operand_t | Lshift of id_t * id_t * operand_t - | Load of id_t * loc_t - | Store of loc_t * id_t - | Vstore of type_t * loc_t * id_t + | Load of id_t * type_t * loc_t + | Store of loc_t * type_t * id_t | Return | Wmadd of id_t * id_t * id_t * id_t diff --git a/ocaml/parser/syntax.mli b/ocaml/parser/syntax.mli index aa36ace..b7a6b78 100644 --- a/ocaml/parser/syntax.mli +++ b/ocaml/parser/syntax.mli @@ -3,8 +3,8 @@ type access_t = string type attribute_t = access_t list -type type_t = Void | Char | Uchar | Int | Long | Ulong | Llong | Ullong - | Sint of int | Uint of int +type type_t = Void | Char | Uchar | Int | Uint | Long | Ulong | Llong | Ullong + | Sword of int | Uword of int | Const of type_t | Pointer of type_t | Vector of Z.t * type_t @@ -29,9 +29,8 @@ type instr_t = Label of Z.t | Or of id_t * id_t * operand_t | Rshift of id_t * id_t * operand_t | Lshift of id_t * id_t * operand_t - | Load of id_t * loc_t - | Store of loc_t * id_t - | Vstore of type_t * loc_t * id_t + | Load of id_t * type_t * loc_t + | Store of loc_t * type_t * id_t | Return | Wmadd of id_t * id_t * id_t * id_t