47
47
#include " timing.hh"
48
48
#include " sharing.hh"
49
49
#include " xtended.hh"
50
+ #include " sigPromotion.hh"
50
51
51
52
using namespace std ;
52
53
@@ -97,6 +98,10 @@ Tree ScalarCompiler::prepare(Tree LS)
97
98
} else if (gGlobal ->gDumpNorm == 1 ) {
98
99
ppsigShared (L1, cout);
99
100
throw faustexception (" Dump shared normal form finished...\n " );
101
+ } else if (gGlobal ->gDumpNorm == 2 ) {
102
+ // Print signal tree type
103
+ SignalTypePrinter printer (L1);
104
+ throw faustexception (" Dump signal type finished...\n " );
100
105
}
101
106
// No more table privatisation
102
107
Tree L2 = L1;
@@ -326,12 +331,13 @@ bool ScalarCompiler::getCompiledExpression(Tree sig, string& cexp)
326
331
*/
327
332
string ScalarCompiler::setCompiledExpression (Tree sig, const string& cexp)
328
333
{
329
- // cerr << "ScalarCompiler::setCompiledExpression : " << cexp << " ==> " << ppsig(sig) << endl;
330
334
string old;
331
335
if (fCompileProperty .get (sig, old) && (old != cexp)) {
332
- // cerr << "ERROR already a compiled expression attached : " << old << " replaced by " << cexp << endl;
333
- // exit(1);
336
+ // stringstream error;
337
+ // error << "ERROR already a compiled expression attached : " << old << " replaced by " << cexp << endl;
338
+ // throw faustexception(error.str());
334
339
}
340
+
335
341
fCompileProperty .set (sig, cexp);
336
342
return cexp;
337
343
}
@@ -347,6 +353,7 @@ string ScalarCompiler::setCompiledExpression(Tree sig, const string& cexp)
347
353
* @param vecname the string representing the vector name.
348
354
* @return true is already compiled
349
355
*/
356
+
350
357
void ScalarCompiler::setVectorNameProperty (Tree sig, const string& vecname)
351
358
{
352
359
faustassert (vecname.size () > 0 );
@@ -371,6 +378,7 @@ bool ScalarCompiler::getVectorNameProperty(Tree sig, string& vecname)
371
378
* @param sig the signal expression to compile.
372
379
* @return the C code translation of sig as a string
373
380
*/
381
+
374
382
string ScalarCompiler::CS (Tree sig)
375
383
{
376
384
// contextor contextRecursivness;
@@ -459,9 +467,9 @@ void ScalarCompiler::compileSingleSignal(Tree sig)
459
467
string ScalarCompiler::generateCode (Tree sig)
460
468
{
461
469
#if 0
462
- fprintf(stderr, "CALL generateCode(");
470
+ fprintf(stderr, "CALL generateCode(");
463
471
printSignal(sig, stderr);
464
- fprintf(stderr, ")\n");
472
+ fprintf(stderr, ")\n");
465
473
#endif
466
474
467
475
int i;
@@ -642,53 +650,13 @@ string ScalarCompiler::generateOutput(Tree sig, const string& idx, const string&
642
650
return dst;
643
651
}
644
652
645
- static int binopPriority (Tree sig)
646
- {
647
- int opcode;
648
- Tree arg1;
649
- Tree arg2;
650
- return isSigBinOp (sig, &opcode, arg1, arg2) ? gBinOpTable [opcode]->fPriority : INT_MAX;
651
- }
652
653
/* ****************************************************************************
653
654
BINARY OPERATION
654
655
*****************************************************************************/
655
656
656
657
string ScalarCompiler::generateBinOp (Tree sig, int opcode, Tree arg1, Tree arg2)
657
658
{
658
- // check the priorities and add parentheses when needed
659
- int p0 = gBinOpTable [opcode]->fPriority ;
660
- int p1 = binopPriority (arg1);
661
- int p2 = binopPriority (arg2);
662
-
663
- bool np1 = (p0 > p1) || isLogicalOpcode (opcode);
664
- bool np2 = (p0 > p2) || isLogicalOpcode (opcode);
665
-
666
- string c1 = CS (arg1);
667
- string c2 = CS (arg2);
668
-
669
- if (opcode == kDiv ) {
670
- // special handling for division, we always want a float division
671
- Type t1 = getCertifiedSigType (arg1);
672
- Type t2 = getCertifiedSigType (arg2);
673
-
674
- if (t1->nature () == kInt && t2->nature () == kInt ) {
675
- return generateCacheCode (sig, subst (" ($3($0) $1 $3($2))" , c1, gBinOpTable [opcode]->fName , c2, ifloat ()));
676
- } else if (t1->nature () == kInt && t2->nature () == kReal ) {
677
- if (np2) c2 = subst (" ($0)" , c2);
678
- return generateCacheCode (sig, subst (" ($3($0) $1 $2)" , c1, gBinOpTable [opcode]->fName , c2, ifloat ()));
679
- } else if (t1->nature () == kReal && t2->nature () == kInt ) {
680
- if (np1) c1 = subst (" ($0)" , c1);
681
- return generateCacheCode (sig, subst (" ($0 $1 $3($2))" , c1, gBinOpTable [opcode]->fName , c2, ifloat ()));
682
- } else {
683
- if (np1) c1 = subst (" ($0)" , c1);
684
- if (np2) c2 = subst (" ($0)" , c2);
685
- return generateCacheCode (sig, subst (" ($0 $1 $2)" , c1, gBinOpTable [opcode]->fName , c2, ifloat ()));
686
- }
687
- } else {
688
- if (np1) c1 = subst (" ($0)" , c1);
689
- if (np2) c2 = subst (" ($0)" , c2);
690
- return generateCacheCode (sig, subst (" ($0 $1 $2)" , c1, gBinOpTable [opcode]->fName , c2));
691
- }
659
+ return generateCacheCode (sig, subst (" ($0 $1 $2)" , CS (arg1), gBinOpTable [opcode]->fName , CS (arg2)));
692
660
}
693
661
694
662
/* ****************************************************************************
@@ -848,7 +816,7 @@ string ScalarCompiler::generateBitCast(Tree sig, Tree x)
848
816
if (gGlobal ->gFloatSize == 1 ) {
849
817
return generateCacheCode (sig, subst (" (*(int*)&$0)" , CS (x)));
850
818
} else if (gGlobal ->gFloatSize == 2 ) {
851
- return generateCacheCode (sig, subst (" ((*(long int *)&$0)" , CS (x)));
819
+ return generateCacheCode (sig, subst (" ((*(int64_t *)&$0)" , CS (x)));
852
820
} else {
853
821
faustassert (false );
854
822
return " " ;
@@ -977,23 +945,13 @@ string ScalarCompiler::generateSoundfile(Tree sig, Tree path)
977
945
{
978
946
string varname = getFreshID (" fSoundfile" );
979
947
980
- // SL
981
- // fClass->addIncludeFile("<atomic>");
982
- // fClass->addIncludeFile("\"faust/gui/soundfile.h\"");
983
-
984
- // SL
985
- // fClass->addDeclCode(subst("std::atomic<Soundfile*> \t$0;", varname));
986
- fClass ->addDeclCode (subst (" Soundfile* \t $0;" , varname));
987
-
988
- // fClass->addDeclCode(subst("Soundfile* \t$0cache;", varname));
989
948
addUIWidget (reverse (tl (path)), uiWidget (hd (path), tree (varname), sig));
990
-
991
- // SL
949
+
950
+ fClass ->addDeclCode (subst (" Soundfile* \t $0;" , varname));
951
+
992
952
fClass ->addInitUICode (subst (" if (uintptr_t($0) == 0) $0 = defaultsound;" , varname));
993
953
fClass ->addFirstPrivateDecl (subst (" $0cache" , varname));
994
954
995
- // SL
996
- // fClass->addZone2(subst("Soundfile* $0cache = $0.exchange(nullptr);", varname));
997
955
fClass ->addZone2 (subst (" Soundfile* $0cache = $0;" , varname));
998
956
fClass ->addZone4 (subst (" $0 = $0cache;" , varname));
999
957
return varname;
@@ -1047,37 +1005,28 @@ string ScalarCompiler::generateTable(Tree sig, Tree tsize, Tree content)
1047
1005
string cexp;
1048
1006
string ctype, vname;
1049
1007
1050
- // already compiled but check if we need to add declarations
1008
+ // Already compiled but check if we need to add declarations
1051
1009
faustassert (isSigGen (content, g));
1052
1010
pair<string, string> kvnames;
1053
1011
if (!fInstanceInitProperty .get (g, kvnames)) {
1054
- // not declared here, we add a declaration
1012
+ // Not declared here, we add a declaration
1055
1013
bool b = fStaticInitProperty .get (g, kvnames);
1056
1014
faustassert (b);
1057
1015
fClass ->addInitCode (subst (" $0 $1;" , kvnames.first , kvnames.second ));
1058
1016
}
1059
1017
1060
- // definition of table name and type
1061
- // TO CHECK !!!!!!!!!
1062
- Type t = getCertifiedSigType (content); // , tEnv);
1063
-
1064
- if (t->nature () == kInt ) {
1065
- vname = getFreshID (" itbl" );
1066
- ctype = " int" ;
1067
- } else {
1068
- vname = getFreshID (" ftbl" );
1069
- ctype = ifloat ();
1070
- }
1071
-
1072
- // table declaration
1018
+ // Define table name and type
1019
+ getTypedNames (getCertifiedSigType (content), " tbl" , ctype, vname);
1020
+
1021
+ // Table declaration
1073
1022
fClass ->addDeclCode (subst (" $0 \t $1[$2];" , ctype, vname, T (size)));
1074
1023
1075
- // initialization of the content generator
1024
+ // Initialization of the content generator
1076
1025
fClass ->addInitCode (subst (" $0.init(sample_rate);" , generator));
1077
- // filling the table
1026
+ // Filling the table
1078
1027
fClass ->addInitCode (subst (" $0.fill($1,$2);" , generator, T (size), vname));
1079
1028
1080
- // returning the table name
1029
+ // Returning the table name
1081
1030
return vname;
1082
1031
}
1083
1032
@@ -1107,19 +1056,11 @@ string ScalarCompiler::generateStaticTable(Tree sig, Tree tsize, Tree content)
1107
1056
}
1108
1057
}
1109
1058
1110
- // definition of table name and type
1111
- // TO CHECK !!!!!!!!!
1112
- Type t = getCertifiedSigType (content); // , tEnv);
1113
-
1114
- if (t->nature () == kInt ) {
1115
- vname = getFreshID (" itbl" );
1116
- ctype = " int" ;
1117
- } else {
1118
- vname = getFreshID (" ftbl" );
1119
- ctype = ifloat ();
1120
- }
1059
+ // Define table name and type
1060
+ getTypedNames (getCertifiedSigType (content), " tbl" , ctype, vname);
1061
+
1121
1062
1122
- // table declaration
1063
+ // Table declaration
1123
1064
if (gGlobal ->gMemoryManager ) {
1124
1065
fClass ->addDeclCode (subst (" static $0* \t $1;" , ctype, vname));
1125
1066
fClass ->addStaticFields (subst (" $0* \t $1::$2 = 0;" , ctype, fClass ->getClassName (), vname));
@@ -1131,12 +1072,12 @@ string ScalarCompiler::generateStaticTable(Tree sig, Tree tsize, Tree content)
1131
1072
fClass ->addStaticFields (subst (" $0 \t $1::$2[$3];" , ctype, fClass ->getClassName (), vname, T (size)));
1132
1073
}
1133
1074
1134
- // initialization of the content generator
1075
+ // Initialization of the content generator
1135
1076
fClass ->addStaticInitCode (subst (" $0.init(sample_rate);" , cexp));
1136
- // filling the table
1077
+ // Filling the table
1137
1078
fClass ->addStaticInitCode (subst (" $0.fill($1,$2);" , cexp, T (size), vname));
1138
1079
1139
- // returning the table name
1080
+ // Returning the table name
1140
1081
return vname;
1141
1082
}
1142
1083
@@ -1285,7 +1226,7 @@ string ScalarCompiler::generatePrefix(Tree sig, Tree x, Tree e)
1285
1226
1286
1227
string ScalarCompiler::generateSelect2 (Tree sig, Tree sel, Tree s1, Tree s2)
1287
1228
{
1288
- return generateCacheCode (sig, subst (" (($0)?$1: $2)" , CS (sel), CS (s2), CS (s1)));
1229
+ return generateCacheCode (sig, subst (" (($0) ? $1 : $2)" , CS (sel), CS (s2), CS (s1)));
1289
1230
}
1290
1231
1291
1232
/* ****************************************************************************
0 commit comments