forp: change indexing to verilog-like semantics
This commit is contained in:
parent
023f5eca58
commit
4415dde6d3
2 changed files with 7 additions and 6 deletions
|
@ -89,8 +89,9 @@ Expressions can be formed just as in C, however when used in an expression, all
|
|||
The valid operators are listed below, in decreasing precedence. Note that logical operations treat all non-zero values as 1, whereas bitwise operators operate on all bits independently.
|
||||
.TP "\w'\fL<\fR, \fL<=\fR, \fL>\fR, \fL>=\fR 'u"
|
||||
\fL[]\fR
|
||||
Array indexing. The syntax is \fIvar\fL[\fIidx\fL:\fIn\fR] to address \fIn\fR bits with the least-significant bit at \fIidx\fR.
|
||||
Omiting \fL:\fIn\fR addresses a single bit.
|
||||
Array indexing. The syntax is \fIvar\fL[\fIa\fL:\fIb\fR], with \fIa\fR denoting the MSB and \fIb\fR denoting the LSB.
|
||||
Omiting \fL:\fIb\fR addresses a single bit.
|
||||
The result is always treated as unsigned.
|
||||
.TP
|
||||
\fL!\fR, \fL~\fR, \fL+\fR, \fL-\fR
|
||||
(Unary operators) Logical and bitwise "not", unary plus (no-op), arithmetic negation. Because of promotion, \fL~\fR and \fL-\fR operate beyond the width of variables.
|
||||
|
|
|
@ -251,9 +251,9 @@ opidx(Node *rn, Node *n1, Node *n2, Node *n3)
|
|||
{
|
||||
int i, j, k, s;
|
||||
|
||||
j = mptoi(n2->num);
|
||||
if(n3 == nil) k = j;
|
||||
else k = mptoi(n3->num);
|
||||
k = mptoi(n2->num);
|
||||
if(n3 == nil) j = k;
|
||||
else j = mptoi(n3->num);
|
||||
if(j > k){
|
||||
nodevars(rn, 1);
|
||||
return;
|
||||
|
@ -492,7 +492,7 @@ convert(Node *n, uint sz)
|
|||
case ASTIDX:
|
||||
if(n->n2->type != ASTNUM || n->n3 != nil && n->n3->type != ASTNUM)
|
||||
error(n, "non-constant in indexing expression");
|
||||
convert(n->n1, (n->n3 != nil ? mptoi(n->n3->num) : mptoi(n->n2->num)) + 1);
|
||||
convert(n->n1, n->n3 != nil ? mptoi(n->n3->num) - mptoi(n->n2->num) + 1 : 1);
|
||||
opidx(n, n->n1, n->n2, n->n3);
|
||||
break;
|
||||
case ASTTERN:
|
||||
|
|
Loading…
Reference in a new issue