Skip to content

Commit 01a6100

Browse files
committed
Initial
0 parents  commit 01a6100

File tree

11 files changed

+472
-0
lines changed

11 files changed

+472
-0
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/.vscode
2+
3+
# patched
4+
libparse.h
5+
libparse.cc
6+
7+
# swig
8+
libparse.py
9+
libparse_wrap.c
10+
libparse_wrap.cxx
11+
12+
# python
13+
__pycache__
14+
15+
# binaries
16+
*.out
17+
*.o
18+
*.a
19+
*.dylib
20+
*.so
21+
*.dll

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "yosys"]
2+
path = yosys
3+
url = https://github.com/yosyshq/yosys

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
CXXFLAGS += -g -std=c++17 -I$(shell python3 -c "import sysconfig; print(sysconfig.get_path('include'))")
3+
4+
5+
all: _libparse.so
6+
7+
_libparse.so: libparse.cc libparse_wrap.cxx libparse.h py_iostream.h
8+
$(CXX) -fPIC -c $(CXXFLAGS) -DFILTERLIB libparse.cc
9+
$(CXX) -fPIC -c $(CXXFLAGS) -DFILTERLIB libparse_wrap.cxx
10+
$(CXX) -shared libparse.o libparse_wrap.o -o $@
11+
12+
libparse.py libparse_wrap.cxx: libparse.i libparse.h
13+
swig -c++ -python $<
14+
15+
libparse.h: yosys/passes/techmap/libparse.h libparse.h.patch
16+
cp $< $@
17+
patch libparse.h libparse.h.patch
18+
19+
libparse.cc: yosys/passes/techmap/libparse.cc
20+
cp $< $@
21+
patch libparse.cc libparse.cc.patch
22+
23+
.PHONY: regen-patches
24+
regen-patches:
25+
diff yosys/passes/techmap/libparse.h libparse.h > libparse.h.patch || true
26+
diff yosys/passes/techmap/libparse.cc libparse.cc > libparse.cc.patch || true
27+
28+
.PHONY: clean
29+
clean:
30+
rm -f libparse*.cc libparse*.cxx libparse.h libparse.py
31+
rm -f *.so *.o *.dylib *.dll

libparse.cc.patch

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
40,41d39
2+
< for (auto child : children)
3+
< delete child;
4+
45c43
5+
< LibertyAst *LibertyAst::find(std::string name)
6+
---
7+
> std::shared_ptr<LibertyAst> LibertyAst::find(std::string name)
8+
185c183
9+
< LibertyAst *LibertyParser::parse()
10+
---
11+
> std::shared_ptr<LibertyAst> LibertyParser::parse()
12+
225c223
13+
< LibertyAst *ast = new LibertyAst;
14+
---
15+
> auto ast = std::make_shared<LibertyAst>();
16+
340c338
17+
< LibertyAst *child = parse();
18+
---
19+
> auto child = parse();
20+
409c407
21+
< LibertyAst *find_non_null(LibertyAst *node, const char *name)
22+
---
23+
> std::shared_ptr<LibertyAst> find_non_null(std::shared_ptr<LibertyAst> node, const char *name)
24+
411c409
25+
< LibertyAst *ret = node->find(name);
26+
---
27+
> auto ret = node->find(name);
28+
458c456
29+
< void event2vl(LibertyAst *ast, std::string &edge, std::string &expr)
30+
---
31+
> void event2vl(std::shared_ptr<LibertyAst> ast, std::string &edge, std::string &expr)
32+
492c490
33+
< void gen_verilogsim_cell(LibertyAst *ast)
34+
---
35+
> void gen_verilogsim_cell(std::shared_ptr<LibertyAst> ast)
36+
525,526c523,524
37+
< LibertyAst *dir = find_non_null(child, "direction");
38+
< LibertyAst *func = child->find("function");
39+
---
40+
> auto dir = find_non_null(child, "direction");
41+
> auto func = child->find("function");
42+
652c650
43+
< void gen_verilogsim(LibertyAst *ast)
44+
---
45+
> void gen_verilogsim(std::shared_ptr<LibertyAst> ast)

libparse.h.patch

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
1a2,20
2+
> Modifications performed by Efabless Corporation to use automatic memory
3+
> management. License follows:
4+
>
5+
> Copyright (C) 2023 Efabless Corporation
6+
>
7+
> Licensed under the Apache License, Version 2.0 (the "License");
8+
> you may not use this file except in compliance with the License.
9+
> You may obtain a copy of the License at
10+
>
11+
> http://www.apache.org/licenses/LICENSE-2.0
12+
>
13+
> Unless required by applicable law or agreed to in writing, software
14+
> distributed under the License is distributed on an "AS IS" BASIS,
15+
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
> See the License for the specific language governing permissions and
17+
> limitations under the License.
18+
> */
19+
>
20+
> /*
21+
26a46
22+
> #include <memory>
23+
34c54
24+
< std::vector<LibertyAst*> children;
25+
---
26+
> std::vector<std::shared_ptr<LibertyAst>> children;
27+
36c56
28+
< LibertyAst *find(std::string name);
29+
---
30+
> std::shared_ptr<LibertyAst> find(std::string name);
31+
46c66
32+
< LibertyAst *ast;
33+
---
34+
> std::shared_ptr<LibertyAst> ast;
35+
48d67
36+
< ~LibertyParser() { if (ast) delete ast; }
37+
57c76
38+
< LibertyAst *parse();
39+
---
40+
> std::shared_ptr<LibertyAst> parse();

libparse.i

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* File: libparse.i */
2+
%module libparse
3+
%include <std_string.i>
4+
%include <std_vectora.i>
5+
%include <std_shared_ptr.i>
6+
7+
%{
8+
#define SWIG_FILE_WITH_INIT
9+
#include <iostream>
10+
#include <memory>
11+
#include "libparse.h"
12+
#include "py_iostream.h"
13+
%}
14+
15+
16+
%shared_ptr(Yosys::LibertyAst)
17+
%immutable Yosys::LibertyParser::f;
18+
%template(VectorLibertyAstSP) std::vector< std::shared_ptr<Yosys::LibertyAst> >;
19+
%template(VectorStr) std::vector< std::string >;
20+
21+
%typemap(in) std::istream& {
22+
try {
23+
$1 = new PyIStream($input);
24+
} catch (std::runtime_error &e) {
25+
PyErr_SetString(PyExc_TypeError, e.what());
26+
}
27+
}
28+
29+
%typemap(freearg) std::istream& {
30+
delete $1;
31+
}
32+
33+
%include "libparse.h"

0 commit comments

Comments
 (0)