SystemC ERROR: type name requires a specifier or qualifier - systemc

I am trying to write synthesizable SystemC code.
My code:
struct test:sc_module{
sc_in<sc_lv<4>> inp;
sc_out<sc_lv<4>> outp;
void run(){
sc_lv<4> temp = inp.read();
outp.write(temp);
}
SC_CTOR(test){
SC_METHOD(run);
sensitive << inp;
}
};
I am able to simulate the code, but when I run synthesis, Vivado HLS v.2019 throws the following errors. Can someone please help me understand how to fix this error?
ERROR: [HLS 200-70] Compilation errors found: In file included from test2/test.cpp:1:
test2/test.cpp:4:18: error: use of undeclared identifier 'inp'
sc_in<sc_lv<4>> inp;
^
test2/test.cpp:4:21: error: type name requires a specifier or qualifier
sc_in<sc_lv<4>> inp;
^
test2/test.cpp:4:21: warning: declaration does not declare anything [-Wmissing-declarations]
sc_in<sc_lv<4>> inp;

When I add spaces between the angular brackets (as below), it does not throw an error, and synthesis runs successfully.
sc_in< sc_lv<4> > inp;
sc_out< sc_lv<4> > outp;

Related

How can Poplar codelets include code from other header files?

Is it possible for codelets to reference code in other files, like header files?
If I have a codelet file
//FileA.cpp
#include "FileB.h"
class SomeCustomVertex : public Vertex {
public:
bool compute() {
int a = SomeConstantDefinedInFileB;
}
...
}
and some other "codelet" file
//FileB.h
const int SomeConstantDefineInFileB = 42;
and in the host graph program:
graph.addCodelets({"codelets/FileA.cpp", "codelets/FileB.h"});
I get a compile error from popc:
fatal error: 'FileB.h' file not found
#include "FileB.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
terminate called after throwing an instance of 'poplar::graph_program_compilation_error'
what(): Codelet compilation failed (see compiler output for details)
I figured this out.
Graph::addCodelets has a parameter StringRef compileFlags = "", which you can use to inject compiler options.
popc --help shows an option
-I arg Add directory to include search path
So when I use graph.addCodelets({"codelets/FileA.cpp"}, "-I codelets"); in the host program, and have my codelets in 'codelets' subdirectory, this works. No need to explicitly list the ".h" files in the arguments.
Incidentally, also a good way to ensure compiler optimisation (-O3) for the custom codelets.

no suitable user-defined conversion from System::String ^ to System::String exists

I'm relatively inexperienced with C++ and I'm currently creating a simple Windows Forms project. The following code is providing a strange error that I just can't wrap my head around.
if (folderBrowserDialog1->ShowDialog() == ::DialogResult::OK) {
String filepath = folderBrowserDialog1->SelectedPath;
for (auto& p : std::filesystem::directory_iterator(filepath)) {
// read files from filepath
}
}
The error, "no suitable user-defined conversion from System::String ^ to System::String exists" is referring to the folderBrowserDialog1->SelectedPath line. Despite the docs I've checked stating that SelectedPath is a string, apparently it's not the same type of string as C++ is expecting? I assume I need to do some kind of conversion but I'm at a total loss as to how I should do that as I really assumed that SelectedPath would be a regular String.

aggregate ‘QSqlQuery testQuery’ has incomplete type and cannot be defined

I'm sure this must be something simple, but I can't quite work out what's up here...
I'm trying to create a QSqlQuery, and the compiler is giving me this:
error: aggregate ‘QSqlQuery testQuery’ has incomplete type and cannot be defined
This code is in my mainWindow class:
void MainWindow::on_toolButton_clicked()
{
QString filename;
filename = QFileDialog::getSaveFileName(this, tr("Save to SQL Database"),
"~/temp",
tr("Files (*.fdb)"));
QSqlDatabase testDatabase = QSqlDatabase::addDatabase("QSQLITE");
testDatabase.setDatabaseName(filename);
//this line won't compile:
QSqlQuery testQuery;
testDatabase.close();
QSqlDatabase::removeDatabase(QSqlDatabase::database().connectionName());
}
Can anyone see what I'm missing here?
The error message indicates that the type SqlQuery is not completely defined. QSqlQuery is defined in
#include <QSqlQuery>
Include that and things should compile ok.

Firebreath MethodConverter.h invalid initialization

Hi I created a firebreath project. I added this methods to the default generated code:
In the application API header file (MYAppAPI.h):
FB_JSAPI_EVENT(bgp, 3, (const FB::variant&, bool, int));
std::string bgp(std::string& val);
In the application API source file (MAppAPI.mm I am using objective-c):
registerMethod("bgp", make_method(this, &MyAppAPI::bgp));
std::string MyAppAPI::bgp(std::string& val){...}
But when I build the code, I am getting this error:
...firebreath/src/ScriptingCore/MethodConverter.h:115: error: invalid initialization of non-const reference of type 'std::string&' from a temporary of type 'std::basic_string, std::allocator >'
Any ideas?
that should read:
std::string MyAppAPI::bgp(const std::string& val){...}
note the const. You can't pass things by reference into a JS function, so it won't let you pass a non-const reference.

Trying to write a textfield value to file in c++

I am tearing my hair out over this error.
------ Build started: Project: shotfactorybatchgen, Configuration: Debug Win32 ------
shotfactorybatchgen.cpp
c:\documents and settings\administrator\my documents\visual studio 2010\projects\shotfactorybatchgen\shotfactorybatchgen\Form1.h(307): error C2664: 'fprintf' : cannot convert parameter 2 from 'System::String ^' to 'const char *'
No user-defined-conversion operator available, or
Cannot convert a managed type to an unmanaged type
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have looked all around the interwebs but I can not find an answer. Here is the code that the error is happening in.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Decimal value;
if(!Decimal::TryParse(textBox4->Text, value)) {
MessageBox::Show("Non-numeric characters detected in 'Wait Time' filed", "Oops", MessageBoxButtons::OK, MessageBoxIcon::Warning);
} else {
if(!Decimal::TryParse(textBox3->Text, value)) {
MessageBox::Show("Non-numeric characters detected in 'Max Upload' filed", "Oops", MessageBoxButtons::OK, MessageBoxIcon::Warning);
} else {
FILE *OutFile = fopen("run.bat","w");
fprintf(OutFile,"#ECHO OFF\r\nC:\\Python26\\python.exe factory.py");
if(factoryname->Text != ""){
fprintf(OutFile," -f ");
fprintf(OutFile,factoryname->Text);
}
fclose(OutFile);
}
}
}
Any ideas? It is a simple windows form application. I am using Visual Studio C++ 2010
Thanks
Colum
If factoryname->Text identifies a property, then its getter may throw a CLR exception, in which case you will leak the file handle OutFile. Consider not using fopen, etc. It's a C library function and there are better alternatives such as std::ofstream.
Alternatively, as you have .NET available, you could use StreamWriter which will let you pass System::String and thus avoid your conversion problem as well:
StreamWriter writer(someFilePath);
writer.WriteLine(someString);
C++/CLI will take care of closing the writer when the scope is exited.
It's simply a conversion error:
cannot convert parameter 2 from 'System::String ^' to 'const char *'
Possible solution is posted here:
What is the best way to convert between char* and System::String in C++/CLI
Opening Files
Convert System::String to const char*