This repository has been archived by the owner on Jun 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
In-memory AST for generated C source code #60
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4f10b1c
added print statements to compare output
navjotk e7e95dd
define_constants and define_fields now using cgen. But returning stri…
navjotk 6c6d957
store_fields now using cgen
navjotk 90f22b7
store_fields now using cgen
navjotk 3291996
load_fields now using cgen
navjotk 937ab2f
declare_fields now using cgen
navjotk 17f63e0
read_data now using cgen
navjotk 5ce27ec
simple_loop now using cgen. The read_data process is end-to-end cgen …
navjotk 842e6a3
initialise also now using cgen
navjotk 54e8207
Changed the following functions to use cgen: stress_loop, velocity_lo…
navjotk 1c3dc03
velocity_bc also now uses cgen. Cleaned up the dummy code leftover fr…
navjotk 31226ac
Cleaned up the code in staggeredgrid to use less string manipulation
navjotk af48e62
resolving merge conflicts
navjotk 5ec04a0
Update loop fission code to use cgen style code generation
navjotk 5c1d8e0
Consistent use of cgen.Pragma for all ivdep pragma statements
navjotk 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
This file contains 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,55 @@ | ||
from cgen import * | ||
|
||
|
||
class IfDef(Module): | ||
""" | ||
Class to represent IfDef-Else-EndIf construct for the C preprocessor. | ||
While Cgen has classes for #define, #include, #pragma etc., it has nothing for IfDef. | ||
:param condition: the condition in IfDef | ||
:param iflines: the block of code inside the if [an array of type Generable] | ||
:param elselines: the block of code inside the else [an array of type Generable] | ||
""" | ||
def __init__(self, condition, iflines, elselines): | ||
ifdef_line = Line('#ifdef %s' % condition) | ||
else_line = Line('#else') | ||
endif_line = Line('#endif') | ||
lines = [ifdef_line]+iflines+[else_line]+elselines+[endif_line] | ||
super(IfDef, self).__init__(lines) | ||
|
||
|
||
class InlineInitializer(Initializer): | ||
""" | ||
Class to represent Initializers (int i=0) without the semicolon in the end(e.g. in a for statement) | ||
Usage: same as cgen.Initializer | ||
Result: same as cgen.Initializer except for the lack of a semi-colon at the end | ||
""" | ||
def generate(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. """ docstring please """ |
||
result = super(InlineInitializer, self).generate() | ||
for v in result: | ||
if v.endswith(';'): | ||
yield v[:-1] | ||
else: | ||
yield v | ||
|
||
|
||
def replace_in_code(code, str_from, str_to): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. """ docstring please """ |
||
""" | ||
Helper function to find and replace strings inside code blocks | ||
:param code: The code block in which to carry out the find/replace. This can be array of Generables or a Block or a Loop | ||
:param str_from: The string to find (and to be replaced) | ||
:param str_to: The string to replace all instances of str_from with | ||
""" | ||
if isinstance(code, Block): | ||
replace_in_code(code.contents, str_from, str_to) | ||
return code | ||
if isinstance(code, Loop): | ||
replace_in_code(code.body, str_from, str_to) | ||
return code | ||
for code_element in code: | ||
if isinstance(code_element, Statement) or isinstance(code_element, Line): | ||
code_element.text.replace(str_from, str_to) | ||
if isinstance(code_element, Block): | ||
replace_in_code(code_element.contents, str_from, str_to) | ||
if isinstance(code_element, Loop): | ||
replace_in_code(code_element.body, str_from, str_to) | ||
return code |
This file contains 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
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.
""" docstring please """