Add assert() statement support. Issue #106.

This commit is contained in:
Matt Pharr
2011-10-15 13:22:38 -07:00
parent 1ab05c0351
commit 422b8268a9
14 changed files with 289 additions and 3 deletions

25
stmt.h
View File

@@ -305,4 +305,29 @@ public:
};
/** @brief Representation of an assert statement in the program.
Like print() above, since we don't have strings as first-class types in
the language, we need to do some gymnastics to support it. Like
assert() in C, assert checks the given condition and prints an error
and calls abort if the condition fails. For varying conditions, the
assert triggers if it's true for any of the program instances.
*/
class AssertStmt : public Stmt {
public:
AssertStmt(const std::string &msg, Expr *e, SourcePos p);
void EmitCode(FunctionEmitContext *ctx) const;
void Print(int indent) const;
Stmt *Optimize();
Stmt *TypeCheck();
int EstimateCost() const;
/** Message to print if the assertion fails. */
const std::string message;
/** The expression to be evaluated (that is asserted to be true). */
Expr *expr;
};
#endif // ISPC_STMT_H