Skip to content

Commit

Permalink
remove Vstore
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Aug 1, 2024
1 parent 3f68bc8 commit 247c8c4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
13 changes: 7 additions & 6 deletions ocaml/parser/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions ocaml/parser/gimpleLexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"char" , CHAR;
"int" , INT;
"const" , CONST;
"signed" , SIGNED;
"unsigned" , UNSIGNED;
"long" , LONG;
"vector" , VECTOR;
Expand Down
31 changes: 19 additions & 12 deletions ocaml/parser/gimpleParser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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 }
;

Expand Down Expand Up @@ -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) }
;

Expand Down Expand Up @@ -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 }
Expand Down
9 changes: 4 additions & 5 deletions ocaml/parser/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
9 changes: 4 additions & 5 deletions ocaml/parser/syntax.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 247c8c4

Please sign in to comment.