⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oaverilogvalue.cpp

📁 openaccess与verilog互相转化时所用的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	    break;	  case BinaryValue:	    bits = valueString.getLength();	    break;	  default:	    bits = 0;	    break;	}    }    return bits;}// *****************************************************************************// Value::decimalToBinary()//// This function converts the Value to a binary representation.  The value is// assumed to be a decimal number and may not be more than 32 bits.// *****************************************************************************voidValue::decimalToBinary(const oaString	&input,		       const oaUInt4	numInputBits,		       oaString		&output){    if (numInputBits > 32) {	throw Error(LargerThanInt, NULL, (const char*) input);    }    oaUInt4	v = atoi((const char*) input);    output = "";    output.resize(numInputBits);    for (oaInt4 i = numInputBits - 1; i != -1; i--)  {	output += ((0x1 << i) & v) != 0 ? "1" : "0";    }}// *****************************************************************************// Value::hexToBinary()//// This function converts the Value to a binary representation.  The value is// assumed to be a hexidecimal number.  There is no limit to the number of bits.// *****************************************************************************voidValue::hexToBinary(const oaString   &input,		   const oaUInt4    numInputBits,		   oaString	    &output){    output = "";    output.resize(numInputBits);    for (oaUInt4 i = 0; i < input.getLength(); i++)  {	switch (((const char*) input)[i]) {	  case 'f':	      output += "1111";	      break;	  case 'e':	      output += "1110";	      break;	  case 'd':	      output += "1101";	      break;	  case 'c':	      output += "1100";	      break;	  case 'b':	      output += "1011";	      break;	  case 'a':	      output += "1010";	      break;	  case '9':	      output += "1001";	      break;	  case '8':	      output += "1000";	      break;	  case '7':	      output += "0111";	      break;	  case '6':	      output += "0110";	      break;	  case '5':	      output += "0101";	      break;	  case '4':	      output += "0100";	      break;	  case '3':	      output += "0011";	      break;	  case '2':	      output += "0010";	      break;	  case '1':	      output += "0001";	      break;	  case '0':	      output += "0000";	      break;	}    }}// *****************************************************************************// Value::octalToBinary()//// This function converts the Value to a binary representation.  The value is// assumed to be an octal number.  There is no limit to the number of bits.// *****************************************************************************voidValue::octalToBinary(const oaString &input,		     const oaUInt4  numInputBits,		     oaString	    &output){    output = "";    output.resize(numInputBits);    for (oaUInt4 i = 0; i < input.getLength(); i++)  {	switch (((const char*) input)[i]) {	  case '7':	      output += "111";	      break;	  case '6':	      output += "110";	      break;	  case '5':	      output += "101";	      break;	  case '4':	      output += "100";	      break;	  case '3':	      output += "011";	      break;	  case '2':	      output += "010";	      break;	  case '1':	      output += "001";	      break;	  case '0':	      output += "000";	      break;	}    }}// *****************************************************************************// Value::toString()//// This function converts the Value to a string.// *****************************************************************************const oaString&Value::toString(){    oaString	base(2);    switch (type) {      case NumAsStringValue:      case StringValue:      case DoubleValue:	return sval;      case BinaryValue:      case PaddedBinaryValue:	base = "'b";	type = NumAsStringValue;	break;      case OctalValue:	base = "'o";	type = NumAsStringValue;	break;      case DecimalValue:	base = "'d";	type = NumAsStringValue;	break;      case HexValue:	base = "'h";	type = NumAsStringValue;	break;    }    oaString buff(64);    buff.format("%d", numBits);    sval = buff + base + sval;    return sval;}// *****************************************************************************// Value::toInt()//// This function converts the Value to an integer.// *****************************************************************************oaInt4Value::toInt() const{    oaInt4  retval = 0;    if (type == DecimalValue || type == DoubleValue) {	return sval.toInt();    }    oaString	    out;    oaUInt4	    nbits;    ValueTypeEnum   outType;    convertToBinary(sval, numBits, type, out, nbits, outType);    if (nbits > 32) {	throw Error(LargerThanInt, NULL, (const char*) sval);    }    for (oaUInt4 i = 0; i < nbits; i++) {	oaChar	c = out[i];	if (c == '1') {	    retval += 0x1 << (nbits - i - 1);	}    }    return retval;}// *****************************************************************************// Value::toDouble()//// This function converts the Value to an oaDouble.// *****************************************************************************oaDoubleValue::toDouble() const{    return type == DoubleValue ? sval.toDouble() : (oaDouble) toInt();}// *****************************************************************************// Value::isNumber()//// This function returns true if the given string represents a number.  Any// string that begins with any number of digits 0 through 9 followed by an// optional base token (e.g. 'b or 'H) is considered to be a number regardless// of what follows the base token.// *****************************************************************************oaBooleanValue::isNumber(const oaString	&str){    if (str.isEmpty()) {	return false;    }    oaUInt4	    i = 0;    oaChar	    c = str[i];    oaUInt4	    state = 0;    const oaString  baseTokens("bBdDhHoO");    while (c != '\0') {	if (state == 0) {	    if (c == '\'') {		state = 1;	    } else if (c < '0' || c > '9') {		return false;	    }	} else if (state == 1) {	    return baseTokens.index(c) != baseTokens.getLength();	}	c = str[++i];    }    return true;}// *****************************************************************************// ValueList::ValueList()//// This is the constructor for a list of Value pointers. // *****************************************************************************ValueList::ValueList() :   std::list<Value*>(){}// *****************************************************************************// ValueList::~ValueList()//// This function is the destructor for lists of values.  The values in the list// are deleted along with the list.// *****************************************************************************ValueList::~ValueList(){    while (!empty()) {	delete front();	pop_front();    }}END_VERILOG_NAMESPACE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -