2018-09-28 17:54:21 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2026-03-10 21:21:17 +01:00
|
|
|
// Copyright (c) 2026, Parallax Software, Inc.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2018-09-28 17:54:21 +02:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2018-09-28 17:54:21 +02:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2022-01-04 18:17:08 +01:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-09-28 17:54:21 +02:00
|
|
|
// GNU General Public License for more details.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2018-09-28 17:54:21 +02:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2022-01-04 18:17:08 +01:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2025-01-22 02:54:33 +01:00
|
|
|
// The origin of this software must not be misrepresented; you must not
|
|
|
|
|
// claim that you wrote the original software.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2025-01-22 02:54:33 +01:00
|
|
|
// Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
// misrepresented as being the original software.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2025-01-22 02:54:33 +01:00
|
|
|
// This notice may not be removed or altered from any source distribution.
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "FuncExpr.hh"
|
2020-04-05 20:35:51 +02:00
|
|
|
|
2025-02-01 23:49:30 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <sstream>
|
2026-03-29 04:13:35 +02:00
|
|
|
#include <string>
|
|
|
|
|
#include <string_view>
|
2025-02-01 23:49:30 +01:00
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "Report.hh"
|
|
|
|
|
#include "Liberty.hh"
|
2025-02-01 23:49:30 +01:00
|
|
|
#include "LibExprReaderPvt.hh"
|
|
|
|
|
#include "LibExprScanner.hh"
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
|
|
|
|
FuncExpr *
|
2026-03-29 04:13:35 +02:00
|
|
|
parseFuncExpr(std::string_view func,
|
2026-02-28 01:57:08 +01:00
|
|
|
const LibertyCell *cell,
|
2026-03-29 04:13:35 +02:00
|
|
|
std::string_view error_msg,
|
2026-01-04 01:59:35 +01:00
|
|
|
Report *report)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2026-03-29 04:13:35 +02:00
|
|
|
if (!func.empty()) {
|
|
|
|
|
std::string func_str(func);
|
|
|
|
|
std::istringstream stream(func_str);
|
2025-02-01 23:49:30 +01:00
|
|
|
LibExprReader reader(func, cell, error_msg, report);
|
|
|
|
|
LibExprScanner scanner(stream);
|
|
|
|
|
LibExprParse parser(&scanner, &reader);
|
|
|
|
|
parser.parse();
|
|
|
|
|
FuncExpr *expr = reader.result();
|
2022-01-14 00:12:27 +01:00
|
|
|
return expr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 04:13:35 +02:00
|
|
|
LibExprReader::LibExprReader(std::string_view func,
|
2026-02-28 01:57:08 +01:00
|
|
|
const LibertyCell *cell,
|
2026-03-29 04:13:35 +02:00
|
|
|
std::string_view error_msg,
|
2026-01-04 01:59:35 +01:00
|
|
|
Report *report) :
|
2018-09-28 17:54:21 +02:00
|
|
|
func_(func),
|
|
|
|
|
cell_(cell),
|
|
|
|
|
error_msg_(error_msg),
|
|
|
|
|
report_(report),
|
2025-02-01 23:49:30 +01:00
|
|
|
result_(nullptr)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-01 23:49:30 +01:00
|
|
|
// defined in LibertyReader.cc
|
2023-02-19 01:20:40 +01:00
|
|
|
LibertyPort *
|
2026-02-28 01:57:08 +01:00
|
|
|
libertyReaderFindPort(const LibertyCell *cell,
|
2026-03-29 04:13:35 +02:00
|
|
|
std::string_view port_name);
|
2023-02-19 01:20:40 +01:00
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
FuncExpr *
|
2026-03-29 04:13:35 +02:00
|
|
|
LibExprReader::makeFuncExprPort(std::string &&port_name)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2019-03-13 01:25:53 +01:00
|
|
|
FuncExpr *expr = nullptr;
|
2026-03-29 04:13:35 +02:00
|
|
|
const std::string_view port_view(port_name);
|
|
|
|
|
LibertyPort *port = libertyReaderFindPort(cell_, port_view);
|
2018-09-28 17:54:21 +02:00
|
|
|
if (port)
|
|
|
|
|
expr = FuncExpr::makePort(port);
|
|
|
|
|
else
|
2026-03-29 04:13:35 +02:00
|
|
|
report_->warn(1130, "{} references unknown port {}.", error_msg_, port_view);
|
2018-09-28 17:54:21 +02:00
|
|
|
return expr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FuncExpr *
|
2025-02-01 23:49:30 +01:00
|
|
|
LibExprReader::makeFuncExprNot(FuncExpr *arg)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
if (arg)
|
|
|
|
|
return FuncExpr::makeNot(arg);
|
|
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FuncExpr *
|
2025-02-01 23:49:30 +01:00
|
|
|
LibExprReader::makeFuncExprXor(FuncExpr *arg1,
|
2026-01-04 01:59:35 +01:00
|
|
|
FuncExpr *arg2)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
if (arg1 && arg2)
|
|
|
|
|
return FuncExpr::makeXor(arg1, arg2);
|
|
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FuncExpr *
|
2025-02-01 23:49:30 +01:00
|
|
|
LibExprReader::makeFuncExprAnd(FuncExpr *arg1,
|
2026-01-04 01:59:35 +01:00
|
|
|
FuncExpr *arg2)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
if (arg1 && arg2)
|
|
|
|
|
return FuncExpr::makeAnd(arg1, arg2);
|
|
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FuncExpr *
|
2025-02-01 23:49:30 +01:00
|
|
|
LibExprReader::makeFuncExprOr(FuncExpr *arg1,
|
2026-01-04 01:59:35 +01:00
|
|
|
FuncExpr *arg2)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
if (arg1 && arg2)
|
|
|
|
|
return FuncExpr::makeOr(arg1, arg2);
|
|
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2025-02-01 23:49:30 +01:00
|
|
|
LibExprReader::setResult(FuncExpr *result)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
result_ = result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2026-03-29 04:13:35 +02:00
|
|
|
LibExprReader::parseError(std::string_view msg)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2026-03-15 22:35:24 +01:00
|
|
|
report_->error(1131, "{} {}.", error_msg_, msg);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2025-02-01 23:49:30 +01:00
|
|
|
LibExprScanner::LibExprScanner(std::istringstream &stream) :
|
|
|
|
|
yyFlexLexer(&stream)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
}
|
2025-02-01 23:49:30 +01:00
|
|
|
|
2026-03-15 22:35:24 +01:00
|
|
|
} // namespace sta
|