From 03d08047a8238dac18c67ed23b50004a11bd57c6 Mon Sep 17 00:00:00 2001 From: Ethan Mahintorabi Date: Mon, 20 Apr 2026 20:52:40 +0000 Subject: [PATCH] Adds stream interface for parseLibertyFile Signed-off-by: Ethan Mahintorabi --- liberty/LibertyParser.cc | 19 +++++++++++++++---- liberty/LibertyParser.hh | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/liberty/LibertyParser.cc b/liberty/LibertyParser.cc index 446ce30d..f8249300 100644 --- a/liberty/LibertyParser.cc +++ b/liberty/LibertyParser.cc @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -46,15 +47,25 @@ parseLibertyFile(std::string_view filename, std::string fn(filename); gzstream::igzstream stream(fn.c_str()); if (stream.is_open()) { - LibertyParser reader(filename, library_visitor, report); - LibertyScanner scanner(&stream, filename, &reader, report); - LibertyParse parser(&scanner, &reader); - parser.parse(); + parseLibertyFile(stream, filename, library_visitor, report); } else throw FileNotReadable(filename); } +void +parseLibertyFile(std::istream& file_contents, + std::string_view filename, + LibertyGroupVisitor *library_visitor, + Report *report) +{ + + LibertyParser reader(filename, library_visitor, report); + LibertyScanner scanner(&file_contents, filename, &reader, report); + LibertyParse parser(&scanner, &reader); + parser.parse(); +} + LibertyParser::LibertyParser(std::string_view filename, LibertyGroupVisitor *library_visitor, Report *report) : diff --git a/liberty/LibertyParser.hh b/liberty/LibertyParser.hh index de9ec60c..9f0ce4a4 100644 --- a/liberty/LibertyParser.hh +++ b/liberty/LibertyParser.hh @@ -25,6 +25,7 @@ #pragma once #include +#include #include #include #include @@ -280,6 +281,11 @@ public: virtual void visitVariable(LibertyVariable *variable) = 0; }; +void +parseLibertyFile(std::istream& file_contents, + std::string_view filename, + LibertyGroupVisitor *library_visitor, + Report *report); void parseLibertyFile(std::string_view filename, LibertyGroupVisitor *library_visitor,