提交 77987d73 编写于 作者: 饶先宏's avatar 饶先宏

202105271450

上级 2e7afa6a
......@@ -70,7 +70,7 @@ typedef struct sIBigNumber {
int (*AssignUint32)(HOBJECT object, unsigned int value);
int (*AssignUint64)(HOBJECT object, unsigned long long value);
int (*AssignStr)(HOBJECT object, const char* str, const char** nstr);
int (*AssignStr)(HOBJECT object, const char* str, const char** nstr, int autowidth);
int (*Clone)(HOBJECT object, HOBJECT src);
int (*CloneSubBits)(HOBJECT object, HOBJECT src, int from, int width, int signexpand);
......@@ -166,7 +166,7 @@ typedef struct sIBigNumber {
static int _obj##_bn_AssignInt64(HOBJECT object, long long value); \
static int _obj##_bn_AssignUint32(HOBJECT object, unsigned int value); \
static int _obj##_bn_AssignUint64(HOBJECT object, unsigned long long value); \
static int _obj##_bn_AssignStr(HOBJECT object, const char* str, const char** nstr); \
static int _obj##_bn_AssignStr(HOBJECT object, const char* str, const char** nstr, int autowidth); \
static int _obj##_bn_Clone(HOBJECT object, HOBJECT src); \
static int _obj##_bn_CloneSubBits(HOBJECT object, HOBJECT src, int from, int width, int signexpand); \
static int _obj##_bn_Assign(HOBJECT object, HOBJECT src); \
......
......@@ -379,14 +379,23 @@ enum TOKEN_STATE {
TOKEN_HEX
};
static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nstr)
#define MAXNUMWIDTH (1 << 30)
static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nstr, int autowidth)
{
int width, objwidth, sign;
enum TOKEN_STATE state;
const char* strt = str;
int numvalid = 0;
sBigInteger* pobj;
pobj = (sBigInteger*)objectThis(object);
width = -1;
objwidth = pobj->width;
if (autowidth == 0 && objwidth <= 0)
return -1;
bigint_bn_SetWidth(object, 64, 0);
state = TOKEN_INITIAL;
sign = 0;
while (*strt != 0) {
int ch = *strt;
switch (state) {
......@@ -402,11 +411,43 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
} break;
case TOKEN_NUM: {
if (ch >= '0' && ch <= '9') {
if (pobj->buf[pobj->buflen - 1] > (1 << 27)) {
int w;
w = pobj->width * 2;
if (w > MAXNUMWIDTH) {
w = MAXNUMWIDTH;
}
if (0 != bigint_bn_SetWidth(object, w, 0)) {
return -1;
}
}
bigint_bn_MulInt32(object, object, 10);
bigint_bn_AddInt32(object, object, ch - '0');
}
else if (ch == '\'') {
int i;
for (i = pobj->buflen - 1; i > 0; i--) {
if (pobj->buf[i] != 0) {
/* too large width of a number */
width = MAXNUMWIDTH;
break;
}
}
if (width == -1) {
if (pobj->buf[0] > MAXNUMWIDTH) {
width = MAXNUMWIDTH;
}
else {
width = pobj->buf[0];
}
}
state = TOKEN_BASE;
if (width == 0)
width = -1;
else
if (0 != bigint_bn_SetWidth(object, width, 0)) {
return -1;
}
numvalid = 0;
}
else {
......@@ -414,7 +455,10 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
}
}break;
case TOKEN_BASE: {
if (ch == 'b' || ch == 'B') {
if (ch == 's' || ch == 'S') {
sign = 1;
}
else if (ch == 'b' || ch == 'B') {
bigint_bn_AssignInt32(object, 0);
state = TOKEN_BIN;
}
......@@ -439,8 +483,19 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
}break;
case TOKEN_BIN: {
if (ch == '0' || ch == '1') {
bigint_bn_MulInt32(object, object, 2);
bigint_bn_AddInt32(object, object, ch - '0');
if (autowidth && (width == -1)) {
if (pobj->buf[pobj->buflen - 1] > (1 << 27)) {
int w;
w = pobj->width * 2;
if (w > MAXNUMWIDTH) {
w = MAXNUMWIDTH;
}
if (0 != bigint_bn_SetWidth(object, w, 0))
return -1;
}
}
bigint_bn_MulUint32(object, object, 2);
bigint_bn_AddUint32(object, object, ch - '0');
numvalid = 1;
}
else if (ch == '_') {
......@@ -451,8 +506,19 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
}break;
case TOKEN_OCT: {
if (ch >= '0' && ch <= '7') {
bigint_bn_MulInt32(object, object, 8);
bigint_bn_AddInt32(object, object, ch - '0');
if (autowidth && (width == -1)) {
if (pobj->buf[pobj->buflen - 1] > (1 << 27)) {
int w;
w = pobj->width * 2;
if (w > MAXNUMWIDTH) {
w = MAXNUMWIDTH;
}
if (0 != bigint_bn_SetWidth(object, w, 0))
return -1;
}
}
bigint_bn_MulUint32(object, object, 8);
bigint_bn_AddUint32(object, object, ch - '0');
numvalid = 1;
}
else if (ch == '_') {
......@@ -463,8 +529,19 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
}break;
case TOKEN_DEC: {
if (ch >= '0' && ch <= '9') {
bigint_bn_MulInt32(object, object, 10);
bigint_bn_AddInt32(object, object, ch - '0');
if (autowidth && (width == -1)) {
if (pobj->buf[pobj->buflen - 1] > (1 << 27)) {
int w;
w = pobj->width * 2;
if (w > MAXNUMWIDTH) {
w = MAXNUMWIDTH;
}
if (0 != bigint_bn_SetWidth(object, w, 0))
return -1;
}
}
bigint_bn_MulUint32(object, object, 10);
bigint_bn_AddUint32(object, object, ch - '0');
numvalid = 1;
}
else {
......@@ -474,13 +551,24 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
case TOKEN_HEX: {
if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) {
numvalid = 1;
bigint_bn_MulInt32(object, object, 16);
if (autowidth && (width == -1)) {
if (pobj->buf[pobj->buflen - 1] > (1 << 27)) {
int w;
w = pobj->width * 2;
if (w > MAXNUMWIDTH) {
w = MAXNUMWIDTH;
}
if (0 != bigint_bn_SetWidth(object, w, 0))
return -1;
}
}
bigint_bn_MulUint32(object, object, 16);
if (ch > '0' && ch <= '9')
bigint_bn_AddInt32(object, object, ch - '0');
bigint_bn_AddUint32(object, object, ch - '0');
else if (ch >= 'a' && ch <= 'f')
bigint_bn_AddInt32(object, object, ch - 'a' + 10);
bigint_bn_AddUint32(object, object, ch - 'a' + 10);
else if (ch >= 'A' && ch <= 'F')
bigint_bn_AddInt32(object, object, ch - 'A' + 10);
bigint_bn_AddUint32(object, object, ch - 'A' + 10);
}
else if (ch == '_') {
}
......@@ -497,7 +585,25 @@ static int bigint_bn_AssignStr(HOBJECT object, const char* str, const char **nst
lastnum:
if (nstr != NULL)
*nstr = strt;
bigint_bn_SetWidth(object, pobj->width, 1);
if (autowidth && (width == -1)) {
int i;
width = 0;
for (i = pobj->buflen - 1; i >= 0; i--) {
if (pobj->buf[i] != 0) {
width = actualwidth(pobj->buf[i]);
width += i * CELL_WIDTH;
break;
}
}
if (width == 0)
width = 1;
if (sign == 0)
width++;
}
else {
width = pobj->width;
}
bigint_bn_SetWidth(object, width, sign);
return 0;
}
......
......@@ -44,7 +44,7 @@ int main(int argc, char* argv[])
const char* nstr = testnumber;
const char* lstr = testnumber;
/*
while (0 == objectCall2(bignumber, AssignStr, lstr, &nstr)) {
while (0 == objectCall3(bignumber, AssignStr, lstr, &nstr, 1)) {
objectCall3(bignumber, GetStr, 16, buf, 128);
printf("%s=%s, \nnext=%s\n", lstr, buf, nstr);
lstr = nstr;
......
......@@ -137,7 +137,7 @@ static int hdl4se_bind2Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
int j;
lstr = (const char*)pParams[i].pvalue;
for (j = 0; j < BINDCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->inputwidth[j]);
lstr = nstr;
}
......
......@@ -137,7 +137,7 @@ static int hdl4se_bind3Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
int j;
lstr = (const char*)pParams[i].pvalue;
for (j = 0; j < BINDCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->inputwidth[j]);
lstr = nstr;
}
......
......@@ -137,7 +137,7 @@ static int hdl4se_bind4Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
int j;
lstr = (const char*)pParams[i].pvalue;
for (j = 0; j < BINDCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->inputwidth[j]);
lstr = nstr;
}
......
......@@ -151,7 +151,7 @@ static int hdl4se_binopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
int j;
lstr = (const char*)pParams[i].pvalue;
for (j = 0; j < INCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->in_width[j]);
}
else {
......@@ -159,14 +159,14 @@ static int hdl4se_binopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
}
lstr = nstr;
}
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->out_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->op);
}
else {
......
......@@ -111,13 +111,13 @@ static int hdl4se_constCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
if (0 == objectCall3(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
if (pobj->width <= 0 || pobj->width > (1 << 24))
return -1;
pobj->out_data = bigintegerCreate(pobj->width);
objectCall2(pobj->out_data, AssignStr, nstr, NULL);
objectCall3(pobj->out_data, AssignStr, nstr, NULL, 0);
objectRelease(temp);
}
}
......
......@@ -134,7 +134,7 @@ static int hdl4se_mux16Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
if (0 == objectCall3(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
......
......@@ -136,7 +136,7 @@ static int hdl4se_mux2Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
if (0 == objectCall3(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
......
......@@ -134,7 +134,7 @@ static int hdl4se_mux4Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
if (0 == objectCall3(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
......
......@@ -134,7 +134,7 @@ static int hdl4se_mux8Create(const PARAMITEM* pParams, int paramcount, HOBJECT*
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
if (0 == objectCall3(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
......
......@@ -120,7 +120,7 @@ static int hdl4se_regCreate(const PARAMITEM* pParams, int paramcount, HOBJECT* p
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
if (0 == objectCall3(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
......
......@@ -140,7 +140,7 @@ static int hdl4se_split2Create(const PARAMITEM* pParams, int paramcount, HOBJECT
const char* lstr;
int j;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
else {
......@@ -148,14 +148,14 @@ static int hdl4se_split2Create(const PARAMITEM* pParams, int paramcount, HOBJECT
}
lstr = nstr;
for (j = 0; j < SPLITCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->out_info[j][0]);
}
else {
return -1;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->out_info[j][1]);
}
else {
......
......@@ -143,7 +143,7 @@ static int hdl4se_split4Create(const PARAMITEM* pParams, int paramcount, HOBJECT
const char* lstr;
int j;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
else {
......@@ -151,14 +151,14 @@ static int hdl4se_split4Create(const PARAMITEM* pParams, int paramcount, HOBJECT
}
lstr = nstr;
for (j = 0; j < SPLITCOUNT; j++) {
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->out_info[j][0]);
}
else {
return -1;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->out_info[j][1]);
}
else {
......
......@@ -137,21 +137,21 @@ static int hdl4se_unopCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
const char* nstr;
const char* lstr;
lstr = (const char*)pParams[i].pvalue;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->in_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->out_width);
}
else {
return EIID_INVALIDPARAM;
}
lstr = nstr;
if (0 == objectCall2(temp, AssignStr, lstr, &nstr)) {
if (0 == objectCall3(temp, AssignStr, lstr, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->op);
}
else {
......
......@@ -125,7 +125,7 @@ static int hdl4se_wireCreate(const PARAMITEM* pParams, int paramcount, HOBJECT*
IBigNumber** temp = bigintegerCreate(32);
if (temp != NULL) {
const char* nstr;
if (0 == objectCall2(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr)) {
if (0 == objectCall3(temp, AssignStr, (const char*)pParams[i].pvalue, &nstr, 0)) {
objectCall1(temp, GetInt32, &pobj->width);
}
objectRelease(temp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册