1 /************************************************************************ 2 ************************************************************************ 3 FAUST compiler 4 Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale 5 --------------------------------------------------------------------- 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 ************************************************************************ 20 ************************************************************************/ 21 22 #ifndef _DLANG_CODE_CONTAINER_H 23 #define _DLANG_CODE_CONTAINER_H 24 25 #include "code_container.hh" 26 #include "dlang_instructions.hh" 27 #include "dsp_factory.hh" 28 #include "omp_code_container.hh" 29 #include "vec_code_container.hh" 30 #include "wss_code_container.hh" 31 32 #ifdef WIN32 33 #pragma warning(disable : 4250) 34 #endif 35 36 using namespace std; 37 38 class DLangCodeContainer : public virtual CodeContainer { 39 protected: 40 DLangInstVisitor fCodeProducer; 41 std::ostream* fOut; 42 string fSuperKlassName; 43 44 void produceMetadata(int tabs); 45 void produceInit(int tabs); 46 47 public: DLangCodeContainer(const string & name,const string & super,int numInputs,int numOutputs,std::ostream * out)48 DLangCodeContainer(const string& name, const string& super, int numInputs, int numOutputs, std::ostream* out) 49 : fCodeProducer(out), fOut(out), fSuperKlassName(super) 50 { 51 initialize(numInputs, numOutputs); 52 fKlassName = name; 53 } 54 ~DLangCodeContainer()55 virtual ~DLangCodeContainer() {} 56 57 virtual void produceClass(); 58 virtual void generateCompute(int tab) = 0; 59 virtual void produceInternal(); 60 61 void generateImports(); 62 static string dModuleName(const string& klassName); 63 64 virtual dsp_factory_base* produceFactory(); 65 66 virtual void printHeader(); 67 68 static void printDRecipeComment(ostream& dst, const string& klassName); 69 static void printDModuleStmt(ostream& dst, const string& klassName); 70 71 CodeContainer* createScalarContainer(const string& name, int sub_container_type); 72 73 static CodeContainer* createContainer(const string& name, const string& super, int numInputs, int numOutputs, 74 ostream* dst = new stringstream()); 75 }; 76 77 class DLangScalarCodeContainer : public DLangCodeContainer { 78 protected: 79 public: 80 DLangScalarCodeContainer(const string& name, const string& super, int numInputs, int numOutputs, std::ostream* out, 81 int sub_container_type); ~DLangScalarCodeContainer()82 virtual ~DLangScalarCodeContainer() 83 {} 84 85 void generateCompute(int tab); 86 }; 87 88 class DLangScalarOneSampleCodeContainer : public DLangScalarCodeContainer { 89 protected: 90 virtual void produceClass(); 91 public: DLangScalarOneSampleCodeContainer(const string & name,const string & super,int numInputs,int numOutputs,std::ostream * out,int sub_container_type)92 DLangScalarOneSampleCodeContainer(const string& name, const string& super, int numInputs, int numOutputs, std::ostream* out, 93 int sub_container_type) 94 : DLangScalarCodeContainer(name, super, numInputs, numOutputs, out, sub_container_type) 95 {} ~DLangScalarOneSampleCodeContainer()96 virtual ~DLangScalarOneSampleCodeContainer() 97 {} 98 99 void generateCompute(int tab); 100 }; 101 102 class DLangVectorCodeContainer : public VectorCodeContainer, public DLangCodeContainer { 103 protected: 104 public: 105 DLangVectorCodeContainer(const string& name, const string& super, int numInputs, int numOutputs, std::ostream* out); ~DLangVectorCodeContainer()106 virtual ~DLangVectorCodeContainer() 107 {} 108 109 void generateCompute(int tab); 110 }; 111 112 #endif 113