Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hdlmake
Manage
Activity
Members
Labels
Plan
Issues
20
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Projects
Hdlmake
Commits
0b196b78
Commit
0b196b78
authored
11 years ago
by
Paweł Szostek
Browse files
Options
Downloads
Patches
Plain Diff
add TW's vhdl parser (not coupled yet)
parent
8cdbe392
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/vhdl_parser.py
+122
-0
122 additions, 0 deletions
src/vhdl_parser.py
with
122 additions
and
0 deletions
src/vhdl_parser.py
0 → 100755
+
122
−
0
View file @
0b196b78
#!/usr/bin/python
def
remove_gaps
(
buf
,
delims
,
gap_chars
,
lower_strings
=
False
):
da
=
{}
for
d
in
delims
:
da
[
d
]
=
False
prev_is_gap
=
False
buf2
=
""
lines
=
[]
for
c
in
buf
:
for
d
in
delims
:
if
(
c
==
d
):
da
[
d
]
=
not
da
[
d
]
within_string
=
any
(
da
.
values
())
and
not
(
c
in
delims
)
if
(
not
within_string
):
if
(
c
in
gap_chars
):
if
(
not
prev_is_gap
):
prev_is_gap
=
True
buf2
+=
"
"
else
:
prev_is_gap
=
False
buf2
+=
c
if
(
c
==
"
;
"
or
c
==
"
\n
"
):
lines
.
append
(
buf2
);
buf2
=
""
else
:
buf2
+=
c
;
prev_is_gap
=
False
return
lines
from
dep_solver
import
DepParser
,
DepRelation
,
DepFile
class
VHDLParser
(
DepParser
):
def
parse
(
self
,
f_deps
,
filename
):
f
=
open
(
filename
,
"
r
"
)
buf
=
""
# stage 1: strip comments
for
l
in
f
:
ci
=
l
.
find
(
"
--
"
)
if
(
ci
==
0
):
continue
while
(
ci
>
0
):
nquotes
=
l
[:
ci
].
count
(
'"'
)
# ignore comments in strings
if
(
nquotes
%
2
==
0
):
l
=
l
[:
ci
-
1
];
break
ci
=
l
.
find
(
"
--
"
,
ci
+
1
)
buf
+=
l
# stage 2: remove spaces, crs, lfs, strip strings (we don't need them)
buf2
=
""
string_literal
=
char_literal
=
False
prev_is_gap
=
False
gap_chars
=
"
\r\n\t
"
lines
=
[]
for
c
in
buf
:
if
(
c
==
'"'
and
not
char_literal
):
string_literal
=
not
string_literal
if
(
c
==
"'"
and
not
string_literal
):
char_literal
=
not
char_literal
within_string
=
(
string_literal
or
char_literal
)
and
(
c
!=
'"'
)
and
(
c
!=
"'"
)
if
(
not
within_string
):
if
(
c
in
gap_chars
):
if
(
not
prev_is_gap
):
prev_is_gap
=
True
buf2
+=
"
"
else
:
prev_is_gap
=
False
buf2
+=
c
.
lower
()
if
(
c
==
"
;
"
):
lines
.
append
(
buf2
);
buf2
=
""
else
:
prev_is_gap
=
False
import
re
patterns
=
{
"
use
"
:
"
^ *use *(\w+) *\. *(\w+) *. *\w+ *;
"
,
"
entity
"
:
"
^ *entity +(\w+) +is +(port|generic)
"
,
"
package
"
:
"
^ *package +(\w+) +is
"
,
"
arch_begin
"
:
"
^ *architecture +(\w+) +of +(\w+) +is +
"
,
"
arch_end
"
:
"
^ *end +(\w+) +;
"
,
"
instance
"
:
"
^ *(\w+) *\: *(\w+) *(port|generic) *map
"
}
compiled_patterns
=
map
(
lambda
p
:
(
p
,
re
.
compile
(
patterns
[
p
])),
patterns
)
within_architecture
=
False
for
l
in
lines
:
matches
=
filter
(
lambda
(
k
,
v
):
v
!=
None
,
map
(
lambda
(
k
,
v
):
(
k
,
re
.
match
(
v
,
l
)),
compiled_patterns
))
if
(
not
len
(
matches
)):
continue
what
,
g
=
matches
[
0
]
if
(
what
==
"
use
"
):
f_deps
.
add_relation
(
DepRelation
(
g
.
group
(
1
)
+
"
.
"
+
g
.
group
(
2
),
DepRelation
.
USE
,
DepRelation
.
PACKAGE
))
if
(
what
==
"
package
"
):
f_deps
.
add_relation
(
DepRelation
(
g
.
group
(
1
),
DepRelation
.
PROVIDE
,
DepRelation
.
PACKAGE
))
elif
(
what
==
"
entity
"
):
f_deps
.
add_relation
(
DepRelation
(
g
.
group
(
1
),
DepRelation
.
PROVIDE
,
DepRelation
.
ENTITY
))
elif
(
what
==
"
package
"
):
f_deps
.
add_relation
(
DepRelation
(
g
.
group
(
1
),
DepRelation
.
PROVIDE
,
DepRelation
.
PACKAGE
))
elif
(
what
==
"
arch_begin
"
):
arch_name
=
g
.
group
(
1
)
within_architecture
=
True
elif
(
what
==
"
arch_end
"
and
within_architecture
and
g
.
group
(
1
)
==
arch_name
):
within_architecture
=
False
elif
(
what
==
"
instance
"
and
within_architecture
):
f_deps
.
add_relation
(
DepRelation
(
g
.
group
(
1
),
DepRelation
.
USE
,
DepRelation
.
ENTITY
))
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment