Skip to content

Commit b7db9e8

Browse files
nasrineshraghijeanlego
authored andcommitted
ODIN_II language coverage: part-select keyword (#511)
* Add part-select keyword as a language coverage * new line at the end of the file * Update Documentation according to index part-select * added range checking to part-selct operator * refactored newPartSelectRangeRef into newRangeRef * added limits calculations * Add test bench for part-select * hotfix for part-select range * Add test * fixed -: index calculation * add error message * change in error message * change the error messages * Fix the messages * latest change
1 parent d4771a1 commit b7db9e8

16 files changed

+158
-5
lines changed

ODIN_II/README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,10 @@ Verilog Synthesizable Keyword Support:
309309
+-------------------+------------------+---------------------+--------------------+
310310
| macromodule | | | |
311311
+-------------------+------------------+---------------------+--------------------+
312-
313-
312+
| +: | | | |
313+
+-------------------+------------------+---------------------+--------------------+
314+
| -: | | | |
315+
+-------------------+------------------+---------------------+--------------------+
314316

315317
Verilog NON-Synthesizable Keyword Support:
316318
*********************************

ODIN_II/SRC/include/ast_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ void make_concat_into_list_of_strings(ast_node_t *concat_top, char *instance_nam
2424
void change_to_number_node(ast_node_t *node, long number);
2525

2626
int get_range(ast_node_t* first_node);
27+
2728
char *get_name_of_pin_at_bit(ast_node_t *var_node, int bit, char *instance_name_prefix);
2829
char *get_name_of_var_declare_at_bit(ast_node_t *var_declare, int bit);
2930
char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix);

ODIN_II/SRC/include/parse_making_ast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ ast_node_t *markAndProcessSymbolListWith(ids top_type, ids id, ast_node_t *symbo
2121
ast_node_t *newArrayRef(char *id, ast_node_t *expression, int line_number);
2222
ast_node_t *newArrayRef2D(char *id, ast_node_t *expression1, ast_node_t *expression2, int line_number);
2323
ast_node_t *newRangeRef(char *id, ast_node_t *expression1, ast_node_t *expression2, int line_number);
24+
ast_node_t *newPartSelectRangeRef(char *id, ast_node_t *expression1, ast_node_t *expression2, char direction,
25+
int line_number);
2426
ast_node_t *newRangeRef2D(char *id, ast_node_t *expression1, ast_node_t *expression2, ast_node_t *expression3, ast_node_t *expression4, int line_number);
2527
ast_node_t *newBinaryOperation(operation_list op_id, ast_node_t *expression1, ast_node_t *expression2, int line_number);
2628
ast_node_t *newExpandPower(operation_list op_id, ast_node_t *expression1, ast_node_t *expression2, int line_number);

ODIN_II/SRC/parse_making_ast.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,54 @@ ast_node_t *newRangeRef(char *id, ast_node_t *expression1, ast_node_t *expressio
835835
return new_node;
836836
}
837837

838+
839+
/*---------------------------------------------------------------------------------------------
840+
* (function: newPartSelectRangeRef)
841+
*-------------------------------------------------------------------------------------------*/
842+
ast_node_t *newPartSelectRangeRef(char *id, ast_node_t *expression1, ast_node_t *expression2, char direction,
843+
int line_number)
844+
{
845+
846+
long sc_spot;
847+
848+
oassert(expression1 != NULL && expression1->type == NUMBERS && expression2 != NULL && expression2->type == NUMBERS);
849+
850+
/* Try to find the original array to check low/high indices */
851+
if ((sc_spot = sc_lookup_string(modules_inputs_sc, id)) == -1 &&
852+
(sc_spot = sc_lookup_string(modules_outputs_sc, id)) == -1){
853+
error_message(PARSE_ERROR, line_number, current_parse_file, "Could not find variable %s", id);
854+
return nullptr;
855+
}
856+
ast_node_t *original_range = (ast_node_t *) modules_inputs_sc->data[sc_spot];;
857+
long upper_limit = original_range->children[1]->types.number.value;
858+
long bottom_limit = original_range->children[2]->types.number.value;
859+
if (expression1->types.number.value < 0 || expression2->types.number.value < 0){
860+
861+
/* Negetive numbers are not supported */
862+
error_message(PARSE_ERROR, line_number, current_parse_file,
863+
"Odin doesn't support negative number in index : %s[%d%s%d].", id,
864+
expression1->types.number.value, direction == 1 ? "+:" : "-:",
865+
expression2->types.number.value);
866+
}
867+
868+
if (direction == 1){
869+
expression1->types.number.value = expression1->types.number.value + expression2->types.number.value - 1;
870+
expression2->types.number.value = expression1->types.number.value - expression2->types.number.value + 1;
871+
}
872+
else{
873+
expression2->types.number.value = expression1->types.number.value - expression2->types.number.value + 1;
874+
}
875+
if (expression1->types.number.value > upper_limit || expression2->types.number.value < bottom_limit) {
876+
/* out of original range */
877+
error_message(PARSE_ERROR, line_number,current_parse_file,
878+
"This part-select range %s:[%d%s%d] is out of range. It should be in the %s:[%d:%d] range.",
879+
id,expression1->types.number.value, direction ==1 ? "+:" : "-:",expression2->types.number.value,
880+
id,upper_limit,bottom_limit );
881+
}
882+
883+
return newRangeRef(id, expression1, expression2, line_number);
884+
}
885+
838886
/*---------------------------------------------------------------------------------------------
839887
* (function: newBinaryOperation)
840888
*-------------------------------------------------------------------------------------------*/

ODIN_II/SRC/verilog_bison.y

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ int yylex(void);
6565
%token vOUTPUT vPARAMETER vPOSEDGE vREG vWIRE vXNOR vXOR vDEFPARAM voANDAND
6666
%token voOROR voLTE voGTE voPAL voSLEFT voSRIGHT vo ASRIGHT voEQUAL voNOTEQUAL voCASEEQUAL
6767
%token voCASENOTEQUAL voXNOR voNAND voNOR vWHILE vINTEGER
68-
%token vNOT_SUPPORT
68+
%token vNOT_SUPPORT
69+
%token vPLUS_COLON vMINUS_COLON
6970
%token '?' ':' '|' '^' '&' '<' '>' '+' '-' '*' '/' '%' '(' ')' '{' '}' '[' ']'
7071

7172
%right '?' ':'
@@ -510,6 +511,8 @@ primary:
510511
| vSYMBOL_ID {$$ = newSymbolNode($1, yylineno);}
511512
| vSYMBOL_ID '[' expression ']' {$$ = newArrayRef($1, $3, yylineno);}
512513
| vSYMBOL_ID '[' expression ']' '[' expression ']' {$$ = newArrayRef2D($1, $3, $6, yylineno);}
514+
| vSYMBOL_ID '[' expression vPLUS_COLON expression ']' {$$ = newPartSelectRangeRef($1, $3, $5, 1, yylineno);}
515+
| vSYMBOL_ID '[' expression vMINUS_COLON expression ']' {$$ = newPartSelectRangeRef($1, $3, $5, -1, yylineno);}
513516
| vSYMBOL_ID '[' expression ':' expression ']' {$$ = newRangeRef($1, $3, $5, yylineno);}
514517
| vSYMBOL_ID '[' expression ':' expression ']' '[' expression ':' expression ']' {$$ = newRangeRef2D($1, $3, $5, $8, $10, yylineno);}
515518
| '{' probable_expression_list '}' {$$ = $2; ($2)->types.concat.num_bit_strings = -1;}

ODIN_II/SRC/verilog_flex.l

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,12 @@ char* standardize_number(const char* input);
175175
<INITIAL>"~^" { MP; return voXNOR;}
176176
<INITIAL>"~&" { MP; return voNAND;}
177177
<INITIAL>"~|" { MP; return voNOR;}
178+
<INITIAL>"+:" { MP; return vPLUS_COLON;}
179+
<INITIAL>"-:" { MP; return vMINUS_COLON;}
178180

179181
/* unsupported Operators */
180182
<INITIAL>"&&&" { MP; return vNOT_SUPPORT;}
181-
<INITIAL>"+:" { MP; return vNOT_SUPPORT;}
182-
<INITIAL>"-:" { MP; return vNOT_SUPPORT;}
183+
183184

184185

185186
/* operands */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module OR2in (A,B,C1,C2);
2+
3+
input [5:0] A ;
4+
input [5:0] B ;
5+
output [2:0] C1 ;
6+
output [2:0] C2 ;
7+
8+
assign C1=A[2-:3] | B[2-:3] ;
9+
assign C2=A[5-:3] | B[5-:3] ;
10+
11+
endmodule
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
GLOBAL_SIM_BASE_CLK A B
2+
0 0X20 0X26
3+
0 0X2C 0X16
4+
0 0X3C 0X36
5+
0 0X22 0X06
6+
0 0X24 0X20
7+
0 0X01 0X06
8+
0 0X0C 0X07
9+
0 0X01 0X26
10+
0 0X21 0X06
11+
0 0X0C 0X26
12+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
C1 C2
2+
0X06 0X04
3+
0X06 0X07
4+
0X06 0X07
5+
0X06 0X04
6+
0x04 0x04
7+
0x07 0x00
8+
0x07 0x01
9+
0x07 0x04
10+
0x07 0x04
11+
0x06 0x05
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module And2in (A,B,C1,C2);
2+
3+
input [5:0] A ;
4+
input [5:0] B ;
5+
output [2:0] C1 ;
6+
output [2:0] C2 ;
7+
8+
assign C1 = A[0+:3] & B[0+:3] ;
9+
assign C2 = A[-3+:3] & B[3+:3] ;
10+
11+
endmodule
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
GLOBAL_SIM_BASE_CLK A B
2+
0 0X27 0X1A
3+
0 0X28 0X32
4+
0 0X10 0X3F
5+
0 0X1D 0X3F
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
C1 C2
2+
0X2 0X0
3+
0X0 0X4
4+
0X0 0X2
5+
0X5 0X3
6+
7+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module And2in (A,B,C1,C2);
2+
3+
input [7:0] A ;
4+
input [7:0] B ;
5+
output [3:0] C1 ;
6+
output [3:0] C2 ;
7+
8+
assign C1=A[0+:4] & B[0+:4] ;
9+
assign C2=A[3+:5] & B[3+:5] ;
10+
11+
endmodule
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
GLOBAL_SIM_BASE_CLK A B
2+
0 0X60 0XA6
3+
0 0XEC 0X16
4+
0 0XBC 0XB6
5+
0 0X62 0X46
6+
0 0XE4 0X20
7+
0 0X01 0X86
8+
0 0XCC 0X47
9+
0 0X41 0XE6
10+
0 0XE1 0X06
11+
0 0XCC 0XE6
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
C1 C2
2+
0X0 0X4
3+
0X4 0X0
4+
0X4 0X6
5+
0X2 0X8
6+
0X0 0X4
7+
0X0 0X0
8+
0X4 0X8
9+
0X0 0X8
10+
0X0 0X0
11+
0X4 0X8
12+

doc/src/odin/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ Verilog Synthesizable Keyword Support:
309309
+-------------------+------------------+---------------------+--------------------+
310310
| macromodule | | | |
311311
+-------------------+------------------+---------------------+--------------------+
312+
| +: | | | |
313+
+-------------------+------------------+---------------------+--------------------+
314+
| -: | | | |
315+
+-------------------+------------------+---------------------+--------------------+
316+
312317

313318

314319
Verilog NON-Synthesizable Keyword Support:

0 commit comments

Comments
 (0)