2020#include " tc/core/tc2halide.h"
2121#include " tc/lang/parser.h"
2222#include " tc/lang/sema.h"
23+ #include " tc/utils/compiler_options.h"
2324
2425namespace tc2halide {
2526
@@ -270,7 +271,7 @@ void forwardBoundsInference(
270271 const std::vector<Expr>& exprs,
271272 const FunctionBounds& bounds,
272273 const lang::TreeRef& comprehension,
273- bool throwWarnings ,
274+ const tc::CompilerOptions& compilerOptions ,
274275 Scope<Interval>* solution) {
275276 class CreateConstraints : public IRVisitor {
276277 using IRVisitor::visit;
@@ -488,10 +489,10 @@ void forwardBoundsInference(
488489 lang::ErrorReport err (comprehension);
489490 err << " Required precondition will not be checked at runtime: "
490491 << remaining;
491- if (throwWarnings) {
492+ if (compilerOptions. throwWarnings ) {
492493 throw err;
493494 } else {
494- warn (err);
495+ warn (err, compilerOptions );
495496 }
496497 }
497498}
@@ -509,7 +510,7 @@ Expr reductionUpdate(Expr e) {
509510void translateComprehension (
510511 const lang::Comprehension& comprehension,
511512 const map<string, Parameter>& params,
512- bool throwWarnings ,
513+ const tc::CompilerOptions& compilerOptions ,
513514 map<string, Function>* funcs,
514515 FunctionBounds* bounds) {
515516 Function f;
@@ -670,7 +671,7 @@ void translateComprehension(
670671 // Infer the rest
671672 all_exprs.push_back (rhs);
672673 forwardBoundsInference (
673- all_exprs, *bounds, comprehension, throwWarnings , &solution);
674+ all_exprs, *bounds, comprehension, compilerOptions , &solution);
674675
675676 // TODO: What if subsequent updates have incompatible bounds
676677 // (e.g. an in-place stencil)?. The .bound directive will use the
@@ -754,7 +755,9 @@ void translateComprehension(
754755}
755756
756757// Translate a semantically checked TC def to HalideComponents struct.
757- HalideComponents translateDef (const lang::Def& def, bool throwWarnings) {
758+ HalideComponents translateDef (
759+ const lang::Def& def,
760+ const tc::CompilerOptions& compilerOptions) {
758761 map<string, Function> funcs;
759762 HalideComponents components;
760763 components.def = def;
@@ -765,7 +768,7 @@ HalideComponents translateDef(const lang::Def& def, bool throwWarnings) {
765768 }
766769 for (auto c : def.statements ()) {
767770 translateComprehension (
768- c, components.params , throwWarnings , &funcs, &bounds);
771+ c, components.params , compilerOptions , &funcs, &bounds);
769772 }
770773 vector<Function> outputs;
771774 for (auto p : def.returns ()) {
@@ -906,19 +909,24 @@ HalideComponents translateDef(const lang::Def& def, bool throwWarnings) {
906909}
907910} // namespace
908911
909- HalideComponents
910- translate (isl::ctx ctx, const lang::TreeRef& treeRef, bool throwWarnings) {
912+ HalideComponents translate (
913+ isl::ctx ctx,
914+ const lang::TreeRef& treeRef,
915+ const tc::CompilerOptions& compilerOptions = tc::CompilerOptions()) {
911916 LOG_IF (INFO, tc::FLAGS_debug_halide) << treeRef;
912917 return translateDef (
913- lang::Def (lang::Sema ().checkFunction (treeRef)), throwWarnings);
918+ lang::Def (lang::Sema (compilerOptions).checkFunction (treeRef)),
919+ compilerOptions);
914920}
915921
916922// NOTE: there is no guarantee here that the tc string has only one def. It
917923// could have many defs. Only first def will be converted in that case.
918- HalideComponents
919- translate (isl::ctx ctx, const std::string& tc, bool throwWarnings) {
924+ HalideComponents translate (
925+ isl::ctx ctx,
926+ const std::string& tc,
927+ const tc::CompilerOptions& compilerOptions = tc::CompilerOptions()) {
920928 LOG_IF (INFO, tc::FLAGS_debug_halide) << tc;
921- return translate (ctx, lang::Parser (tc).parseFunction (), throwWarnings );
929+ return translate (ctx, lang::Parser (tc).parseFunction (), compilerOptions );
922930}
923931
924932} // namespace tc2halide
0 commit comments