From 53f500644fd00f85d792ce94d045d4ea5054ff60 Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Fri, 30 Aug 2024 11:21:45 +0200 Subject: [PATCH] Interp backend working. --- compiler/generator/code_container.cpp | 17 +++++++++++++---- compiler/generator/instructions.hh | 4 ++-- compiler/generator/instructions_compiler.cpp | 4 ++++ compiler/global.cpp | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/compiler/generator/code_container.cpp b/compiler/generator/code_container.cpp index 74140f1c0c..4c48bbb573 100644 --- a/compiler/generator/code_container.cpp +++ b/compiler/generator/code_container.cpp @@ -502,6 +502,15 @@ void CodeContainer::processFIR(void) fCurLoop->generateScalarLoop("count")); endTiming("FIR var checker"); } + +#ifdef FIR_BUILD + if (global::isDebug("FIR_PRINTER")) { + stringstream res; + FIRInstVisitor fir_visitor(&res); + flattenFIR()->accept(&fir_visitor); + std::cout << res.str(); + } +#endif } // Possibly rewrite arrays access using iZone/fZone @@ -538,7 +547,7 @@ void CodeContainer::rewriteInZones() void CodeContainer::mergeSubContainers() { BlockInst* sub_ui = new BlockInst(); - + for (const auto& it : fSubContainers) { // Merge the subcontainer in the main one fExtGlobalDeclarationInstructions->merge(it->fExtGlobalDeclarationInstructions); @@ -556,9 +565,9 @@ void CodeContainer::mergeSubContainers() it->fUserInterfaceInstructions->fCode.clear(); it->fStaticInitInstructions->fCode.clear(); } - - // Insert subcontainer UIs at the end the top group, just before the last closeBox - fUserInterfaceInstructions->insert(fUserInterfaceInstructions->size()-1, sub_ui); + + // Insert subcontainer UIs at the end the top group, just before the last closeBox + fUserInterfaceInstructions->insert(fUserInterfaceInstructions->size() - 1, sub_ui); // Possibly rewrite access in iZone/fZone rewriteInZones(); diff --git a/compiler/generator/instructions.hh b/compiler/generator/instructions.hh index 21423b27b8..7a49e0fa15 100644 --- a/compiler/generator/instructions.hh +++ b/compiler/generator/instructions.hh @@ -1008,14 +1008,14 @@ struct BlockInst : public StatementInst { fCode.push_back(it); } } - + void mergeFront(BlockInst* inst) { for (const auto& it : inst->fCode) { fCode.push_front(it); } } - + void insert(int index, BlockInst* inst) { auto it = fCode.begin(); diff --git a/compiler/generator/instructions_compiler.cpp b/compiler/generator/instructions_compiler.cpp index 4a11fdcd16..e789f78de1 100644 --- a/compiler/generator/instructions_compiler.cpp +++ b/compiler/generator/instructions_compiler.cpp @@ -28,6 +28,7 @@ #include "instructions_compiler.hh" #include "instructions_compiler1.hh" #include "instructions_compiler_jax.hh" +#include "interpreter_code_container.hh" #include "normalform.hh" #include "prim2.hh" #include "recursivness.hh" @@ -429,6 +430,9 @@ CodeContainer* InstructionsCompiler::signal2Container(const string& name, Tree s } else if (gGlobal->gOutputLang == "jax") { InstructionsCompilerJAX C(container); C.compileSingleSignal(sig); + } else if (gGlobal->gOutputLang == "interp") { + InterpreterInstructionsCompiler C(container); + C.compileSingleSignal(sig); } else { // Special compiler for -fx mode if (gGlobal->gFloatSize == 4) { diff --git a/compiler/global.cpp b/compiler/global.cpp index d33a60e07e..c45b08cf7b 100644 --- a/compiler/global.cpp +++ b/compiler/global.cpp @@ -2477,6 +2477,7 @@ string global::printHelp() << endl; sstr << tab << "FAUST_DEBUG = FAUST_LLVM2 print LLVM IR after optimisation." << endl; + sstr << tab << "FAUST_DEBUG = FIR_PRINTER print FIR after generation." << endl; sstr << tab << "FAUST_DEBUG = FAUST_LLVM_NO_FM deactivate fast-math optimisation in LLVM IR." << endl;