@@ -147,6 +147,9 @@ struct DropInst;
147
147
// Null statement
148
148
struct NullStatementInst ;
149
149
150
+ // FIR module
151
+ struct ModuleInst ;
152
+
150
153
// ======
151
154
// Types
152
155
// ======
@@ -336,6 +339,9 @@ struct InstVisitor : public virtual Garbageable {
336
339
// Block
337
340
virtual void visit (BlockInst* inst) {}
338
341
342
+ // Module
343
+ virtual void visit (ModuleInst* inst) {}
344
+
339
345
// Addresses
340
346
virtual void visit (NamedAddress* address) {}
341
347
virtual void visit (IndexedAddress* address) {}
@@ -418,6 +424,9 @@ struct CloneVisitor : public virtual Garbageable {
418
424
// Block
419
425
virtual StatementInst* visit (BlockInst* inst) = 0;
420
426
427
+ // Module
428
+ virtual StatementInst* visit (ModuleInst* inst) = 0;
429
+
421
430
// User interface
422
431
virtual StatementInst* visit (AddMetaDeclareInst* inst) = 0;
423
432
virtual StatementInst* visit (OpenboxInst* inst) = 0;
@@ -1029,6 +1038,35 @@ struct BlockInst : public StatementInst {
1029
1038
ValueInst* getReturnValue ();
1030
1039
};
1031
1040
1041
+ // ===========
1042
+ // FIR module
1043
+ // ===========
1044
+
1045
+ struct ModuleInst : public StatementInst {
1046
+ std::string fName ;
1047
+ BlockInst* fDSPStruct ;
1048
+ BlockInst* fGlobals ;
1049
+ std::list<StatementInst*> fFunctions ;
1050
+
1051
+ ModuleInst (const std::string& name, BlockInst* dsp_struct, BlockInst* globals,
1052
+ const std::list<StatementInst*>& functions = {})
1053
+ : fName (name), fDSPStruct (dsp_struct), fGlobals (globals), fFunctions (functions)
1054
+ {
1055
+ }
1056
+
1057
+ void pushFunction (StatementInst* fun)
1058
+ {
1059
+ faustassert (fun);
1060
+ fFunctions .push_back (fun);
1061
+ }
1062
+
1063
+ std::string getName () { return fName ; };
1064
+
1065
+ void accept (InstVisitor* visitor) { visitor->visit (this ); }
1066
+
1067
+ StatementInst* clone (CloneVisitor* cloner) { return cloner->visit (this ); }
1068
+ };
1069
+
1032
1070
// =============
1033
1071
// Declarations
1034
1072
// =============
@@ -1937,6 +1975,18 @@ class BasicCloneVisitor : public CloneVisitor {
1937
1975
return cloned;
1938
1976
}
1939
1977
1978
+ // Module
1979
+ virtual StatementInst* visit (ModuleInst* inst)
1980
+ {
1981
+ ModuleInst* cloned =
1982
+ new ModuleInst (inst->fName , static_cast <BlockInst*>(inst->fDSPStruct ->clone (this )),
1983
+ static_cast <BlockInst*>(inst->fGlobals ->clone (this )));
1984
+ for (const auto & it : inst->fFunctions ) {
1985
+ cloned->pushFunction (it->clone (this ));
1986
+ }
1987
+ return cloned;
1988
+ }
1989
+
1940
1990
// User interface
1941
1991
virtual StatementInst* visit (AddMetaDeclareInst* inst)
1942
1992
{
@@ -2150,6 +2200,15 @@ struct DispatchVisitor : public InstVisitor {
2150
2200
}
2151
2201
}
2152
2202
2203
+ virtual void visit (ModuleInst* inst)
2204
+ {
2205
+ inst->fDSPStruct ->accept (this );
2206
+ inst->fGlobals ->accept (this );
2207
+ for (const auto & it : inst->fFunctions ) {
2208
+ it->accept (this );
2209
+ }
2210
+ }
2211
+
2153
2212
// Typed
2154
2213
virtual void visit (FunTyped* typed)
2155
2214
{
@@ -2585,6 +2644,13 @@ struct IB {
2585
2644
}
2586
2645
static BlockInst* genBlockInst () { return new BlockInst (); }
2587
2646
2647
+ static ModuleInst* genModuleInst (const std::string& name, BlockInst* dsp_struct,
2648
+ BlockInst* globals,
2649
+ const std::list<StatementInst*>& functions = {})
2650
+ {
2651
+ return new ModuleInst (name, dsp_struct, globals, functions);
2652
+ }
2653
+
2588
2654
// Types
2589
2655
static BasicTyped* genBasicTyped (Typed::VarType type); // moved in instructions.cpp
2590
2656
@@ -3168,6 +3234,158 @@ struct IB {
3168
3234
}
3169
3235
return genDeclareFunInst (name, genFunTyped (named_args, genBasicTyped (rtype)));
3170
3236
}
3237
+
3238
+ static Names genMethod (const std::string& obj, bool ismethod)
3239
+ {
3240
+ Names args;
3241
+ if (!ismethod) {
3242
+ args.push_back (IB::genNamedTyped (obj, Typed::kObj_ptr ));
3243
+ }
3244
+ return args;
3245
+ }
3246
+
3247
+ static Values genObjArg (const std::string& obj, bool ismethod)
3248
+ {
3249
+ Values args;
3250
+ if (!ismethod) {
3251
+ args.push_back (genLoadFunArgsVar (obj));
3252
+ }
3253
+ return args;
3254
+ }
3255
+
3256
+ static DeclareFunInst* generateGetIO (const std::string& name, const std::string& obj, int io,
3257
+ bool ismethod, FunTyped::FunAttribute funtype)
3258
+ {
3259
+ Names args = genMethod (obj, ismethod);
3260
+ BlockInst* block = genBlockInst ();
3261
+ block->pushBackInst (genRetInst (genInt32NumInst (io)));
3262
+
3263
+ // Creates function
3264
+ FunTyped* fun_type = genFunTyped (args, genInt32Typed (), funtype);
3265
+ return genDeclareFunInst (name, fun_type, block);
3266
+ }
3267
+
3268
+ static DeclareFunInst* generateGetInputs (const std::string& name, const std::string& obj,
3269
+ bool ismethod, FunTyped::FunAttribute funtype,
3270
+ int inputs)
3271
+ {
3272
+ return generateGetIO (name, obj, inputs, ismethod, funtype);
3273
+ }
3274
+
3275
+ static DeclareFunInst* generateGetOutputs (const std::string& name, const std::string& obj,
3276
+ bool ismethod, FunTyped::FunAttribute funtype,
3277
+ int outputs)
3278
+ {
3279
+ return generateGetIO (name, obj, outputs, ismethod, funtype);
3280
+ }
3281
+
3282
+ static DeclareFunInst* generateGetSampleRate (const std::string& name, const std::string& obj,
3283
+ bool ismethod, bool isvirtual)
3284
+ {
3285
+ Names args = genMethod (obj, ismethod);
3286
+
3287
+ BlockInst* block = genBlockInst ();
3288
+ block->pushBackInst (genRetInst (genLoadStructVar (" fSampleRate" )));
3289
+
3290
+ // Creates function
3291
+ FunTyped* fun_type = genFunTyped (args, genInt32Typed (),
3292
+ (isvirtual) ? FunTyped::kVirtual : FunTyped::kDefault );
3293
+ return genDeclareFunInst (name, fun_type, block);
3294
+ }
3295
+
3296
+ static DeclareFunInst* generateInit (const std::string& name, const std::string& obj,
3297
+ bool ismethod, bool isvirtual)
3298
+ {
3299
+ Names args = genMethod (obj, ismethod);
3300
+ args.push_back (genNamedTyped (" sample_rate" , Typed::kInt32 ));
3301
+
3302
+ BlockInst* block = genBlockInst ();
3303
+ {
3304
+ Values args1 = genObjArg (obj, ismethod);
3305
+ args1.push_back (genLoadFunArgsVar (" sample_rate" ));
3306
+ block->pushBackInst (genVoidFunCallInst (" classInit" , args1));
3307
+ }
3308
+
3309
+ {
3310
+ Values args1 = genObjArg (obj, ismethod);
3311
+ args1.push_back (genLoadFunArgsVar (" sample_rate" ));
3312
+ block->pushBackInst (genVoidFunCallInst (" instanceInit" , args1));
3313
+ }
3314
+
3315
+ // Creates function
3316
+ return genVoidFunction (name, args, block, isvirtual);
3317
+ }
3318
+
3319
+ static DeclareFunInst* generateInstanceInit (const std::string& name, const std::string& obj,
3320
+ bool ismethod, bool isvirtual)
3321
+ {
3322
+ Names args = genMethod (obj, ismethod);
3323
+ args.push_back (genNamedTyped (" sample_rate" , Typed::kInt32 ));
3324
+
3325
+ BlockInst* block = genBlockInst ();
3326
+ {
3327
+ Values args1 = genObjArg (obj, ismethod);
3328
+ args1.push_back (genLoadFunArgsVar (" sample_rate" ));
3329
+ block->pushBackInst (genVoidFunCallInst (" instanceConstants" , args1));
3330
+ }
3331
+
3332
+ {
3333
+ Values args1 = genObjArg (obj, ismethod);
3334
+ block->pushBackInst (genVoidFunCallInst (" instanceResetUserInterface" , args1));
3335
+ }
3336
+
3337
+ {
3338
+ Values args1 = genObjArg (obj, ismethod);
3339
+ block->pushBackInst (genVoidFunCallInst (" instanceClear" , args1));
3340
+ }
3341
+
3342
+ // Creates function
3343
+ return genVoidFunction (name, args, block, isvirtual);
3344
+ }
3345
+
3346
+ static DeclareFunInst* generateInstanceResetUserInterface (const std::string& name,
3347
+ const std::string& obj, bool ismethod,
3348
+ bool isvirtual,
3349
+ BlockInst* reset_block)
3350
+ {
3351
+ Names args;
3352
+ if (!ismethod) {
3353
+ args.push_back (genNamedTyped (obj, Typed::kObj_ptr ));
3354
+ }
3355
+
3356
+ // Creates function
3357
+ FunTyped* fun_type = IB::genFunTyped (args, genVoidTyped (), FunTyped::kDefault );
3358
+ return genDeclareFunInst (name, fun_type, reset_block);
3359
+ }
3360
+
3361
+ static DeclareFunInst* generateInstanceClear (const std::string& name, const std::string& obj,
3362
+ bool ismethod, bool isvirtual);
3363
+
3364
+ static DeclareFunInst* generateInstanceClear (const std::string& name, const std::string& obj,
3365
+ bool ismethod, bool isvirtual,
3366
+ BlockInst* clear_block)
3367
+ {
3368
+ Names args = genMethod (obj, ismethod);
3369
+
3370
+ // Creates function
3371
+ return IB::genVoidFunction (name, args, clear_block, isvirtual);
3372
+ }
3373
+
3374
+ static DeclareFunInst* generateComputeFun (const std::string& name, const std::string& obj,
3375
+ bool ismethod, bool isvirtual,
3376
+ BlockInst* compute_block)
3377
+ {
3378
+ Names args = genMethod (obj, ismethod);
3379
+ args.push_back (genNamedTyped (" count" , Typed::kInt32 ));
3380
+ args.push_back (genNamedTyped (" inputs" , Typed::kFloatMacro_ptr_ptr ));
3381
+ args.push_back (genNamedTyped (" outputs" , Typed::kFloatMacro_ptr_ptr ));
3382
+
3383
+ // Explicit return
3384
+ compute_block->pushBackInst (genRetInst ());
3385
+
3386
+ // Creates function
3387
+ return IB::genVoidFunction (name, args, compute_block, isvirtual);
3388
+ }
3171
3389
};
3172
3390
3173
3391
/*
0 commit comments