Skip to content

Commit

Permalink
Formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Dec 9, 2024
1 parent abf5ffa commit 94da68b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
9 changes: 4 additions & 5 deletions compiler/generator/instructions_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,9 @@ void InstructionsCompiler::compileMultiSignal(Tree L)
pushComputeBlockMethod(IB::genDeclareBufferIterators(
"*output", "outputs", fContainer->outputs(), type, true));
} else if (gGlobal->gOutputLang == "rust" && gGlobal->gInPlace) {
// todo what if there are more inputs then outputs?
int ios = max(fContainer->outputs(),fContainer->inputs());
pushComputeBlockMethod(IB::genDeclareBufferIterators(
"*io", "ios", ios, type, true));
// TODO: what if there are more inputs than outputs?
int ios = max(fContainer->outputs(), fContainer->inputs());
pushComputeBlockMethod(IB::genDeclareBufferIterators("*io", "ios", ios, type, true));
} else if (gGlobal->gOutputLang == "julia") {
// special handling for Julia backend
pushComputeBlockMethod(IB::genDeclareBufferIterators(
Expand Down Expand Up @@ -940,7 +939,7 @@ ValueInst* InstructionsCompiler::generateInput(Tree sig, int idx)
// HACK for Rust backend
if (gGlobal->gOutputLang == "rust" && !gGlobal->gInPlace) {
res = IB::genLoadStackVar(subst("*input$0", T(idx)));
} else if (gGlobal->gOutputLang == "rust"&& gGlobal->gInPlace) {
} else if (gGlobal->gOutputLang == "rust" && gGlobal->gInPlace) {
res = IB::genLoadStackVar(subst("*io$0", T(idx)));
} else if (gGlobal->gOutputLang == "jax") {
res = IB::genLoadArrayStackVar("inputs", IB::genInt32NumInst(idx));
Expand Down
19 changes: 5 additions & 14 deletions compiler/generator/rust/rust_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ void RustCodeContainer::produceFaustDspBlob()
*fOut << tab << "fn set_param(&mut self, param: ParamIndex, value: Self::T) {" << endl;
*fOut << tab << tab << "self.set_param(param, value)" << endl;
*fOut << tab << "}" << endl;
*fOut << tab
<< "fn compute(&mut self, count: i32, inputs: &[&[Self::T]], outputs: &mut [&mut "
*fOut << "fn compute(&mut self, count: i32, inputs: &[&[Self::T]], outputs: &mut [&mut "
"[Self::T]]) {"
<< endl;
*fOut << tab << tab << "self.compute(count as usize, inputs, outputs)" << endl;
Expand All @@ -236,7 +235,6 @@ void RustCodeContainer::produceClass()
tab(n, *fOut);
*fOut << "pub type FaustFloat = " << ifloat() << ";";


// Generate gub containers
generateSubContainers();

Expand Down Expand Up @@ -354,8 +352,7 @@ void RustCodeContainer::produceClass()

tab(n, *fOut);
*fOut << "impl " << fKlassName << " {";
tab(n, *fOut);


// Memory methods
tab(n + 2, *fOut);
if (fAllocateInstructions->fCode.size() > 0) {
Expand Down Expand Up @@ -397,7 +394,6 @@ void RustCodeContainer::produceClass()
produceMetadata(n + 1);

// Get sample rate method
tab(n + 1, *fOut);
fCodeProducer.Tab(n + 1);
tab(n + 1, *fOut);
*fOut << "pub fn get_sample_rate(&self) -> i32 { self.fSampleRate as i32}";
Expand Down Expand Up @@ -523,8 +519,8 @@ void RustCodeContainer::produceClass()
// Compute
if (gGlobal->gOneSample) {
generateComputeFrame(n + 1);
} else if (gGlobal->gInPlace){
generateComputeIO(n+1);
} else if (gGlobal->gInPlace) {
generateComputeIO(n + 1);
} else {
generateCompute(n + 1);
}
Expand Down Expand Up @@ -625,7 +621,6 @@ void RustCodeContainer::generateComputeHeader(int n, std::ostream* fOut)
{
// Compute "compute" declaration
tab(n, *fOut);
tab(n, *fOut);
*fOut << "pub fn compute(";
tab(n + 1, *fOut);
*fOut << "&mut self,";
Expand All @@ -644,7 +639,6 @@ void RustCodeContainer::generateComputeIOHeader(int n, std::ostream* fOut)
{
// Compute "compute" declaration
tab(n, *fOut);
tab(n, *fOut);
*fOut << "pub fn compute(&mut self, count: usize, mut ios: &mut [impl AsMut<[FaustFloat]>]) {";
tab(n + 1, *fOut);
}
Expand Down Expand Up @@ -704,7 +698,6 @@ void RustScalarCodeContainer::generateCompute(int n)
{
// Generates declaration
tab(n, *fOut);
tab(n, *fOut);
generateComputeHeader(n, fOut);
tab(n + 1, *fOut);
fCodeProducer.Tab(n + 1);
Expand Down Expand Up @@ -734,17 +727,15 @@ void RustScalarCodeContainer::generateComputeIO(int n)
{
// Generates declaration
tab(n, *fOut);
tab(n, *fOut);
generateComputeIOHeader(n, fOut);
tab(n + 1, *fOut);
fCodeProducer.Tab(n + 1);


generateComputeBlock(&fCodeProducer);

// Generates one single scalar loop
std::vector<std::string> iterators;
int num_buffers = max(fNumInputs,fNumOutputs);
int num_buffers = max(fNumInputs, fNumOutputs);
for (int i = 0; i < num_buffers; ++i) {
iterators.push_back("ios" + std::to_string(i));
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/generator/rust/rust_code_container.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class RustCodeContainer : public virtual CodeContainer {
}
virtual ~RustCodeContainer() {}

virtual void produceClass();
void generateComputeHeader(int n, std::ostream* fOut);
void generateComputeIOHeader(int n, std::ostream* fOut);
void generateComputeFrame(int tab);
virtual void produceClass();
void generateComputeHeader(int n, std::ostream* fOut);
void generateComputeIOHeader(int n, std::ostream* fOut);
void generateComputeFrame(int tab);
virtual void generateCompute(int tab) = 0;
virtual void generateComputeIO(int tab) {};
virtual void generateComputeIO(int tab){};
void produceInternal();
void produceFaustDspBlob();
virtual dsp_factory_base* produceFactory();
Expand Down
10 changes: 5 additions & 5 deletions compiler/generator/rust/rust_instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ class RustInstVisitor : public TextInstVisitor {
virtual void visit(DeclareBufferIterators* inst)
{
/* Generates an expression like:
let [outputs0, outputs1, ..] = outputs.as_mut() else { panic!(\"wrong number of outputs\"); };";
let outputs0 = outputs0.as_mut[..count].iter_mut();
let outputs1 = outputs1.as_mut[..count].iter_mut();
let [outputs0, outputs1, ..] = outputs.as_mut() else { panic!(\"wrong number of outputs\");
};"; let outputs0 = outputs0.as_mut[..count].iter_mut(); let outputs1 =
outputs1.as_mut[..count].iter_mut();
*/

// Don't generate if no channels or onesample mode
Expand All @@ -244,13 +244,13 @@ class RustInstVisitor : public TextInstVisitor {
}
*fOut << ".. ] = " << name;
if (inst->fMutable) {
if (gGlobal->gInPlace){
if (gGlobal->gInPlace) {
*fOut << ".as_mut() else { panic!(\"wrong number of IO buffers\"); };";
} else {
*fOut << ".as_mut() else { panic!(\"wrong number of output buffers\"); };";
}
} else {
*fOut << ".as_ref() else { panic!(\"wrong number of input buffers\"); };";
*fOut << ".as_ref() else { panic!(\"wrong number of input buffers\"); };";
}

// Build fixed size iterator variables
Expand Down
3 changes: 2 additions & 1 deletion compiler/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,8 @@ bool global::processCmdline(int argc, const char* argv[])
}

if (!gRustNoTraitSwitch && gInPlace && gOutputLang == "rust") {
throw faustexception("ERROR : for 'rust' the '-inpl' flag must be combined with '-rnt' flag\n");
throw faustexception(
"ERROR : for 'rust' the '-inpl' flag must be combined with '-rnt' flag\n");
}

if (gInPlace && gVectorSwitch) {
Expand Down

0 comments on commit 94da68b

Please sign in to comment.