-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[libc] added newhdrgen class implementation #96710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e50a92a
[libc] added newhdrgen class implementation
RoseZhang03 a2120c2
resolved formatting issues, set Function arguments parameter as a dic…
RoseZhang03 3003152
used Black Formatter
RoseZhang03 0fc4225
nit: Function class parameter standard changed to standards since it …
RoseZhang03 3295adc
updated self.standard to be called self.standards
RoseZhang03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
libc/newhdrgen/class_implementation/classes/enumeration.py
This file contains hidden or 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,21 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ====-- Enumeration class for libc function headers ----------*- python -*--==# | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ==-------------------------------------------------------------------------==# | ||
|
||
|
||
class Enumeration: | ||
def __init__(self, name, value=None): | ||
self.name = name | ||
self.value = value | ||
|
||
def __str__(self): | ||
if self.value != None: | ||
return f"{self.name} = {self.value}" | ||
else: | ||
return f"{self.name}" |
This file contains hidden or 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 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ====-- Function class for libc function headers -------------*- python -*--==# | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ==-------------------------------------------------------------------------==# | ||
|
||
|
||
class Function: | ||
def __init__( | ||
self, standards, return_type, name, arguments, guard=None, attributes=[] | ||
): | ||
self.standards = standards | ||
self.return_type = return_type | ||
self.name = name | ||
self.arguments = [arg["type"] for arg in arguments] | ||
self.guard = guard | ||
self.attributes = attributes | ||
|
||
def __str__(self): | ||
args_str = ", ".join(self.arguments) | ||
attributes_str = " ".join(self.attributes) | ||
result = f"{self.return_type} {self.name}({args_str}){attributes_str};" | ||
if self.guard: | ||
result = f"#ifdef {self.guard}\n{result}\n#endif // {self.guard}" | ||
return result |
This file contains hidden or 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 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ====-- Include class for libc function headers --------------*- python -*--==# | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ==-------------------------------------------------------------------------==# | ||
|
||
|
||
class Include: | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
def __str__(self): | ||
return f'#include "{self.name}"' |
This file contains hidden or 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,21 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ====-- Macro class for libc function headers ----------------*- python -*--==# | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ==-------------------------------------------------------------------------==# | ||
|
||
|
||
class Macro: | ||
def __init__(self, name, value=None): | ||
self.name = name | ||
self.value = value | ||
|
||
def __str__(self): | ||
if self.value != None: | ||
return f"#define {self.name} {self.value}" | ||
else: | ||
return f"#define {self.name}" |
This file contains hidden or 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,18 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ====-- Object class for libc function headers ---------------*- python -*--==# | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ==-------------------------------------------------------------------------==# | ||
|
||
|
||
class Object: | ||
def __init__(self, name, type): | ||
self.name = name | ||
self.type = type | ||
|
||
def __str__(self): | ||
return f"extern {self.type} {self.name}" |
This file contains hidden or 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 @@ | ||
#!/usr/bin/env python | ||
# | ||
# ====-- Type class for libc function headers -----------------*- python -*--==# | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# ==-------------------------------------------------------------------------==# | ||
|
||
|
||
class Type: | ||
def __init__(self, type_name): | ||
self.type_name = type_name | ||
|
||
def __str__(self): | ||
return f"#include <llvm-libc-types/{self.type_name}.h>" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we extract just the type for the argument? Don't we need the identifier? Parameter attributes?
What fields are you expecting an
arg
to have?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way we use arguments in the Yaml file is carrying the parameter type so we can identify it as type in arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have this in case we end up having to separate the argument type into prefix, name, suffix. If it is confirmed that we don't need to do so, we can easily remove "type:" so that it is a regular list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we end up adding more fields to an
argument
, then we might want just to keep aFunction
'sarguments
as a list of dict's rather than list of strings of the parameter types. But I'll leave that up to later patches that make use of these objects.