Skip to content

Commit ef8ee74

Browse files
committed
Use of new ArrayVar class in -os mode, cleanup.
1 parent 49f2278 commit ef8ee74

17 files changed

+290
-305
lines changed

compiler/generator/c/c_code_container.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ void CScalarOneSampleCodeContainer1::produceClass()
416416
tab(n, *fOut);
417417

418418
tab(n, *fOut);
419-
*fOut << "#define FAUST_INT_CONTROLS " << fInt32ControlNum << endl;
420-
*fOut << "#define FAUST_REAL_CONTROLS " << fRealControlNum << endl;
419+
*fOut << "#define FAUST_INT_CONTROLS " << fIntControl->fCurIndex << endl;
420+
*fOut << "#define FAUST_REAL_CONTROLS " << fRealControl->fCurIndex << endl;
421421
tab(n, *fOut);
422422

423423
*fOut << "#ifndef TESTBENCH";
@@ -566,12 +566,12 @@ void CScalarOneSampleCodeContainer1::produceClass()
566566

567567
tab(n, *fOut);
568568
*fOut << "int getNumIntControls" << fKlassName << "(" << fKlassName << "* dsp) { return "
569-
<< fInt32ControlNum << "; }";
569+
<< fIntControl->fCurIndex << "; }";
570570
tab(n, *fOut);
571571

572572
tab(n, *fOut);
573573
*fOut << "int getNumRealControls" << fKlassName << "(" << fKlassName << "* dsp) { return "
574-
<< fRealControlNum << "; }";
574+
<< fRealControl->fCurIndex << "; }";
575575

576576
// Compute
577577
generateCompute(n);
@@ -774,11 +774,11 @@ void CScalarOneSampleCodeContainer2::produceClass()
774774

775775
tab(n, *fOut);
776776
*fOut << "int getNumIntControls" << fKlassName << "(" << fKlassName << "* dsp) { return "
777-
<< fInt32ControlNum << "; }";
777+
<< fIntControl->fCurIndex << "; }";
778778
tab(n, *fOut);
779779

780780
*fOut << "int getNumRealControls" << fKlassName << "(" << fKlassName << "* dsp) { return "
781-
<< fRealControlNum << "; }";
781+
<< fRealControl->fCurIndex << "; }";
782782
tab(n, *fOut);
783783

784784
tab(n, *fOut);
@@ -791,8 +791,8 @@ void CScalarOneSampleCodeContainer2::produceClass()
791791
generateCompute(n);
792792

793793
tab(n, *fOut);
794-
*fOut << "#define FAUST_INT_CONTROLS " << fInt32ControlNum << endl;
795-
*fOut << "#define FAUST_REAL_CONTROLS " << fRealControlNum << endl;
794+
*fOut << "#define FAUST_INT_CONTROLS " << fIntControl->fCurIndex << endl;
795+
*fOut << "#define FAUST_REAL_CONTROLS " << fRealControl->fCurIndex << endl;
796796

797797
tab(n, *fOut);
798798
*fOut << "#define FAUST_INT_ZONE " << int_zone_size << endl;
@@ -1029,11 +1029,11 @@ void CScalarOneSampleCodeContainer3::produceClass()
10291029

10301030
tab(n, *fOut);
10311031
*fOut << "int getNumIntControls" << fKlassName << "(" << fKlassName << "* dsp) { return "
1032-
<< fInt32ControlNum << "; }";
1032+
<< fIntControl->fCurIndex << "; }";
10331033
tab(n, *fOut);
10341034

10351035
*fOut << "int getNumRealControls" << fKlassName << "(" << fKlassName << "* dsp) { return "
1036-
<< fRealControlNum << "; }";
1036+
<< fRealControl->fCurIndex << "; }";
10371037
tab(n, *fOut);
10381038

10391039
tab(n, *fOut);
@@ -1048,8 +1048,8 @@ void CScalarOneSampleCodeContainer3::produceClass()
10481048
generateCompute(n);
10491049

10501050
tab(n, *fOut);
1051-
*fOut << "#define FAUST_INT_CONTROLS " << fInt32ControlNum << endl;
1052-
*fOut << "#define FAUST_REAL_CONTROLS " << fRealControlNum << endl;
1051+
*fOut << "#define FAUST_INT_CONTROLS " << fIntControl->fCurIndex << endl;
1052+
*fOut << "#define FAUST_REAL_CONTROLS " << fRealControl->fCurIndex << endl;
10531053

10541054
tab(n, *fOut);
10551055
// copy_from_mem.fIntIndex and copy_from_mem.fRealIndex contains the size used for tables, DLs and iConst/fConst variables
@@ -1319,11 +1319,11 @@ void CScalarOneSampleCodeContainer4::produceClass()
13191319

13201320
tab(n, *fOut);
13211321
*fOut << "int getNumIntControls" << fKlassName << "(" << fKlassName << "* dsp) { return "
1322-
<< fInt32ControlNum << "; }";
1322+
<< fIntControl->fCurIndex << "; }";
13231323
tab(n, *fOut);
13241324

13251325
*fOut << "int getNumRealControls" << fKlassName << "(" << fKlassName << "* dsp) { return "
1326-
<< fRealControlNum << "; }";
1326+
<< fRealControl->fCurIndex << "; }";
13271327
tab(n, *fOut);
13281328

13291329
tab(n, *fOut);
@@ -1336,8 +1336,8 @@ void CScalarOneSampleCodeContainer4::produceClass()
13361336
generateCompute(n);
13371337

13381338
tab(n, *fOut);
1339-
*fOut << "#define FAUST_INT_CONTROLS " << fInt32ControlNum << endl;
1340-
*fOut << "#define FAUST_REAL_CONTROLS " << fRealControlNum << endl;
1339+
*fOut << "#define FAUST_INT_CONTROLS " << fIntControl->fCurIndex << endl;
1340+
*fOut << "#define FAUST_REAL_CONTROLS " << fRealControl->fCurIndex << endl;
13411341

13421342
tab(n, *fOut);
13431343
// int_zone_size and real_zone_size contains the size used for tables, DLs and iConst/fConst variables

compiler/generator/cmajor/cmajor_code_container.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ void CmajorCodeContainer::produceClass()
233233
}
234234

235235
// For control computation
236-
if (fInt32ControlNum > 0) {
237-
*fOut << "int32[" << fInt32ControlNum << "] iControl;";
236+
if (fIntControl->fCurIndex > 0) {
237+
*fOut << "int32[" << fIntControl->fCurIndex << "] iControl;";
238238
tab(n + 1, *fOut);
239239
}
240-
if (fRealControlNum > 0) {
241-
*fOut << fCodeProducer.getTypeManager()->fTypeDirectTable[itfloat()] << "[" << fRealControlNum << "] fControl;";
240+
if (fRealControl->fCurIndex > 0) {
241+
*fOut << fCodeProducer.getTypeManager()->fTypeDirectTable[itfloat()] << "[" << fRealControl->fCurIndex << "] fControl;";
242242
}
243243

244244
// Global declarations

compiler/generator/code_container.cpp

Lines changed: 23 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ CodeContainer::CodeContainer()
6464
fComputeBlockInstructions(InstBuilder::genBlockInst()),
6565
fPostComputeBlockInstructions(InstBuilder::genBlockInst()),
6666
fComputeFunctions(InstBuilder::genBlockInst()),
67-
fUserInterfaceInstructions(InstBuilder::genBlockInst()),
68-
fInt32ControlNum(0),
69-
fRealControlNum(0)
67+
fUserInterfaceInstructions(InstBuilder::genBlockInst())
7068
{
7169
fCurLoop = new CodeLoop(0, gGlobal->getFreshID("i"));
70+
// iControl/fControl are given as arguments, or kept as struct fields in -os3 mode.
71+
Address::AccessType access = (gGlobal->gOneSample == 3) ? Address::AccessType::kStruct : Address::AccessType::kFunArgs;
72+
fIntControl = new ArrayVar("iControl", access);
73+
fRealControl = new ArrayVar("fControl", access);
7274
}
7375

7476
CodeContainer::~CodeContainer()
@@ -659,10 +661,7 @@ void CodeContainer::printMacros(ostream& fout, int n)
659661
DeclareFunInst* CodeContainer::generateGetIO(const string& name, const string& obj, int io, bool ismethod,
660662
FunTyped::FunAttribute funtype)
661663
{
662-
Names args;
663-
if (!ismethod) {
664-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
665-
}
664+
Names args = genMethod(obj, ismethod);
666665
BlockInst* block = InstBuilder::genBlockInst();
667666
block->pushBackInst(InstBuilder::genRetInst(InstBuilder::genInt32NumInst(io)));
668667

@@ -683,10 +682,7 @@ DeclareFunInst* CodeContainer::generateGetOutputs(const string& name, const stri
683682

684683
DeclareFunInst* CodeContainer::generateAllocate(const string& name, const string& obj, bool ismethod, bool isvirtual)
685684
{
686-
Names args;
687-
if (!ismethod) {
688-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
689-
}
685+
Names args = genMethod(obj, ismethod);
690686

691687
BlockInst* block = InstBuilder::genBlockInst();
692688
block->pushBackInst(fAllocateInstructions);
@@ -700,10 +696,7 @@ DeclareFunInst* CodeContainer::generateAllocate(const string& name, const string
700696

701697
DeclareFunInst* CodeContainer::generateDestroy(const string& name, const string& obj, bool ismethod, bool isvirtual)
702698
{
703-
Names args;
704-
if (!ismethod) {
705-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
706-
}
699+
Names args = genMethod(obj, ismethod);
707700

708701
BlockInst* block = InstBuilder::genBlockInst();
709702
block->pushBackInst(fDestroyInstructions);
@@ -718,10 +711,7 @@ DeclareFunInst* CodeContainer::generateDestroy(const string& name, const string&
718711
DeclareFunInst* CodeContainer::generateGetIORate(const string& name, const string& obj, vector<int>& io, bool ismethod,
719712
bool isvirtual)
720713
{
721-
Names args;
722-
if (!ismethod) {
723-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
724-
}
714+
Names args = genMethod(obj, ismethod);
725715
args.push_back(InstBuilder::genNamedTyped("channel", Typed::kInt32));
726716

727717
BlockInst* block = InstBuilder::genBlockInst();
@@ -757,11 +747,8 @@ DeclareFunInst* CodeContainer::generateGetIORate(const string& name, const strin
757747
DeclareFunInst* CodeContainer::generateInstanceClear(const string& name, const string& obj, bool ismethod,
758748
bool isvirtual)
759749
{
760-
Names args;
761-
if (!ismethod) {
762-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
763-
}
764-
750+
Names args = genMethod(obj, ismethod);
751+
765752
BlockInst* block = InstBuilder::genBlockInst();
766753
block->pushBackInst(fClearInstructions);
767754

@@ -775,10 +762,7 @@ DeclareFunInst* CodeContainer::generateInstanceClear(const string& name, const s
775762
DeclareFunInst* CodeContainer::generateInstanceConstants(const string& name, const string& obj, bool ismethod,
776763
bool isvirtual)
777764
{
778-
Names args;
779-
if (!ismethod) {
780-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
781-
}
765+
Names args = genMethod(obj, ismethod);
782766
args.push_back(InstBuilder::genNamedTyped("sample_rate", Typed::kInt32));
783767

784768
BlockInst* block = InstBuilder::genBlockInst();
@@ -818,10 +802,7 @@ DeclareFunInst* CodeContainer::generateStaticInitFun(const string& name, bool is
818802
DeclareFunInst* CodeContainer::generateInstanceInitFun(const string& name, const string& obj, bool ismethod,
819803
bool isvirtual)
820804
{
821-
Names args;
822-
if (!ismethod) {
823-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
824-
}
805+
Names args = genMethod(obj, ismethod);
825806
args.push_back(InstBuilder::genNamedTyped("sample_rate", Typed::kInt32));
826807

827808
BlockInst* init_block = InstBuilder::genBlockInst();
@@ -839,10 +820,7 @@ DeclareFunInst* CodeContainer::generateInstanceInitFun(const string& name, const
839820

840821
DeclareFunInst* CodeContainer::generateFillFun(const string& name, const string& obj, bool ismethod, bool isvirtual)
841822
{
842-
Names args;
843-
if (!ismethod) {
844-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
845-
}
823+
Names args = genMethod(obj, ismethod);
846824
args.push_back(InstBuilder::genNamedTyped("count", Typed::kInt32));
847825
if (fSubContainerType == kInt) {
848826
args.push_back(InstBuilder::genNamedTyped(fTableName, Typed::kInt32_ptr));
@@ -868,27 +846,18 @@ DeclareFunInst* CodeContainer::generateFillFun(const string& name, const string&
868846

869847
DeclareFunInst* CodeContainer::generateInit(const string& name, const string& obj, bool ismethod, bool isvirtual)
870848
{
871-
Names args;
872-
if (!ismethod) {
873-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
874-
}
849+
Names args = genMethod(obj, ismethod);
875850
args.push_back(InstBuilder::genNamedTyped("sample_rate", Typed::kInt32));
876851

877852
BlockInst* block = InstBuilder::genBlockInst();
878853
{
879-
Values args1;
880-
if (!ismethod) {
881-
args1.push_back(InstBuilder::genLoadFunArgsVar(obj));
882-
}
854+
Values args1 = genObjArg(obj, ismethod);
883855
args1.push_back(InstBuilder::genLoadFunArgsVar("sample_rate"));
884856
block->pushBackInst(InstBuilder::genVoidFunCallInst("classInit", args1));
885857
}
886858

887859
{
888-
Values args1;
889-
if (!ismethod) {
890-
args1.push_back(InstBuilder::genLoadFunArgsVar(obj));
891-
}
860+
Values args1 = genObjArg(obj, ismethod);
892861
args1.push_back(InstBuilder::genLoadFunArgsVar("sample_rate"));
893862
block->pushBackInst(InstBuilder::genVoidFunCallInst("instanceInit", args1));
894863
}
@@ -900,35 +869,23 @@ DeclareFunInst* CodeContainer::generateInit(const string& name, const string& ob
900869
DeclareFunInst* CodeContainer::generateInstanceInit(const string& name, const string& obj, bool ismethod,
901870
bool isvirtual)
902871
{
903-
Names args;
904-
if (!ismethod) {
905-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
906-
}
872+
Names args = genMethod(obj, ismethod);
907873
args.push_back(InstBuilder::genNamedTyped("sample_rate", Typed::kInt32));
908874

909875
BlockInst* block = InstBuilder::genBlockInst();
910876
{
911-
Values args1;
912-
if (!ismethod) {
913-
args1.push_back(InstBuilder::genLoadFunArgsVar(obj));
914-
}
877+
Values args1 = genObjArg(obj, ismethod);
915878
args1.push_back(InstBuilder::genLoadFunArgsVar("sample_rate"));
916879
block->pushBackInst(InstBuilder::genVoidFunCallInst("instanceConstants", args1));
917880
}
918881

919882
{
920-
Values args1;
921-
if (!ismethod) {
922-
args1.push_back(InstBuilder::genLoadFunArgsVar(obj));
923-
}
883+
Values args1 = genObjArg(obj, ismethod);
924884
block->pushBackInst(InstBuilder::genVoidFunCallInst("instanceResetUserInterface", args1));
925885
}
926886

927887
{
928-
Values args1;
929-
if (!ismethod) {
930-
args1.push_back(InstBuilder::genLoadFunArgsVar(obj));
931-
}
888+
Values args1 = genObjArg(obj, ismethod);
932889
block->pushBackInst(InstBuilder::genVoidFunCallInst("instanceClear", args1));
933890
}
934891

@@ -939,10 +896,7 @@ DeclareFunInst* CodeContainer::generateInstanceInit(const string& name, const st
939896
DeclareFunInst* CodeContainer::generateGetSampleRate(const string& name, const string& obj, bool ismethod,
940897
bool isvirtual)
941898
{
942-
Names args;
943-
if (!ismethod) {
944-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
945-
}
899+
Names args = genMethod(obj, ismethod);
946900

947901
BlockInst* block = InstBuilder::genBlockInst();
948902
block->pushBackInst(InstBuilder::genRetInst(InstBuilder::genLoadStructVar("fSampleRate")));
@@ -955,10 +909,7 @@ DeclareFunInst* CodeContainer::generateGetSampleRate(const string& name, const s
955909

956910
DeclareFunInst* CodeContainer::generateComputeFun(const string& name, const string& obj, bool ismethod, bool isvirtual)
957911
{
958-
Names args;
959-
if (!ismethod) {
960-
args.push_back(InstBuilder::genNamedTyped(obj, Typed::kObj_ptr));
961-
}
912+
Names args = genMethod(obj, ismethod);
962913
args.push_back(InstBuilder::genNamedTyped("count", Typed::kInt32));
963914
args.push_back(InstBuilder::genNamedTyped("inputs", Typed::kFloatMacro_ptr_ptr));
964915
args.push_back(InstBuilder::genNamedTyped("outputs", Typed::kFloatMacro_ptr_ptr));

0 commit comments

Comments
 (0)