-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
145 additions
and
22 deletions.
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
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
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
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
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,26 @@ | ||
#ifndef OCCA_LANG_TRANSFORMS_BUILTINS_RESTRICT_HEADER | ||
#define OCCA_LANG_TRANSFORMS_BUILTINS_RESTRICT_HEADER | ||
|
||
#include <occa/lang/transforms/statementTransform.hpp> | ||
|
||
namespace occa { | ||
namespace lang { | ||
class qualifier_t; | ||
|
||
namespace transforms { | ||
class restrict : public statementTransform { | ||
public: | ||
const qualifier_t &restrictQualifier; | ||
|
||
restrict(const qualifier_t &restrictQualifier_); | ||
|
||
virtual statement_t* transformStatement(statement_t &smnt); | ||
}; | ||
|
||
bool applyRestrictTransforms(statement_t &smnt, | ||
const qualifier_t &restrictQualifier); | ||
} | ||
} | ||
} | ||
|
||
#endif |
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
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
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
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
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,49 @@ | ||
#include <occa/lang/statement.hpp> | ||
#include <occa/lang/variable.hpp> | ||
#include <occa/lang/qualifier.hpp> | ||
#include <occa/lang/builtins/types.hpp> | ||
#include <occa/lang/transforms/builtins/restrict.hpp> | ||
|
||
namespace occa { | ||
namespace lang { | ||
namespace transforms { | ||
restrict::restrict(const qualifier_t &restrictQualifier_) : | ||
restrictQualifier(restrictQualifier_) { | ||
validStatementTypes = (statementType::functionDecl | | ||
statementType::function); | ||
} | ||
|
||
statement_t* restrict::transformStatement(statement_t &smnt) { | ||
function_t &func = ( | ||
(smnt.type() & statementType::function) | ||
? smnt.to<functionStatement>().function | ||
: smnt.to<functionDeclStatement>().function | ||
); | ||
|
||
const int argc = (int) func.args.size(); | ||
for (int i = 0; i < argc; ++i) { | ||
variable_t *arg = func.args[i]; | ||
if (arg && arg->hasAttribute("restrict")) { | ||
const int pointerCount = (int) arg->vartype.pointers.size(); | ||
if (pointerCount) { | ||
arg->vartype.pointers[pointerCount - 1] += restrictQualifier; | ||
} else { | ||
arg->attributes["restrict"].printError( | ||
"[@restrict] can only be applied to pointer function arguments" | ||
); | ||
return NULL; | ||
} | ||
} | ||
} | ||
|
||
return &smnt; | ||
} | ||
|
||
bool applyRestrictTransforms(statement_t &smnt, | ||
const qualifier_t &restrictQualifier) { | ||
restrict restrictTransform(restrictQualifier); | ||
return restrictTransform.statementTransform::apply(smnt); | ||
} | ||
} | ||
} | ||
} |
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