From c1ece9d1894bc768deb04fd5c255fa58325e060f Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Wed, 29 Nov 2017 16:07:46 +0100 Subject: [PATCH] Add compilation options in the faustassert message. --- compiler/errors/errormsg.cpp | 13 +++++++ compiler/errors/errormsg.hh | 4 +- compiler/errors/exception.hh | 10 +---- compiler/generator/code_container.cpp | 2 +- compiler/generator/code_container.hh | 38 +----------------- .../generator/wasm/wasm_code_container.cpp | 4 +- .../generator/wasm/wast_code_container.cpp | 4 +- compiler/global.cpp | 39 ++++++++++++++++++- compiler/global.hh | 2 + 9 files changed, 62 insertions(+), 54 deletions(-) diff --git a/compiler/errors/errormsg.cpp b/compiler/errors/errormsg.cpp index faf3dd0632..cabd400b5a 100644 --- a/compiler/errors/errormsg.cpp +++ b/compiler/errors/errormsg.cpp @@ -30,6 +30,19 @@ using namespace std; const char* yyfilename = "????"; +void faustassert(bool cond) +{ + if (!cond) { + #ifndef EMCC + stacktrace(20); + #endif + std::stringstream str; + str << "ASSERT : please report the stack trace and the failing DSP file to Faust developers ("; + gGlobal->printCompilationOptions(str); str << ")\n"; + throw faustexception(str.str()); + } +} + void lexerror(const char* msg) { string fullmsg = "ERROR : " + string(msg) + '\n'; diff --git a/compiler/errors/errormsg.hh b/compiler/errors/errormsg.hh index bc66a79f51..3527d8750a 100644 --- a/compiler/errors/errormsg.hh +++ b/compiler/errors/errormsg.hh @@ -24,8 +24,8 @@ #include "tlib.hh" -extern int yylineno; -extern const char * yyfilename; +extern int yylineno; +extern const char* yyfilename; // associate and retrieve file and line properties to a symbol definition void setDefProp(Tree sym, const char* filename, int lineno); diff --git a/compiler/errors/exception.hh b/compiler/errors/exception.hh index 29d18d3043..e3b3a27d19 100644 --- a/compiler/errors/exception.hh +++ b/compiler/errors/exception.hh @@ -77,14 +77,6 @@ inline void stacktrace(int val) #endif } -inline void faustassert(bool cond) -{ - if (!cond) { - #ifndef EMCC - stacktrace(20); - #endif - throw faustexception("ASSERT : please report the stack trace and the failing DSP file to Faust developers.\n"); - } -} +void faustassert(bool cond); #endif diff --git a/compiler/generator/code_container.cpp b/compiler/generator/code_container.cpp index 883312364e..2e146732da 100644 --- a/compiler/generator/code_container.cpp +++ b/compiler/generator/code_container.cpp @@ -743,7 +743,7 @@ void CodeContainer::generateJSON(JSONInstVisitor* visitor) { // Prepare compilation options stringstream options; - printCompilationOptions(options); + gGlobal->printCompilationOptions(options); visitor->init("", fNumInputs, fNumOutputs, "", "", FAUSTVERSION, options.str(), "", std::map()); generateUserInterface(visitor); diff --git a/compiler/generator/code_container.hh b/compiler/generator/code_container.hh index b954603418..dd6e365a39 100644 --- a/compiler/generator/code_container.hh +++ b/compiler/generator/code_container.hh @@ -130,42 +130,6 @@ class CodeContainer : public virtual Garbageable { void generateDAGLoopAux(CodeLoop* loop, BlockInst* loop_code, DeclareVarInst* count, int loop_num, bool omp = false); void generateDAGLoopInternal(CodeLoop* loop, BlockInst* block, DeclareVarInst* count, bool omp); - void printCompilationOptions(ostream& dst) - { - if (gGlobal->gSchedulerSwitch) { - dst << "-sch" - << " -vs " << gGlobal->gVecSize - << ((gGlobal->gFunTaskSwitch) ? " -fun" : "") - << ((gGlobal->gGroupTaskSwitch) ? " -g" : "") - << ((gGlobal->gDeepFirstSwitch) ? " -dfs" : "") - << ((gGlobal->gFloatSize == 2) ? " -double" : (gGlobal->gFloatSize == 3) ? " -quad" : "") - << " -ftz " << gGlobal->gFTZMode - << ((gGlobal->gMemoryManager) ? " -mem" : ""); - } else if (gGlobal->gVectorSwitch) { - dst << "-vec" << " -lv " << gGlobal->gVectorLoopVariant - << " -vs " << gGlobal->gVecSize - << ((gGlobal->gFunTaskSwitch) ? " -fun" : "") - << ((gGlobal->gGroupTaskSwitch) ? " -g" : "") - << ((gGlobal->gDeepFirstSwitch) ? " -dfs" : "") - << ((gGlobal->gFloatSize == 2) ? " -double" : (gGlobal->gFloatSize == 3) ? " -quad" : "") - << " -ftz " << gGlobal->gFTZMode - << ((gGlobal->gMemoryManager) ? " -mem" : ""); - } else if (gGlobal->gOpenMPSwitch) { - dst << "-omp" << " -vs " << gGlobal->gVecSize - << " -vs " << gGlobal->gVecSize - << ((gGlobal->gFunTaskSwitch) ? " -fun" : "") - << ((gGlobal->gGroupTaskSwitch) ? " -g" : "") - << ((gGlobal->gDeepFirstSwitch) ? " -dfs" : "") - << ((gGlobal->gFloatSize == 2) ? " -double" : (gGlobal->gFloatSize == 3) ? " -quad" : "") - << " -ftz " << gGlobal->gFTZMode - << ((gGlobal->gMemoryManager) ? " -mem" : ""); - } else { - dst << ((gGlobal->gFloatSize == 1) ? "-scal" : ((gGlobal->gFloatSize == 2) ? "-double" : (gGlobal->gFloatSize == 3) ? "-quad" : "")) - << " -ftz " << gGlobal->gFTZMode - << ((gGlobal->gMemoryManager) ? " -mem" : ""); - } - } - void printHeader(ostream& dst) { // defines the metadata we want to print as comments at the begin of in the file @@ -191,7 +155,7 @@ class CodeContainer : public virtual Garbageable { dst << "Code generated with Faust " << FAUSTVERSION << " (https://faust.grame.fr)" << endl; dst << "Compilation options: "; - printCompilationOptions(dst); + gGlobal->printCompilationOptions(dst); dst << "\n------------------------------------------------------------ */" << endl; } diff --git a/compiler/generator/wasm/wasm_code_container.cpp b/compiler/generator/wasm/wasm_code_container.cpp index 1cc29ea0de..c67cfc720b 100644 --- a/compiler/generator/wasm/wasm_code_container.cpp +++ b/compiler/generator/wasm/wasm_code_container.cpp @@ -318,7 +318,7 @@ void WASMCodeContainer::produceClass() // Prepare compilation options stringstream options; - printCompilationOptions(options); + gGlobal->printCompilationOptions(options); stringstream size; size << gGlobal->gWASMVisitor->getStructSize(); @@ -359,7 +359,7 @@ void WASMCodeContainer::produceClass() // Generate JSON and getSize tab(n, fHelper); fHelper << "/*\n" << "Code generated with Faust version " << FAUSTVERSION << endl; fHelper << "Compilation options: "; - printCompilationOptions(fHelper); + gGlobal->printCompilationOptions(fHelper); fHelper << "\n*/\n"; // Generate JSON diff --git a/compiler/generator/wasm/wast_code_container.cpp b/compiler/generator/wasm/wast_code_container.cpp index 8dc7cf8b3c..a49b8536fb 100644 --- a/compiler/generator/wasm/wast_code_container.cpp +++ b/compiler/generator/wasm/wast_code_container.cpp @@ -276,7 +276,7 @@ void WASTCodeContainer::produceClass() // Prepare compilation options stringstream options; - printCompilationOptions(options); + gGlobal->printCompilationOptions(options); stringstream size; size << gGlobal->gWASTVisitor->getStructSize(); @@ -330,7 +330,7 @@ void WASTCodeContainer::produceClass() // Generate JSON and getSize tab(n, fHelper); fHelper << "/*\n" << "Code generated with Faust version " << FAUSTVERSION << endl; fHelper << "Compilation options: "; - printCompilationOptions(fHelper); + gGlobal->printCompilationOptions(fHelper); fHelper << "\n*/\n"; // Generate JSON diff --git a/compiler/global.cpp b/compiler/global.cpp index 429f39b404..3a0e7cf7fa 100644 --- a/compiler/global.cpp +++ b/compiler/global.cpp @@ -538,7 +538,44 @@ void global::init() gInjectFlag = false; // inject an external source file into the architecture file gInjectFile = ""; // instead of a compiled dsp file } - + +void global::printCompilationOptions(ostream& dst) +{ + if (gSchedulerSwitch) { + dst << "-sch" + << " -vs " << gVecSize + << ((gFunTaskSwitch) ? " -fun" : "") + << ((gGroupTaskSwitch) ? " -g" : "") + << ((gDeepFirstSwitch) ? " -dfs" : "") + << ((gFloatSize == 2) ? " -double" : (gFloatSize == 3) ? " -quad" : "") + << " -ftz " << gFTZMode + << ((gMemoryManager) ? " -mem" : ""); + } else if (gVectorSwitch) { + dst << "-vec" << " -lv " << gVectorLoopVariant + << " -vs " << gVecSize + << ((gFunTaskSwitch) ? " -fun" : "") + << ((gGroupTaskSwitch) ? " -g" : "") + << ((gDeepFirstSwitch) ? " -dfs" : "") + << ((gFloatSize == 2) ? " -double" : (gFloatSize == 3) ? " -quad" : "") + << " -ftz " << gFTZMode + << ((gMemoryManager) ? " -mem" : ""); + } else if (gOpenMPSwitch) { + dst << "-omp" << " -vs " << gVecSize + << " -vs " << gVecSize + << ((gFunTaskSwitch) ? " -fun" : "") + << ((gGroupTaskSwitch) ? " -g" : "") + << ((gDeepFirstSwitch) ? " -dfs" : "") + << ((gFloatSize == 2) ? " -double" : (gFloatSize == 3) ? " -quad" : "") + << " -ftz " << gFTZMode + << ((gMemoryManager) ? " -mem" : ""); + } else { + dst << ((gFloatSize == 1) ? "-scal" : ((gFloatSize == 2) ? "-double" : (gFloatSize == 3) ? "-quad" : "")) + << " -ftz " << gFTZMode + << ((gMemoryManager) ? " -mem" : ""); + } +} + + global::~global() { Garbageable::cleanup(); diff --git a/compiler/global.hh b/compiler/global.hh index e2a111a4f3..29914a6afd 100644 --- a/compiler/global.hh +++ b/compiler/global.hh @@ -532,6 +532,8 @@ struct global { { return gVarTypeTable[name]->getType(); } + + void printCompilationOptions(ostream& dst); }; // Unique shared global pointer