Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/kactus2/kactus2dev
Browse files Browse the repository at this point in the history
  • Loading branch information
VasiliiFeshchenko committed Jul 30, 2024
2 parents 6d2b34c + 8db0d32 commit 3270d01
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 22 deletions.
42 changes: 41 additions & 1 deletion Administrative/releaseFiles/upgrade.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -718,4 +718,44 @@ ADD Workspaces/Design/LibraryFilters/Revision/ShowStd14 Boolean true
ADD Workspaces/Design/LibraryFilters/Revision/ShowStd22 Boolean true

VERSION 3.13.79
ADD General/EditorLocking Boolean false
ADD General/EditorLocking Boolean false

VERSION 3.13.525.0
ADD Workspaces/Default/ComponentEditorFilters/HW/Flat/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Product/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Board/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Chip/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Soc/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/IP/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Flat/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Product/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Board/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Chip/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Soc/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/IP/Power_domains Boolean true

ADD Workspaces/Default/ComponentEditorFilters/HW/Flat/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Product/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Board/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Chip/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Soc/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/IP/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Flat/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Product/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Board/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Chip/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Soc/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/IP/Modes Boolean true

ADD Workspaces/Default/ComponentEditorFilters/HW/Flat/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Product/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Board/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Chip/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Soc/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/IP/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Flat/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Product/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Board/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Chip/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Soc/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/IP/Type_definitions Boolean true
46 changes: 40 additions & 6 deletions KactusAPI/expressions/SystemVerilogExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace
const QRegularExpression BINARY_OPERATOR(QStringLiteral("[/%^+-]|<<|>>|<=?|>=?|!==?|===?|[&|*]{1,2}|[$]pow"));

const QRegularExpression UNARY_OPERATOR(QStringLiteral(
"[$]clog2|[$]exp|[$]sqrt|[$]ipxact_mode_condition|[$]ipxact_port_value|[$]ipxact_field_value|~"));
"[$]clog2|[$]exp|[$]sqrt|[$]ipxact_mode_condition|[$]ipxact_port_value|[$]ipxact_field_value|~|`"));

const QRegularExpression TERNARY_OPERATOR(QStringLiteral("[?:]"));

Expand Down Expand Up @@ -64,7 +64,9 @@ namespace
//-----------------------------------------------------------------------------
QString SystemVerilogExpressionParser::parseExpression(QStringView expression, bool* validExpression) const
{
return solveRPN(convertToRPN(expression), validExpression);
// Copy of expression needs to be created for replacing unary minuses with special character.
QString expressionCopy = expression.toString();
return solveRPN(convertToRPN(expressionCopy), validExpression);
}

//-----------------------------------------------------------------------------
Expand All @@ -89,8 +91,8 @@ bool SystemVerilogExpressionParser::isPlainValue(QStringView expression) const
int SystemVerilogExpressionParser::baseForExpression(QStringView expression) const
{
int greatestBase = 0;

for (auto const& token : convertToRPN(expression))
QString asStr = expression.toString();
for (auto const& token : convertToRPN(asStr))
{
if (isLiteral(token))
{
Expand All @@ -108,7 +110,7 @@ int SystemVerilogExpressionParser::baseForExpression(QStringView expression) con
//-----------------------------------------------------------------------------
// Function: SystemVerilogExpressionParser::convertToRPN()
//-----------------------------------------------------------------------------
QVector<QStringView> SystemVerilogExpressionParser::convertToRPN(QStringView expression)
QVector<QStringView> SystemVerilogExpressionParser::convertToRPN(QString& expression)
{
// Convert expression to Reverse Polish Notation (RPN) using the Shunting Yard algorithm.
QVector<QStringView> output;
Expand All @@ -117,7 +119,28 @@ QVector<QStringView> SystemVerilogExpressionParser::convertToRPN(QStringView exp
int openParenthesis = 0;
bool nextMayBeLiteral = true;

qsizetype previousIndex = -1;
const auto SIZE = expression.size();

// Convert unary minuses to backticks. Needs to be done before main loop, otherwise string views will be invalidated.
// SolveRPN knows to treat backticks as unary minus.
for (qsizetype index = 0; index < SIZE; ++index)
{
const QChar current = expression.at(index);
if (current.isSpace())
{
continue;
}

// Minus == unary minus if preceded by opening parenthesis or if first token
if (current == QLatin1Char('-') && (previousIndex == -1 || expression.at(previousIndex) == OPEN_PARENTHESIS_STRING))
{
expression[index] = QLatin1Char('`');
}

previousIndex = index;
}

for (qsizetype index = 0; index < SIZE; /*index incremented inside loop*/)
{
const QChar current = expression.at(index);
Expand Down Expand Up @@ -215,7 +238,8 @@ QVector<QStringView> SystemVerilogExpressionParser::convertToRPN(QStringView exp
else
{
static const QRegularExpression separator(ANY_OPERATOR.pattern() % QStringLiteral("|[(){},]"));
const auto unknown = expression.mid(index, separator.match(expression, index).capturedStart() - index);
auto unknown = QStringView(expression);
unknown = unknown.mid(index, separator.match(expression, index).capturedStart() - index);

output.append(unknown.trimmed());

Expand Down Expand Up @@ -589,6 +613,15 @@ QString SystemVerilogExpressionParser::solveUnary(QStringView operation, QString
{
return QString::number(~term.toLongLong());
}
else if (operation.compare(QLatin1String("`")) == 0)
{
if (!term.contains(QLatin1Char('.')))
{
return QString::number(-term.toLongLong());
}

return QString::number(-term.toDouble(), 'f', precisionOf(term));
}

return QStringLiteral("x");
}
Expand Down Expand Up @@ -710,6 +743,7 @@ unsigned int SystemVerilogExpressionParser::operatorPrecedence(QStringView oper)
{QStringLiteral("*") , 12},
{QStringLiteral("/") , 12},
{QStringLiteral("**") , 13},
{QStringLiteral("`") , 13}, // unary minus
{QStringLiteral("~") , 14},
{QStringLiteral("$clog2") , 14},
{QStringLiteral("$pow") , 14},
Expand Down
4 changes: 2 additions & 2 deletions KactusAPI/include/ParameterizableInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class KACTUS2_API ParameterizableInterface
*
* @return The value of the expression in decimal form.
*/
QString parseExpressionToDecimal(QString const& expression) const;
QString parseExpressionToDecimal(QString const& expression, bool* expressionIsValid = nullptr) const;

/*!
* Parse the selected expression to the selected base number.
Expand All @@ -83,7 +83,7 @@ class KACTUS2_API ParameterizableInterface
*
* @return The value of the expression in the base number form.
*/
QString parseExpressionToBaseNumber(QString const& expression, unsigned int baseNumber) const;
QString parseExpressionToBaseNumber(QString const& expression, unsigned int baseNumber, bool* expressionIsValid = nullptr) const;

private:

Expand Down
2 changes: 1 addition & 1 deletion KactusAPI/include/SystemVerilogExpressionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class KACTUS2_API SystemVerilogExpressionParser : public ExpressionParser
*
* @return The conversion result.
*/
static QVector<QStringView> convertToRPN(QStringView expression);
static QVector<QStringView> convertToRPN(QString& expression);

/*!
* Solves the given RPN expression.
Expand Down
5 changes: 4 additions & 1 deletion KactusAPI/interfaces/common/AbstractParameterInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ std::string AbstractParameterInterface::getValue(std::string const& parameterNam
}
else
{
return parseExpressionToBaseNumber(parameter->getValue(), baseNumber).toStdString();
bool expressionIsValid = false;
auto value = parseExpressionToBaseNumber(parameter->getValue(), baseNumber, &expressionIsValid).toStdString();

return expressionIsValid ? value : std::string("x");
}
}

Expand Down
8 changes: 4 additions & 4 deletions KactusAPI/interfaces/common/ParameterizableInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ QString ParameterizableInterface::formattedValueFor(QString const& expression) c
//-----------------------------------------------------------------------------
// Function: ParameterizableInterface::parseExpressionToDecimal()
//-----------------------------------------------------------------------------
QString ParameterizableInterface::parseExpressionToDecimal(QString const& expression) const
QString ParameterizableInterface::parseExpressionToDecimal(QString const& expression, bool* expressionIsValid /*= nullptr*/) const
{
return expressionParser_->parseExpression(expression);
return expressionParser_->parseExpression(expression, expressionIsValid);
}

//-----------------------------------------------------------------------------
// Function: ParameterizableInterface::parseExpressionToBaseNumber()
//-----------------------------------------------------------------------------
QString ParameterizableInterface::parseExpressionToBaseNumber(QString const& expression, unsigned int baseNumber) const
QString ParameterizableInterface::parseExpressionToBaseNumber(QString const& expression, unsigned int baseNumber, bool* expressionIsValid /*= nullptr*/) const
{
return valueFormatter_->format(parseExpressionToDecimal(expression), baseNumber);
return valueFormatter_->format(parseExpressionToDecimal(expression, expressionIsValid), baseNumber);
}
6 changes: 4 additions & 2 deletions Plugins/VHDLGenerator/vhdlgenerator2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ bool VhdlGenerator2::addRTLView(QString const& fileSetName, const QString& vhdlF
}

// get the relative path to add to file set
QString relativePath = General::getRelativePath(ipDir, vhdlFileName);
QString relativePath = General::getRelativeSavePath(ipDir, vhdlFileName);
if (relativePath.isEmpty())
{
emit errorMessage(tr("Could not create relative path to vhdl file."));
Expand Down Expand Up @@ -329,13 +329,15 @@ bool VhdlGenerator2::addRTLView(QString const& fileSetName, const QString& vhdlF

// create a new file
QSharedPointer<File> topVhdlFile = topFileSet->addFile(relativePath, settings);
FileType vhdlFileType(QStringLiteral("vhdlSource"));
topVhdlFile->setIncludeFile(true);
topVhdlFile->setLogicalName("work");
topVhdlFile->setCommand(QString("vcom"));
topVhdlFile->setBuildFlags("-quiet -check_synthesis -work work", "true");
topVhdlFile->getFileTypes()->append(vhdlFileType);

if (!component_->hasView(viewName_))
{
{
QSharedPointer<View> targetView(new View(viewName_));
QSharedPointer<View::EnvironmentIdentifier> envId( new View::EnvironmentIdentifier );
envId->language = "vhdl";
Expand Down
8 changes: 8 additions & 0 deletions editors/ComponentEditor/common/ExpressionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,11 @@ int ExpressionEditor::getSelectionLastWord() const
{
return toPlainText().left(textCursor().selectionEnd()).count(WORD_DELIMITER);
}

//-----------------------------------------------------------------------------
// Function: ExpressionEditor::getSelectionStartIndex()
//-----------------------------------------------------------------------------
int ExpressionEditor::getSelectionStartIndex() const
{
return textCursor().selectionStart();
}
7 changes: 7 additions & 0 deletions editors/ComponentEditor/common/ExpressionEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ private slots:
* @return Length of the last word in the selection.
*/
int getSelectionLastWord() const final;

/*!
* Get the start index of the selection.
*
* @return The start index of the current selection.
*/
int getSelectionStartIndex() const final;
};

#endif // EXPRESSIONEDITOR_H
8 changes: 8 additions & 0 deletions editors/ComponentEditor/common/ExpressionLineEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,11 @@ int ExpressionLineEditor::getSelectionLastWord() const
{
return text().left(selectionEnd()).count(WORD_DELIMITER);
}

//-----------------------------------------------------------------------------
// Function: ExpressionLineEditor::getSelectionStartIndex()
//-----------------------------------------------------------------------------
int ExpressionLineEditor::getSelectionStartIndex() const
{
return selectionStart();
}
7 changes: 7 additions & 0 deletions editors/ComponentEditor/common/ExpressionLineEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ private slots:
* @return Length of the last word in the selection.
*/
int getSelectionLastWord() const final;

/*!
* Get the start index of the selection.
*
* @return The start index of the current selection.
*/
int getSelectionStartIndex() const final;
};

#endif // EXPRESSIONLINEEDITOR_H
2 changes: 1 addition & 1 deletion editors/ComponentEditor/common/MasterExpressionEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ void MasterExpressionEditor::replaceSelectionInExpression(QKeyEvent* keyEvent)

int firstTermPos = indexOfNthWord(firstWord, expression_);
expression_.remove(expression_.indexOf(selectedText, firstTermPos), selectedText.length());
expression_.insert(firstTermPos, keyEvent->text()); // Don't just remove selection, also insert whatever was typed.
expression_.insert(getSelectionStartIndex(), keyEvent->text()); // Don't just remove selection, also insert whatever was typed.
}

//-----------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions editors/ComponentEditor/common/MasterExpressionEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ class MasterExpressionEditor
*/
virtual int getSelectionLastWord() const = 0;

/*!
* Get the start index of the selection.
*
* @return The start index of the current selection.
*/
virtual int getSelectionStartIndex() const = 0;

/*!
* Checks if the editing would change text in the middle of a referencing term.
*
Expand Down
3 changes: 2 additions & 1 deletion editors/ComponentEditor/componenteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ QStringList ComponentEditor::getHwItemNames()
itemNames << "File_sets" << "Choices" << "Parameters" << "Memory_maps" <<
"Address_spaces" << "Instantiations" << "Views" << "Software_views" << "System_views" << "Ports" <<
"Bus_interfaces" << "Indirect_interfaces" << "Channels" << "Remap_states" << "Cpus" <<
"Other_clock_drivers" << "Reset_types" << "COM_interfaces" << "Software_properties";
"Other_clock_drivers" << "Reset_types" << "COM_interfaces" << "Software_properties" <<
"Type_definitions" << "Modes" << "Power_domains";

return itemNames;
}
Expand Down
42 changes: 41 additions & 1 deletion executable/upgrade.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,44 @@ ADD Workspaces/Design/LibraryFilters/Revision/ShowStd14 Boolean true
ADD Workspaces/Design/LibraryFilters/Revision/ShowStd22 Boolean true

VERSION 3.13.79
ADD General/EditorLocking Boolean false
ADD General/EditorLocking Boolean false

VERSION 3.13.525.0
ADD Workspaces/Default/ComponentEditorFilters/HW/Flat/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Product/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Board/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Chip/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Soc/Power_domains Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/IP/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Flat/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Product/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Board/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Chip/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Soc/Power_domains Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/IP/Power_domains Boolean true

ADD Workspaces/Default/ComponentEditorFilters/HW/Flat/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Product/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Board/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Chip/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Soc/Modes Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/IP/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Flat/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Product/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Board/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Chip/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Soc/Modes Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/IP/Modes Boolean true

ADD Workspaces/Default/ComponentEditorFilters/HW/Flat/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Product/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Board/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Chip/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/Soc/Type_definitions Boolean true
ADD Workspaces/Default/ComponentEditorFilters/HW/IP/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Flat/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Product/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Board/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Chip/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/Soc/Type_definitions Boolean true
ADD Workspaces/Design/ComponentEditorFilters/HW/IP/Type_definitions Boolean true
2 changes: 2 additions & 0 deletions tests/Core/tst_SystemVerilogExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ void tst_SystemVerilogExpressionParser::testParseMultipleOperations_data()
QTest::newRow("clog2() precedes power operation") << "2**$clog2(4) + 1" << "5";

QTest::newRow("Value of clog2() preceds other operations") << "(2 + 2)*3*$clog2(4*2*2) + 2" << "50";

QTest::newRow("Unary minus in expression") << "-$clog2(32)-($sqrt(25)-(-$pow(2,2)))" << "-14";
}

//-----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 3270d01

Please sign in to comment.