Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Commits
976c63a8
Verified
Commit
976c63a8
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
refactor(genapi): Save offset
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
06df747a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!9
Refactor genapi.py script
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/api/genapi.py
+6
-7
6 additions, 7 deletions
epicardium/api/genapi.py
with
6 additions
and
7 deletions
epicardium/api/genapi.py
+
6
−
7
View file @
976c63a8
...
...
@@ -11,6 +11,11 @@ MATCH_DECLARATION = re.compile(
MATCH_ARGS
=
re
.
compile
(
r
"
(?P<type>\w+(?:\*+|\s+))(?P<name>\w+),
"
)
def
sizeof
(
args
):
"""
Return a string that describes the size of a list of arguments.
"""
return
"
+
"
.
join
(
a
[
"
sizeof
"
]
for
a
in
args
)
if
args
!=
[]
else
"
0
"
def
parse_declarations
(
source
):
"""
Parse all declarations in the given source.
"""
declarations
=
[]
...
...
@@ -30,6 +35,7 @@ def parse_declarations(source):
"
type
"
:
arg_type
,
"
name
"
:
arg_name
,
"
sizeof
"
:
"
sizeof({})
"
.
format
(
arg_type
),
"
offset
"
:
sizeof
(
args
),
})
declarations
.
append
({
...
...
@@ -43,11 +49,6 @@ def parse_declarations(source):
return
declarations
def
sizeof
(
args
):
"""
Return a string that describes the size of a list of arguments.
"""
return
"
+
"
.
join
(
a
[
"
sizeof
"
]
for
a
in
args
)
if
args
!=
[]
else
"
0
"
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
"
Generate the API stubs from a header file.
"
...
...
@@ -112,7 +113,6 @@ def main():
f_client
.
write
(
tmp
.
format
(
**
decl
))
for
i
,
arg
in
enumerate
(
decl
[
"
args
"
]):
arg
[
"
offset
"
]
=
sizeof
(
decl
[
"
args
"
][:
i
])
tmp
=
"""
\
*({type}*)(buffer + {offset}) = {name};
"""
...
...
@@ -161,7 +161,6 @@ void __api_dispatch_call(uint32_t id, void*buffer)
for
i
,
arg
in
enumerate
(
decl
[
"
args
"
]):
arg
[
"
comma
"
]
=
""
if
i
==
0
else
"
,
"
arg
[
"
offset
"
]
=
sizeof
(
decl
[
"
args
"
][:
i
])
tmp
=
"""
{comma}
*({type}*)(buffer + {offset})
"""
f_dispatcher
.
write
(
tmp
.
format
(
**
arg
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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