Commit 3b8b2f9c authored by Pierre Aubert's avatar Pierre Aubert
Browse files

First full proxy generation test ok for compilation

parent 01d49a1d
......@@ -2,8 +2,8 @@
#ifndef __PRINT_ARCH_H__
#define __PRINT_ARCH_H__
void print_arch(const char* str);
// __restrict__
void print_arch(const char * __restrict__ str);
#endif
#ifndef __PRINT_ARCH_H__
#define __PRINT_ARCH_H__
// __restrict__
void print_arch(const char * __restrict__ str, long unsigned int size);
#endif
......@@ -117,9 +117,9 @@ std::string cpp_backendProxyLoaderParseArchFileSource(const PVecArchLib & vecArc
body += "\t\treturn false;\n";
body += "\t}\n";
body += "\t//Let's get the file size\n";
body += "\tfseek(fs, 0, SEEK_END);\n";
body += "\tsize_t fileSize(ftell(fs));\n";
body += "\tfseek(fs, 0, SEEK_SET);\n";
body += "\tfseek(fp, 0, SEEK_END);\n";
body += "\tsize_t fileSize(ftell(fp));\n";
body += "\tfseek(fp, 0, SEEK_SET);\n";
body += "\tif(fileSize == 0lu){\n";
body += "\t\treturn false;\n";
body += "\t}\n";
......@@ -128,9 +128,9 @@ std::string cpp_backendProxyLoaderParseArchFileSource(const PVecArchLib & vecArc
body += "\t//And load the file\n";
body += "\tif(fread(procCpuInfo, sizeof(char), fileSize, fp) != fileSize){return false;}\n";
body += "\t//Let's check the avalaible architectures\n";
std::string strElse("");
std::string strElse("\t");
for(PVecArchLib::const_reverse_iterator it(vecArchLib.rbegin()); it != vecArchLib.rend(); ++it){
body += "\t" + strElse + "if(strstr(procCpuInfo, \""+it->getArchitecture()+"\") != NULL){\n";
body += strElse + "if(strstr(procCpuInfo, \""+it->getArchitecture()+"\") != NULL){\n";
std::string libName(getFileName(it->getName()));
body += "\t\tload(\""+libName+"\");\n";
body += "\t}";
......@@ -217,7 +217,8 @@ std::string cpp_backendProxyLoaderSource(const PVecSource & vecSource, const PVe
std::string body(cpp_licenceSaveStr());
body += "#include <stdio.h>\n";
body += "#include <stdlib.h>\n";
body += "#include <dlfcn.h>\n\n";
body += "#include <dlfcn.h>\n";
body += "#include <string.h>\n\n";
for(PVecSource::const_iterator it(vecSource.begin()); it != vecSource.end(); ++it){
body += "#include \""+it->getName()+"\"\n";
......
......@@ -61,6 +61,7 @@ bool HeaderParser::parseFile(){
PFunction function;
if(parseDocString()){}
else if(p_parser->isMatch("//")){p_parser->getUntilKeyWithoutPatern("\n");} //Skip comment
else if(p_parser->isMatch("/*")){p_parser->getUntilKeyWithoutPatern("*/");} //Skip comment
else if(parseMacro()){}
else if(parseFunction(function)){
p_currentSource.getVecFunction().push_back(function);
......@@ -142,7 +143,7 @@ bool HeaderParser::parseFunction(PFunction & function){
std::string templateDef(""), returnType("");
parseTemplateDef(templateDef);
parseType(returnType);
std::cerr << "HeaderParser::parseFunction : returnType = '"<<returnType<<"'" << std::endl;
std::string functionName(p_parser->getNextToken());
if(functionName == ""){return false;} //This is not a function
function.setDocString(p_lastDocString);
......@@ -155,14 +156,21 @@ bool HeaderParser::parseFunction(PFunction & function){
PArgument arg;
if(parseDocString()){}
else if(p_parser->isMatch("//")){p_parser->getUntilKeyWithoutPatern("\n");} //Skip comment
else if(p_parser->isMatch("/*")){p_parser->getUntilKeyWithoutPatern("*/");} //Skip comment
else if(parseArgument(arg)){
function.getVecArgument().push_back(arg);
if(!p_parser->isMatch(",") && !isMatchRewind(")")){
errorAt();
std::cerr << "HeaderParser::parseFunction : expect ',' or ')' after function definition '"<<functionName<<"'" << std::endl;
return true;
}
}else{
errorAt();
std::cerr << "HeaderParser::parseFunction : cannot parse attribute" << std::endl;
return true;
}
p_parser->skipWhiteSpace();
}
if(!p_parser->isMatch(";")){
errorAt();
......@@ -201,6 +209,14 @@ void HeaderParser::parseTemplateDef(std::string & templateDef){
templateDef += ">";
}
///Say if the given string is a pointer or a reference
/** @param str : string to be analysed
* @return true if the given string is a pointer or a reference, false otherwise
*/
bool isPtrRef(const std::string & str){
return findCharsInString(str, "&*") || str == "__restrict__";
}
///Parse a PAttribute
/** @param[out] arg : PArgument to be parsed
* @return true on success, false otherwise
......@@ -213,21 +229,22 @@ bool HeaderParser::parseArgument(PArgument & arg){
std::string varName(""), ptrRef(""), tmpPtrRef("");
tmpPtrRef = p_parser->getNextToken();
// ptrRef = p_parser->getNextToken();
if(findCharsInString(tmpPtrRef, "&*")/* || tmpPtrRef == "__restrict__"*/){
while(findCharsInString(tmpPtrRef, "&*")/* || tmpPtrRef == "__restrict__"*/){
if(isPtrRef(tmpPtrRef)){
do{
ptrRef += tmpPtrRef;
tmpPtrRef = p_parser->getNextToken();
// if(tmpPtrRef == "__restrict__"){ptrRef += " ";}
ptrRef += tmpPtrRef;
}
varName = p_parser->getNextToken();
}while(isPtrRef(tmpPtrRef));
varName = tmpPtrRef;
}else{
ptrRef = tmpPtrRef;
varName = ptrRef;
ptrRef = "";
}
std::cerr << "HeaderParser::parseArgument : varName = '"<<varName<<"', ptrRef = '"<<ptrRef<<"'" << std::endl;
std::cerr << "HeaderParser::parseArgument : type = '"<<type<<", ptrRef = '"<<ptrRef<<"', varName = '"<<varName<<"'" << std::endl;
std::string defaultValue("");
if(p_parser->isMatch("=")){ //Some default value
defaultValue = p_parser->getNextToken();
......@@ -253,7 +270,7 @@ bool HeaderParser::parseArgument(PArgument & arg){
void HeaderParser::parseType(std::string & type){
type = "";
std::string token(p_parser->getNextToken());
while(token == "const" || token == "unsigned" || token == "long"/* || findCharsInString(token, "&*")*/){
while(token == "const" || token == "unsigned" || token == "long"){
type += token + " ";
token = p_parser->getNextToken();
}
......
......@@ -134,7 +134,7 @@ int main(int argc, char** argv){
defaultMode.getValue(libName, "library");
PVecArchLib vecArchLib;
// parseVecArchLib(vecArchLib, defaultMode);
parseVecArchLib(vecArchLib, defaultMode);
return processFiles(listInputFile, libName, vecArchLib, outputDir);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment