/
surelog.rb
110 lines (104 loc) 路 4.75 KB
/
surelog.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
class Surelog < Formula
desc "SystemVerilog Pre-processor, parser, elaborator, UHDM compiler"
homepage "https://github.com/chipsalliance/Surelog"
url "https://github.com/chipsalliance/Surelog/archive/refs/tags/v1.82.tar.gz"
sha256 "e2c4074f9d35b7a1450b722681d1557bdd4af3de09363dbdb9d0da9cf26b976b"
license "Apache-2.0"
revision 1
head "https://github.com/chipsalliance/Surelog.git", branch: "master"
bottle do
sha256 cellar: :any, arm64_sonoma: "5e059568d44235efdbeaf513460ca46ee1be23b8c00669f5b7c0d93641a7741f"
sha256 cellar: :any, arm64_ventura: "bf1c1030465c42460c24db3295073ce2dba67018e4ee4c8800b1927724d37018"
sha256 cellar: :any, arm64_monterey: "27148e5995701680dcb9482581a4caa491abe75c8149d4487795b2bbee90a9c9"
sha256 cellar: :any, sonoma: "6be4e77c6b7c545133b887d6d9e0a434837832bfb392d46967a4a6d7c5a1328b"
sha256 cellar: :any, ventura: "a014dcb16342815f0dadb977d5a8c66fc19c6631dbf9106f92fcf8d9da6707fa"
sha256 cellar: :any, monterey: "b68a26f046359b0dd25d2de863e36ce3a9a681ac5d892fdb5cbd1726f821f977"
sha256 cellar: :any_skip_relocation, x86_64_linux: "bdc75b1ec247a81d68177ab2f36ea4ba60ef96515d447fbba5dc84b8df32bd59"
end
depends_on "antlr" => :build
depends_on "cmake" => :build
depends_on "nlohmann-json" => :build
depends_on "openjdk" => :build
depends_on "python@3.12" => :build
depends_on "pkg-config" => :test
depends_on "antlr4-cpp-runtime"
depends_on "capnp"
depends_on "uhdm"
def install
antlr = Formula["antlr"]
system "cmake", "-S", ".", "-B", "build",
"-DANTLR_JAR_LOCATION=#{antlr.opt_prefix}/antlr-#{antlr.version}-complete.jar",
"-DBUILD_SHARED_LIBS=ON",
"-DCMAKE_INSTALL_RPATH=#{rpath}",
"-DPython3_EXECUTABLE=#{which("python3.12")}",
"-DSURELOG_BUILD_TESTS=OFF",
"-DSURELOG_USE_HOST_ALL=ON",
"-DSURELOG_WITH_ZLIB=ON",
*std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
end
test do
# ensure linking is ok
system bin/"surelog", "--version"
# ensure library is ok
(testpath/"test.cpp").write <<~EOS
#include <Surelog/API/Surelog.h>
#include <Surelog/CommandLine/CommandLineParser.h>
#include <Surelog/Common/FileSystem.h>
#include <Surelog/Design/Design.h>
#include <Surelog/Design/ModuleInstance.h>
#include <Surelog/ErrorReporting/ErrorContainer.h>
#include <Surelog/SourceCompile/SymbolTable.h>
#include <functional>
#include <iostream>
#include <uhdm/uhdm.h>
int main(int argc, const char** argv) {
uint32_t code = 0;
SURELOG::SymbolTable* symbolTable = new SURELOG::SymbolTable();
SURELOG::ErrorContainer* errors = new SURELOG::ErrorContainer(symbolTable);
SURELOG::CommandLineParser* clp =
new SURELOG::CommandLineParser(errors, symbolTable, false, false);
clp->noPython();
bool success = clp->parseCommandLine(argc, argv);
errors->printMessages(clp->muteStdout());
SURELOG::Design* the_design = nullptr;
SURELOG::scompiler* compiler = nullptr;
if (success && (!clp->help())) {
compiler = SURELOG::start_compiler(clp);
the_design = SURELOG::get_design(compiler);
auto stats = errors->getErrorStats();
code = (!success) | stats.nbFatal | stats.nbSyntax | stats.nbError;
}
if (the_design) {
for (auto& top : the_design->getTopLevelModuleInstances()) {
std::function<void(SURELOG::ModuleInstance*)> inst_visit =
[&inst_visit](SURELOG::ModuleInstance* inst) {
SURELOG::FileSystem* const fileSystem =
SURELOG::FileSystem::getInstance();
std::cout << "Inst: " << inst->getFullPathName() << std::endl;
std::cout << "File: " << fileSystem->toPath(inst->getFileId())
<< std::endl;
for (uint32_t i = 0; i < inst->getNbChildren(); i++) {
inst_visit(inst->getChildren(i));
}
};
inst_visit(top);
}
}
if (success && (!clp->help())) {
SURELOG::shutdown_compiler(compiler);
}
delete clp;
delete symbolTable;
delete errors;
return code;
}
EOS
flags = shell_output("pkg-config --cflags --libs Surelog").chomp.split
system ENV.cxx, testpath/"test.cpp", "-o", "test",
"-L#{Formula["antlr4-cpp-runtime"].opt_prefix}/lib",
"-fPIC", "-std=c++17", *flags
system testpath/"test"
end
end