Skip to content

Commit

Permalink
[NEW] Option -rnlm (--rust-no-libm) added in Rust backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Feb 10, 2025
1 parent aab33f2 commit ad2e156
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
1 change: 0 additions & 1 deletion compiler/DirectedGraph/DirectedGraphAlgorythm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@ inline std::list<N> recschedule(const digraph<N>& G)
return P;
}


/*******************************************************************************
********************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions compiler/generator/rust/rust_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void RustCodeContainer::produceClass()

// Missing math functions
// See: https://users.rust-lang.org/t/analog-of-c-std-remainder/59670
if (gGlobal->gFloatSize == 1) {
if (gGlobal->gFloatSize == 1 && !gGlobal->gRustNoLibm) {
*fOut << "mod ffi {";
tab(n + 1, *fOut);
*fOut << "use std::os::raw::c_float;";
Expand Down Expand Up @@ -283,7 +283,7 @@ void RustCodeContainer::produceClass()
*fOut << "fn remainder_f32(a: f32, b: f32) -> f32 { let n = (a/b).round(); a - b*n }";
tab(n, *fOut);
*/
} else if (gGlobal->gFloatSize == 2) {
} else if (gGlobal->gFloatSize == 2 && !gGlobal->gRustNoLibm) {
*fOut << "mod ffi {";
tab(n + 1, *fOut);
*fOut << "use std::os::raw::{c_double};";
Expand Down
27 changes: 20 additions & 7 deletions compiler/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ void global::reset()

gUIMacroSwitch = false;
gRustNoTraitSwitch = false;
gRustNoLibm = false;

gDumpNorm = -1;
gFTZMode = 0;
Expand Down Expand Up @@ -1258,7 +1259,7 @@ bool global::processCmdline(int argc, const char* argv[])
i += 2;

} else if (isCmd(argv[i], "-style", "--svgstyle")) {
gGlobal->gStyleFile = argv[i + 1];
gStyleFile = argv[i + 1];
i += 2;

} else if (isCmd(argv[i], "-f", "--fold") && (i + 1 < argc)) {
Expand Down Expand Up @@ -1370,6 +1371,10 @@ bool global::processCmdline(int argc, const char* argv[])
gRustNoTraitSwitch = true;
i += 1;

} else if (isCmd(argv[i], "-rnlm", "--rust-no-libm")) {
gRustNoLibm = true;
i += 1;

} else if (isCmd(argv[i], "-t", "--timeout") && (i + 1 < argc)) {
gTimeout = std::atoi(argv[i + 1]);
i += 2;
Expand Down Expand Up @@ -1654,15 +1659,19 @@ bool global::processCmdline(int argc, const char* argv[])
}

if (gMemoryManager >= 1) {
gGlobal->gWaveformInDSP = true;
gWaveformInDSP = true;
}

// ========================
// Check options coherency
// ========================

if (gRustNoTraitSwitch && gOutputLang != "rust") {
throw faustexception("ERROR : '-rnt' option can only be used with rust\n");
throw faustexception("ERROR : '-rnt' option can only be used with 'rust' backend\n");
}

if (gRustNoLibm && gOutputLang != "rust") {
throw faustexception("ERROR : '-rnlm' option can only be used with 'rust' backend\n");
}

if (!gRustNoTraitSwitch && gInPlace && gOutputLang == "rust") {
Expand Down Expand Up @@ -2124,10 +2133,6 @@ string global::printHelp()
<< "-uim --user-interface-macros add user interface macro definitions to the "
"output code."
<< endl;
sstr << tab
<< "-rnt --rust-no-faustdsp-trait (Rust only) Don't generate FaustDsp trait "
"implmentation."
<< endl;
sstr << tab << "-xml generate an XML description file."
<< endl;
sstr << tab << "-json generate a JSON description file."
Expand Down Expand Up @@ -2380,6 +2385,14 @@ string global::printHelp()
<< "-ni <n> --narrowing-iterations <n> number of iterations before stopping "
"narrowing in signal bounding."
<< endl;
sstr << tab
<< "-rnt --rust-no-faustdsp-trait (Rust only) Don't generate FaustDsp trait "
"implmentation."
<< endl;
sstr << tab
<< "-rnlm --rust-no-libm (Rust only) Don't generate FFI calls to libm."
<< endl;

#endif
#ifndef EMCC
sstr << endl << "Block diagram options:" << line;
Expand Down
1 change: 1 addition & 0 deletions compiler/global.hh
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct global {
bool gInlineArchSwitch; // -i option
bool gUIMacroSwitch; // -uim option
bool gRustNoTraitSwitch; // -rnt option
bool gRustNoLibm; // -rnlm option
int gDumpNorm; // -norm option
bool gMathExceptions; // -me option, whether to check math functions domains
bool gLocalCausalityCheck; // -lcc option, when true trigs local causality errors (negative
Expand Down
4 changes: 2 additions & 2 deletions compiler/tlib/tree.hh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct less<CTree*> {
bool operator()(const CTree* lhs, const CTree* rhs) const;
};

}
} // namespace std

/**
* A CTree = (Node x [CTree]) is the association of a content Node and a list of subtrees
Expand Down Expand Up @@ -210,7 +210,7 @@ inline bool less<CTree*>::operator()(const CTree* lhs, const CTree* rhs) const
{
return lhs->serial() < rhs->serial();
}
};
}; // namespace std

//---------------------------------API---------------------------------------
// To build trees
Expand Down

0 comments on commit ad2e156

Please sign in to comment.