Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixHPCProxy
Commits
73f89f10
Commit
73f89f10
authored
Dec 09, 2020
by
Pierre Aubert
Browse files
The parsing an dthe basic code generation of basic input parsing is ok
parent
6bac8354
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
185 additions
and
32 deletions
+185
-32
TESTS/CMakeLists.txt
TESTS/CMakeLists.txt
+1
-0
TESTS/TEST_BASE_HEADER/CMakeLists.txt
TESTS/TEST_BASE_HEADER/CMakeLists.txt
+4
-0
TESTS/TEST_BASE_HEADER/testHeader.h
TESTS/TEST_BASE_HEADER/testHeader.h
+7
-0
src/BackEnd/backend.cpp
src/BackEnd/backend.cpp
+141
-15
src/FrontEnd/HeaderParser.cpp
src/FrontEnd/HeaderParser.cpp
+12
-5
src/Representation/representation.cpp
src/Representation/representation.cpp
+7
-1
src/Representation/representation.h
src/Representation/representation.h
+2
-0
src/main.cpp
src/main.cpp
+11
-11
No files found.
TESTS/CMakeLists.txt
View file @
73f89f10
project
(
Phoenix
)
cmake_minimum_required
(
VERSION 2.8
)
add_subdirectory
(
TEST_BASE_HEADER
)
TESTS/TEST_BASE_HEADER/CMakeLists.txt
0 → 100644
View file @
73f89f10
project
(
Phoenix
)
cmake_minimum_required
(
VERSION 2.8
)
TESTS/TEST_BASE_HEADER/testHeader.h
0 → 100644
View file @
73f89f10
//Comment
void
print_arch
(
const
char
*
str
);
src/BackEnd/backend.cpp
View file @
73f89f10
...
...
@@ -18,31 +18,157 @@ std::string cpp_licenceSaveStr(){
body
+=
"
\t
Licence : CeCILL-C
\n
"
;
body
+=
"****************************************/
\n\n\n
"
;
body
+=
"//Warning : this file has been generated automatically by the phoenix_h
df5
program
\n
"
;
body
+=
"//You can find it at https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixH
DF5
\n
"
;
body
+=
"//Warning : this file has been generated automatically by the phoenix_h
pc_proxy
program
\n
"
;
body
+=
"//You can find it at https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS/PhoenixH
PCProxy
\n
"
;
body
+=
"//Do NOT modify it
\n\n\n
"
;
return
body
;
}
///Get the handle name of the given function
/** @param functionName : function name
* @return corresponding function name
*/
std
::
string
getHandleFunction
(
const
std
::
string
&
functionName
){
return
"handle_"
+
functionName
;
}
///Get the handle type name of the given function
/** @param functionName : function name
* @return corresponding function name
*/
std
::
string
getHandleFunctionType
(
const
std
::
string
&
functionName
){
return
"FunctionTypehandle_"
+
functionName
;
}
///Save the function prototype as an inline function
/** @param function : PFunction to be used
* @return corresponding string
*/
std
::
string
cpp_backendTableHeaderInline
(
PFunction
&
function
){
if
(
function
.
getOtherCode
()
!=
""
){
return
function
.
getOtherCode
();}
std
::
string
body
(
""
);
if
(
function
.
getDocString
()
!=
""
){
body
+=
function
.
getDocString
();}
if
(
function
.
getTemplateDef
()
!=
""
){
body
+=
function
.
getTemplateDef
();}
body
+=
"inline "
+
function
.
getOutputType
()
+
" "
+
function
.
getName
()
+
"("
;
bool
isComma
(
false
);
PVecArgument
&
vecArg
=
function
.
getVecArgument
();
for
(
PVecArgument
::
iterator
it
(
vecArg
.
begin
());
it
!=
vecArg
.
end
();
++
it
){
if
(
isComma
){
body
+=
", "
;}
body
+=
it
->
getType
()
+
" "
;
if
(
it
->
getPtrRef
()
!=
""
){
body
+=
it
->
getPtrRef
()
+
" "
;}
body
+=
it
->
getName
();
if
(
it
->
getDefaultValue
()
!=
""
){
body
+=
" = "
+
it
->
getDefaultValue
();}
isComma
=
true
;
}
body
+=
"){
\n
"
;
isComma
=
false
;
body
+=
"
\t
"
+
getHandleFunction
(
function
.
getName
())
+
"("
;
for
(
PVecArgument
::
iterator
it
(
vecArg
.
begin
());
it
!=
vecArg
.
end
();
++
it
){
if
(
isComma
){
body
+=
", "
;}
body
+=
it
->
getName
();
isComma
=
true
;
}
body
+=
");
\n
"
;
body
+=
"}
\n\n
"
;
return
body
;
}
///Save the function prototype as an inline function
/** @param function : PFunction to be used
* @return corresponding string
*/
std
::
string
cpp_backendTableHeaderHandleType
(
PFunction
&
function
){
if
(
!
repr_isFunction
(
function
)){
return
""
;}
std
::
string
body
(
""
);
body
+=
"typedef "
+
function
.
getOutputType
()
+
"(*"
+
getHandleFunctionType
(
function
.
getName
())
+
")("
;
bool
isComma
(
false
);
PVecArgument
&
vecArg
=
function
.
getVecArgument
();
for
(
PVecArgument
::
iterator
it
(
vecArg
.
begin
());
it
!=
vecArg
.
end
();
++
it
){
if
(
isComma
){
body
+=
", "
;}
body
+=
it
->
getType
();
if
(
it
->
getPtrRef
()
!=
""
){
body
+=
" "
+
it
->
getPtrRef
();}
isComma
=
true
;
}
body
+=
");
\n
"
;
return
body
;
}
///Save the header of the given PSource
/** @param source : PSource to be used
* @return corresponding string
*/
std
::
string
cpp_backendHeader
(
PSource
&
source
){
std
::
string
body
(
cpp_licenceSaveStr
());
std
::
string
baseMacro
(
"__"
+
strToUpper
(
eraseExtension
(
source
.
getName
()))
+
"_H__"
);
body
+=
"#ifndef "
+
baseMacro
+
"
\n
"
;
body
+=
"#define "
+
baseMacro
+
"
\n\n
"
;
body
+=
"#include <iostream>
\n\n\n
"
;
PVecFunction
&
vecFunction
=
source
.
getVecFunction
();
for
(
PVecFunction
::
iterator
it
(
vecFunction
.
begin
());
it
!=
vecFunction
.
end
();
++
it
){
body
+=
cpp_backendTableHeaderHandleType
(
*
it
);
}
body
+=
"
\n\n
"
;
for
(
PVecFunction
::
iterator
it
(
vecFunction
.
begin
());
it
!=
vecFunction
.
end
();
++
it
){
if
(
!
repr_isFunction
(
*
it
)){
continue
;}
body
+=
"extern "
+
getHandleFunctionType
(
it
->
getName
())
+
" "
+
getHandleFunction
(
it
->
getName
())
+
";
\n
"
;
}
body
+=
"
\n\n
"
;
for
(
PVecFunction
::
iterator
it
(
vecFunction
.
begin
());
it
!=
vecFunction
.
end
();
++
it
){
body
+=
cpp_backendTableHeaderInline
(
*
it
);
}
body
+=
"#endif
\n\n
"
;
return
body
;
}
///Save the source of the given PSource
/** @param source : PSource to be used
* @return corresponding string
*/
std
::
string
cpp_backendSource
(
PSource
&
source
){
std
::
string
body
(
cpp_licenceSaveStr
());
body
+=
"#include <stdio.h>
\n
"
;
body
+=
"#include <stdlib.h>
\n
"
;
body
+=
"#include <dlfcn.h>
\n\n
"
;
body
+=
"#include
\"
"
+
eraseExtension
(
source
.
getName
())
+
".h
\"\n\n
"
;
PVecFunction
&
vecFunction
=
source
.
getVecFunction
();
for
(
PVecFunction
::
iterator
it
(
vecFunction
.
begin
());
it
!=
vecFunction
.
end
();
++
it
){
if
(
!
repr_isFunction
(
*
it
)){
continue
;}
body
+=
getHandleFunctionType
(
it
->
getName
())
+
" "
+
getHandleFunction
(
it
->
getName
())
+
";
\n
"
;
}
body
+=
"
\n\n
"
;
body
+=
"///Update the all the function handles of the file
\n
"
;
body
+=
"/**
\t
@param handle : pointer to loaded library
\n
"
;
body
+=
"*/
\n
"
;
body
+=
"void update_function_handle(void * handle){
\n
"
;
for
(
PVecFunction
::
iterator
it
(
vecFunction
.
begin
());
it
!=
vecFunction
.
end
();
++
it
){
if
(
!
repr_isFunction
(
*
it
)){
continue
;}
//TODO : find a way to demangle the function name
body
+=
"
\t
"
+
getHandleFunction
(
it
->
getName
())
+
" = ("
+
getHandleFunctionType
(
it
->
getName
())
+
")(dlsym(handle,
\"
"
+
it
->
getName
()
+
"
\"
));
\n
"
;
}
body
+=
"}
\n\n
"
;
return
body
;
}
///Save a vector of PSource in the output directory
/** @param source : source to be saved
* @param outputDir : output directory where to save PSource
* @return true on success, false otherwise
*/
bool
cpp_backend
(
PSource
&
source
,
const
std
::
string
&
outputDir
){
//
std::string headerSrc(cpp_backendHeader(source));
//
std::string sourceSrc(cpp_backendSource(source));
//
std::string baseFileName(eraseExtension(source.getName()));
//
std::string outputHeaderFile(outputDir + "/" + baseFileName + ".h");
//
std::string outputSourceFile(outputDir + "/" + baseFileName + ".cpp");
//
if(!saveFileContent(outputHeaderFile, headerSrc)){
//
std::cerr << "cpp_backend : cannot save header file '"<<outputHeaderFile<<"'" << std::endl;
//
return false;
//
}
//
if(!saveFileContent(outputSourceFile, sourceSrc)){
//
std::cerr << "cpp_backend : cannot save source file '"<<outputSourceFile<<"'" << std::endl;
//
return false;
//
}
std
::
string
headerSrc
(
cpp_backendHeader
(
source
));
std
::
string
sourceSrc
(
cpp_backendSource
(
source
));
std
::
string
baseFileName
(
eraseExtension
(
source
.
getName
()));
std
::
string
outputHeaderFile
(
outputDir
+
"/"
+
baseFileName
+
".h"
);
std
::
string
outputSourceFile
(
outputDir
+
"/"
+
baseFileName
+
".cpp"
);
if
(
!
saveFileContent
(
outputHeaderFile
,
headerSrc
)){
std
::
cerr
<<
"cpp_backend : cannot save header file '"
<<
outputHeaderFile
<<
"'"
<<
std
::
endl
;
return
false
;
}
if
(
!
saveFileContent
(
outputSourceFile
,
sourceSrc
)){
std
::
cerr
<<
"cpp_backend : cannot save source file '"
<<
outputSourceFile
<<
"'"
<<
std
::
endl
;
return
false
;
}
return
true
;
}
...
...
src/FrontEnd/HeaderParser.cpp
View file @
73f89f10
...
...
@@ -130,7 +130,6 @@ bool HeaderParser::parseFunction(PFunction & function){
parseTemplateDef
(
templateDef
);
parseType
(
returnType
);
std
::
string
functionName
(
p_parser
->
getNextToken
());
if
(
functionName
==
""
){
return
false
;}
//This is not a function
function
.
setDocString
(
p_lastDocString
);
...
...
@@ -138,7 +137,7 @@ bool HeaderParser::parseFunction(PFunction & function){
//Let's get the arguments of the function
if
(
!
p_parser
->
isMatch
(
"("
)){
return
false
;}
//This is not a function
function
.
setName
(
functionName
);
function
.
setOutputType
(
returnType
);
while
(
!
p_parser
->
isEndOfFile
()
&&
!
p_parser
->
isMatch
(
")"
)
&&
p_run
){
PArgument
arg
;
if
(
parseDocString
()){}
...
...
@@ -152,6 +151,11 @@ bool HeaderParser::parseFunction(PFunction & function){
}
p_parser
->
skipWhiteSpace
();
}
if
(
!
p_parser
->
isMatch
(
";"
)){
errorAt
();
std
::
cerr
<<
"HeaderParser::parseFunction : expect ';' after function definition '"
<<
functionName
<<
"'"
<<
std
::
endl
;
return
true
;
}
playOtherCode
();
return
true
;
...
...
@@ -228,10 +232,13 @@ bool HeaderParser::parseArgument(PArgument & arg){
/** @param[out] type : type to be parsed
*/
void
HeaderParser
::
parseType
(
std
::
string
&
type
){
type
=
p_parser
->
getNextToken
();
if
(
type
==
"unsigned"
){
type
+=
" "
+
p_parser
->
getNextToken
();
type
=
""
;
std
::
string
token
(
p_parser
->
getNextToken
());
while
(
token
==
"const"
||
token
==
"unsigned"
){
type
+=
token
+
" "
;
token
=
p_parser
->
getNextToken
();
}
type
+=
token
;
}
...
...
src/Representation/representation.cpp
View file @
73f89f10
...
...
@@ -6,5 +6,11 @@
#include "representation.h"
///Say if the current function is a function prototype
/** @param fct : PFunction
* @return true if the function is a function prototype, false otherwise
*/
bool
repr_isFunction
(
const
PFunction
&
fct
){
return
fct
.
getOtherCode
()
==
""
;
}
src/Representation/representation.h
View file @
73f89f10
...
...
@@ -15,4 +15,6 @@ typedef std::vector<PArgument> PVecArgument;
typedef
std
::
vector
<
PFunction
>
PVecFunction
;
typedef
std
::
vector
<
PSource
>
PVecSource
;
bool
repr_isFunction
(
const
PFunction
&
fct
);
#endif
src/main.cpp
View file @
73f89f10
...
...
@@ -36,17 +36,17 @@ OptionParser createOptionParser(){
* @return true on success, false otherwise
*/
bool
createSourceFromConfig
(
const
std
::
string
&
inputFile
,
const
std
::
string
&
outputDir
){
//
HeaderParser parser;
//
if(!parser.load(inputFile)){
//
std::cerr << "createSourceFromConfig : cannot parse the input file '"<<inputFile<<"'" << std::endl;
//
return false;
//
}
//
PVecSource vecSource = parser.getVecSource();
//
bool b(
ph5
_backend(vecSource, outputDir));
//
if(!b){
//
std::cerr << "createSourceFromConfig : cannot save source/header from input file '"<<inputFile<<"'" << std::endl;
//
}
//
return b;
HeaderParser
parser
;
if
(
!
parser
.
load
(
inputFile
)){
std
::
cerr
<<
"createSourceFromConfig : cannot parse the input file '"
<<
inputFile
<<
"'"
<<
std
::
endl
;
return
false
;
}
PVecSource
vecSource
=
parser
.
getVecSource
();
bool
b
(
cpp
_backend
(
vecSource
,
outputDir
));
if
(
!
b
){
std
::
cerr
<<
"createSourceFromConfig : cannot save source/header from input file '"
<<
inputFile
<<
"'"
<<
std
::
endl
;
}
return
b
;
return
true
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment