TaMaDiDecoder::TaMaDiDecoder(Target* target, int n): Operator(target) { srcFileName="TaMaDiDecoder"; ostringstream name; int outWires = intlog2(n-1); name <<"TaMaDiDecoder_n"<<n<<"_output"<<outWires<<"_uid"<<getNewUId(); setName(name.str()); setCopyrightString("Bogdan Pasca (2011)"); /* Set up the I/O signals of of the entity */ int inWires = intlog2(n-1); addInput ("X",inWires,true); addOutput ("R",n,1,true); vhdl << tab << "with X select" << endl; vhdl << tab << "R <= "<<endl; for (int i=0;i<n;i++){ vhdl << tab << tab <<"\""; for (int k=0;k<i;k++) vhdl << "0"; vhdl << "1"; for (int k=i+1;k<n;k++) vhdl << "0"; vhdl <<"\""; vhdl << " when \"" << unsignedBinary( n-1-i, inWires) <<"\","<<endl; } vhdl << tab << tab << zg(n) <<" when others;" << endl; }
void trap_ins(){ strcpy(outputBuffer, spToken.binary); if (spToken.type == TC_TRAP){ spToken = nextToken(); accept(TC_INT, "Trap vector expected."); strcat(outputBuffer, unsignedBinary(spToken.intValue, 12)); } outputBinary(); finishInstruction(); }
void orig_ins(){ if (spToken.type = TC_ORIG){ spToken = nextToken(); // First pass guarantees an int here spAddress = spToken.intValue - 1; spToken = nextToken(); finishInstruction(); } strcpy(outputBuffer, unsignedBinary(spAddress, 16)); outputBinary(); }
void stringz_ins(){ spToken = nextToken(); accept(TC_STRING_LIT, "String literal expected."); char* lit = spToken.source; int i; for (i = 0; i < spToken.intValue; i++){ char ch = lit[i]; strcpy(outputBuffer, unsignedBinary(ch, 16)); outputBinary(); } strcpy(outputBuffer, FILL_ZERO); outputBinary(); spAddress += spToken.intValue - 2; finishInstruction(); }
TaMaDiPriorityEncoder::TaMaDiPriorityEncoder(Target* target, int n): Operator(target) { srcFileName="TaMaDiPriorityEncoder"; ostringstream name; int outWires = intlog2(n-1); name <<"TaMaDiPriorityEncoder_n"<<n<<"_output"<<outWires<<"_uid"<<getNewUId(); setName(name.str()); setCopyrightString("Bogdan Pasca (2011)"); /* Set up the I/O signals of of the entity */ addInput ("X",n,true); addOutput ("R",outWires,1,true); // vhdl << tab << "with X select" << endl; // vhdl << tab << "R <= "<<endl; // for (int i=0;i<n;i++){ // vhdl << tab << tab << "\""<< unsignedBinary(n-1-i,outWires) <<"\" when \""; // for (int k=0;k<i;k++) // vhdl << "0"; // vhdl << "1"; // for (int k=i+1;k<n;k++) // vhdl << "X"; // vhdl <<"\","<<endl; // } // vhdl << tab << tab << tab << zg(outWires) <<" when others;" << endl; vhdl << tab << "R <= "<<endl; for (int i=0;i<n;i++){ vhdl << tab << tab << "\""<< unsignedBinary(n-1-i,outWires) <<"\" when "; vhdl << "X("<<n-i-1<<")='1' else" << endl; } ostringstream dcare; dcare << "\""; for (int i=0; i<outWires; i++) dcare << "X"; dcare << "\""; vhdl << tab << tab << tab << dcare.str() <<";" << endl; }
void getToken(void) { /* Skip over leading spaces and comments */ while (isspace(inChar)) getCharacter(); /* Point to the beginning of the next token */ tkn_strt = stringSP; /* Process Identifier, Symbol, or Reserved Word */ if ((isalpha(inChar)) || (inChar == '_')) identifier(); /* Process Numeric */ else if (isdigit(inChar)) unsignedNumber(); /* Process string */ else if (inChar == SQUOTE) string(); /* process string type */ /* Process ':' or assignment */ else if (inChar == ':') { getCharacter(); if (inChar == '=') {token = tASSIGN; getCharacter();} else token = ':'; } /* end else if */ /* Process '.' or subrange or real-number */ else if (inChar == '.') { /* Get the character after the '.' */ getCharacter(); /* ".." indicates a subrange */ if (inChar == '.') { token = tSUBRANGE; getCharacter(); } /* '.' digit is a real number */ else if (isdigit(inChar)) unsignedRealNumber(); /* Otherwise, it is just a '.' */ else token = '.'; } /* end else if */ /* Process '<' or '<=' or '<>' or '<<' */ else if (inChar == '<') { getCharacter(); if (inChar == '>') {token = tNE; getCharacter();} else if (inChar == '=') {token = tLE; getCharacter();} else if (inChar == '<') {token = tSHL; getCharacter();} else token = tLT; } /* end else if */ /* Process '>' or '>=' or '><' or '>>' */ else if (inChar == '>') { getCharacter(); if (inChar == '<') {token = tNE; getCharacter();} else if (inChar == '=') {token = tGE; getCharacter();} else if (inChar == '>') {token = tSHR; getCharacter();} else token = tGT; } /* end else if */ /* Get Comment -- form { .. } */ else if (inChar == '{') { do getCharacter(); /* get the next character */ while (inChar != '}'); /* loop until end of comment */ getCharacter(); /* skip over end of comment */ getToken(); /* get the next real token */ } /* end else if */ /* Get comment -- form (* .. *) */ else if (inChar == '(') { getCharacter(); /* skip over comment character */ if (inChar != '*') /* is this a comment? */ { token = '('; /* No return '(' leaving the * unprocessed char in inChar */ } else { uint16_t lastChar = ' '; /* YES... prime the look behind */ for (;;) /* look for end of comment */ { getCharacter(); /* get the next character */ if ((lastChar == '*') && /* Is it '*)' ? */ (inChar == ')')) { break; /* Yes... break out */ } lastChar = inChar; /* save the last character */ } /* end for */ getCharacter(); /* skip over the comment end char */ getToken(); /* and get the next real token */ } /* end else */ } /* end else if */ /* NONSTANDARD: All C/C++-style comments */ else if (inChar == '/') { getCharacter(); /* skip over comment character */ if (inChar == '/') /* C++ style comment? */ { skipLine(); /* Yes, skip rest of line */ getToken(); /* and get the next real token */ } else if (inChar != '*') /* is this a C-style comment? */ { token = '/'; /* No return '/' leaving the * unprocessed char in inChar */ } else { uint16_t lastChar = ' '; /* YES... prime the look behind */ for (;;) /* look for end of comment */ { getCharacter(); /* get the next character */ if ((lastChar == '*') && /* Is it '*)' ? */ (inChar == '/')) { break; /* Yes... break out */ } lastChar = inChar; /* save the last character */ } /* end for */ getCharacter(); /* skip over the comment end char */ getToken(); /* and get the next real token */ } /* end else */ } /* end else if */ /* Check for $XXXX (hex) */ else if (inChar == '%') unsignedHexadecimal(); /* Check for $BBBB (binary) */ else if (inChar == '%') unsignedBinary(); /* if inChar is an ASCII character then return token = character */ else if (isascii(inChar)) { token = inChar; getCharacter(); } /* end else if */ /* Otherwise, discard the character and try again */ else { getCharacter(); getToken(); } /* end else */ DEBUG(lstFile,"[%02x]", token); } /* End getToken */