-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initiating Liberty support * restructuring code * Liberty construction in SNL and first tests * Cleaning licenses * clean license * fixing tests * Fix leak * Leak fix * install snl_liberty lib * more testing * clean licensing * fix license * leak cleaning * Fix coverage
- Loading branch information
Showing
29 changed files
with
72,652 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
Copyright (c) <year> <owner>. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ISC License | ||
|
||
Copyright <YEAR> <OWNER> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory(liberty) | ||
add_subdirectory(verilog) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# SPDX-FileCopyrightText: 2024 The Naja authors <https://github.com/najaeda/naja/blob/main/AUTHORS> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set(SOURCES | ||
SNLLibertyConstructor.cpp | ||
) | ||
|
||
SET(HEADERS SNLLibertyConstructor.h) | ||
|
||
add_library(naja_snl_liberty SHARED ${SOURCES}) | ||
target_link_libraries(naja_snl_liberty naja_snl yosys_liberty) | ||
|
||
target_include_directories(naja_snl_liberty PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
set_target_properties(naja_snl_liberty PROPERTIES PUBLIC_HEADER "${HEADERS}") | ||
install(TARGETS naja_snl_liberty LIBRARY DESTINATION lib PUBLIC_HEADER DESTINATION include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2024 The Naja Authors. | ||
// SPDX-FileCopyrightText: 2024 The Naja authors <https://github.com/najaeda/naja/blob/main/AUTHORS> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "SNLLibertyConstructor.h" | ||
|
||
#include <fstream> | ||
#include "YosysLibertyParser.h" | ||
|
||
#include "SNLLibrary.h" | ||
#include "SNLScalarTerm.h" | ||
#include "SNLLibertyConstructorException.h" | ||
|
||
namespace { | ||
|
||
using namespace naja::SNL; | ||
|
||
SNLTerm::Direction findDirection(const Yosys::LibertyAst* cell) { | ||
for (auto child: cell->children) { | ||
if (child->id == "direction") { | ||
auto direction = child->value; | ||
if (direction == "input") { | ||
return SNLTerm::Direction::Input; | ||
} else if (direction == "output") { | ||
return SNLTerm::Direction::Output; | ||
} else { | ||
throw SNLLibertyConstructorException("Unknown direction"); | ||
} | ||
} | ||
} | ||
throw SNLLibertyConstructorException("Direction not found"); | ||
} | ||
|
||
void parseTerms(SNLDesign* primitive, const Yosys::LibertyAst* cell) { | ||
for (auto child: cell->children) { | ||
if (child->id == "pin") { | ||
auto pinName = child->args[0]; | ||
auto direction = findDirection(child); | ||
auto term = SNLScalarTerm::create(primitive, direction, SNLName(pinName)); | ||
} | ||
} | ||
} | ||
|
||
void parseCell(SNLLibrary* library, const Yosys::LibertyAst* cell) { | ||
auto cellName = cell->args[0]; | ||
auto primitive = SNLDesign::create(library, SNLDesign::Type::Primitive, SNLName(cellName)); | ||
parseTerms(primitive, cell); | ||
} | ||
|
||
void parseCells(SNLLibrary* library, const Yosys::LibertyAst* ast) { | ||
for (auto child: ast->children) { | ||
if (child->id == "cell") { | ||
parseCell(library, child); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
namespace naja { namespace SNL { | ||
|
||
SNLLibertyConstructor::SNLLibertyConstructor(SNLLibrary* library): | ||
library_(library) | ||
{} | ||
|
||
void SNLLibertyConstructor::construct(const std::filesystem::path& path) { | ||
if (not std::filesystem::exists(path)) { | ||
std::string reason(path.string() + " does not exist"); | ||
throw SNLLibertyConstructorException(reason); | ||
} | ||
std::ifstream inFile(path); | ||
if (not inFile.good()) { | ||
std::string reason(path.string() + " is not a readable file"); | ||
throw SNLLibertyConstructorException(reason); | ||
} | ||
auto parser = std::make_unique<Yosys::LibertyParser>(inFile); | ||
auto ast = parser->ast; | ||
if (ast == nullptr) { | ||
//LCOV_EXCL_START | ||
std::string reason("Failed to parse the file"); | ||
throw SNLLibertyConstructorException(reason); | ||
//LCOV_EXCL_STOP | ||
} | ||
auto libraryName = ast->args[0]; | ||
library_->setName(SNLName(libraryName)); | ||
parseCells(library_, ast); | ||
} | ||
|
||
}} // namespace SNL // namespace naja |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2024 The Naja Authors. | ||
// SPDX-FileCopyrightText: 2023 The Naja authors <https://github.com/najaeda/naja/blob/main/AUTHORS> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef __SNL_LIBERTY_CONSTRUCTOR_H_ | ||
#define __SNL_LIBERTY_CONSTRUCTOR_H_ | ||
|
||
#include <filesystem> | ||
|
||
namespace naja { namespace SNL { | ||
|
||
class SNLLibrary; | ||
|
||
class SNLLibertyConstructor { | ||
public: | ||
SNLLibertyConstructor() = delete; | ||
SNLLibertyConstructor(const SNLLibertyConstructor&) = delete; | ||
SNLLibertyConstructor(SNLLibrary* library); | ||
|
||
void construct(const std::filesystem::path& path); | ||
private: | ||
SNLLibrary* library_; | ||
|
||
}; | ||
|
||
}} // namespace SNL // namespace naja | ||
|
||
#endif // __SNL_LIBERTY_CONSTRUCTOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2024 The Naja Authors. | ||
// SPDX-FileCopyrightText: 2024 The Naja authors <https://github.com/najaeda/naja/blob/main/AUTHORS> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef __SNL_LIBERTY_CONSTRUCTOR_EXCEPTION_H_ | ||
#define __SNL_LIBERTY_CONSTRUCTOR_EXCEPTION_H_ | ||
|
||
#include "SNLException.h" | ||
|
||
namespace naja { namespace SNL { | ||
|
||
struct SNLLibertyConstructorException: public SNLException { | ||
public: | ||
SNLLibertyConstructorException() = delete; | ||
SNLLibertyConstructorException(const SNLLibertyConstructorException&) = default; | ||
|
||
SNLLibertyConstructorException(const std::string& reason): | ||
SNLException(reason) | ||
{} | ||
}; | ||
|
||
}} // namespace SNL // namespace naja | ||
|
||
#endif // __SNL_LIBERTY_CONSTRUCTOR_EXCEPTION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory(liberty) | ||
add_subdirectory(verilog) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# SPDX-FileCopyrightText: 2024 The Naja liberty authors <https://github.com/najaeda/naja/blob/main/AUTHORS> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
include(GoogleTest) | ||
|
||
set(tests | ||
SNLLibertyConstructorTest0.cpp | ||
) | ||
|
||
add_executable(snl_liberty_tests ${tests}) | ||
target_compile_definitions(snl_liberty_tests PRIVATE | ||
SNL_LIBERTY_BENCHMARKS="${CMAKE_CURRENT_SOURCE_DIR}") | ||
|
||
target_link_libraries(snl_liberty_tests naja_snl_liberty gmock gtest_main) | ||
|
||
GTEST_DISCOVER_TESTS(snl_liberty_tests) |
Oops, something went wrong.