Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CTUApex
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Heldmann, Tim
CTUApex
Commits
1b74d37f
Commit
1b74d37f
authored
5 months ago
by
Heldmann, Tim
Browse files
Options
Downloads
Patches
Plain Diff
Add beta argument adjustor to CTUApex
parent
7518f333
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/CTUApexConsumer.cpp
+6
-0
6 additions, 0 deletions
src/CTUApexConsumer.cpp
src/main.cpp
+74
-4
74 additions, 4 deletions
src/main.cpp
with
80 additions
and
4 deletions
src/CTUApexConsumer.cpp
+
6
−
0
View file @
1b74d37f
...
...
@@ -150,6 +150,12 @@ void CTUApexConsumer::HandleTranslationUnit(clang::ASTContext &Context) {
SPDLOG_INFO
(
"Generate wrapper calls"
);
SPDLOG_CRITICAL
(
"WRAPPER CALLS CAN NOT YET BE IMPLEMENTED"
);
for
(
const
auto
&
e
:
call_graph
->
getNodes
()){
std
::
cout
<<
e
.
second
->
getFunctionName
()
<<
"
\n
"
;
}
assert
(
call_graph
->
getMain
());
if
(
auto
md
=
call_graph
->
getMain
()
->
checkAndGet
<
ExtractionMetadata
>
();
md
.
first
&&
!
md
.
second
->
isMarkedToExtract
()){
//we have no main function and need to create or own
outFile
<<
"
\n
int main(){return 0;}
\n
"
;
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
74
−
4
View file @
1b74d37f
...
...
@@ -60,14 +60,15 @@ static cl::opt<bool> OnlyWrapper("generate-only-wrapper", cl::desc("Output only
static
cl
::
opt
<
bool
>
DumpAnalysisResult
(
"dump-analysis-result"
,
cl
::
desc
(
"Dump the dependence analysis result to stdout"
),
cl
::
cat
(
CTUApex
));
class
CTUApexF
actory
:
clang
::
ASTFrontendAction
{
class
CTUApexF
rontendAction
:
clang
::
ASTFrontendAction
{
public:
CTUApexF
actory
(
metacg
::
Callgraph
&
cg
)
:
cg
(
&
cg
)
{}
CTUApexF
rontendAction
(
metacg
::
Callgraph
&
cg
)
:
cg
(
&
cg
)
{}
std
::
unique_ptr
<
clang
::
ASTConsumer
>
newASTConsumer
()
{
return
std
::
unique_ptr
<
clang
::
ASTConsumer
>
(
new
CTUApexConsumer
(
cg
,
includes
,
macros
,
pragmas
));
}
std
::
unique_ptr
<
clang
::
ASTConsumer
>
CreateASTConsumer
([[
maybe_unused
]]
clang
::
CompilerInstance
&
compiler
,
[[
maybe_unused
]]
llvm
::
StringRef
sr
)
{
return
std
::
unique_ptr
<
clang
::
ASTConsumer
>
(
new
CTUApexConsumer
(
cg
,
includes
,
macros
,
pragmas
));
...
...
@@ -98,6 +99,64 @@ void markFunctionsAlongCallpaths(metacg::Callgraph &cg) {
}
}
#include
"clang/Basic/SourceManager.h"
#include
"clang/Frontend/CompilerInstance.h"
#include
"clang/Frontend/FrontendAction.h"
#include
"clang/Lex/Preprocessor.h"
#include
"clang/Lex/HeaderSearch.h"
#include
"clang/Tooling/Tooling.h"
using
namespace
clang
;
using
namespace
clang
::
tooling
;
std
::
vector
<
std
::
string
>
clangIncludeBasedArgumentAdjustor
(
const
CommandLineArguments
&
cla
,
StringRef
sr
){
//call the compiler specified in cla[0] with -S and -v like so
std
::
string
command
=
"clang"
;
//command.append(" -S -v");
command
.
append
(
" -W,p -v -fsyntax-only"
);
for
(
int
i
=
1
;
i
<
cla
.
size
();
i
++
){
command
.
append
(
" "
+
cla
[
i
]);
}
command
.
append
(
" 2>&1"
);
std
::
unique_ptr
<
FILE
,
decltype
(
&
pclose
)
>
pipe
(
popen
(
command
.
c_str
(),
"r"
),
pclose
);
//then read the output of the command like so:
std
::
string
txt
;
std
::
array
<
char
,
128
>
buffer
{};
while
(
fgets
(
buffer
.
data
(),
buffer
.
size
(),
pipe
.
get
())
!=
nullptr
)
{
txt
+=
buffer
.
data
();
}
//search for "include search starts here" string and add all the paths with -I to the tool invocation
txt
=
txt
.
substr
(
txt
.
rfind
(
"search starts here:"
)
+
20
,
txt
.
rfind
(
"End of search list."
)
-
txt
.
rfind
(
"search starts here:"
)
-
20
);
std
::
vector
<
std
::
string
>
ret
;
ret
.
assign
(
cla
.
begin
(),
cla
.
end
());
std
::
string
::
size_type
pos
;
std
::
string
::
size_type
prev
=
0
;
while
((
pos
=
txt
.
find
(
'\n'
,
prev
))
!=
std
::
string
::
npos
)
{
ret
.
push_back
(
"-I"
+
txt
.
substr
(
prev
,
pos
-
prev
));
prev
=
pos
+
2
;
}
return
ret
;
}
std
::
vector
<
std
::
string
>
clangResourceDirBasedAdjuster
(
const
CommandLineArguments
&
cla
,
StringRef
){
//call the compiler specified in cla[0] with -S and -v like so
std
::
string
command
=
"clang --print-resource-dir 2>1&"
;
std
::
unique_ptr
<
FILE
,
decltype
(
&
pclose
)
>
pipe
(
popen
(
command
.
c_str
(),
"r"
),
pclose
);
//then read the output of the command like so:
std
::
string
txt
;
std
::
array
<
char
,
128
>
buffer
{};
while
(
fgets
(
buffer
.
data
(),
buffer
.
size
(),
pipe
.
get
())
!=
nullptr
)
{
txt
+=
buffer
.
data
();
}
std
::
vector
<
std
::
string
>
ret
;
ret
.
assign
(
cla
.
begin
(),
cla
.
end
());
trim
(
txt
);
txt
.
pop_back
();
ret
.
push_back
(
"-I"
+
txt
+
"/include"
);
return
ret
;
}
int
main
(
int
argc
,
const
char
**
argv
)
{
auto
ExpectedParser
=
CommonOptionsParser
::
create
(
argc
,
argv
,
CTUApex
);
...
...
@@ -131,7 +190,10 @@ int main(int argc, const char **argv) {
CommonOptionsParser
&
OptionsParser
=
ExpectedParser
.
get
();
ClangTool
tool
(
OptionsParser
.
getCompilations
(),
OptionsParser
.
getSourcePathList
());
tool
.
clearArgumentsAdjusters
();
tool
.
appendArgumentsAdjuster
(
clangResourceDirBasedAdjuster
);
metacg
::
io
::
FileSource
fs
(
cg_file
.
getValue
());
...
...
@@ -147,8 +209,14 @@ int main(int argc, const char **argv) {
auto
&
mcgManager
=
metacg
::
graph
::
MCGManager
::
get
();
mcgManager
.
addToManagedGraphs
(
"emptyGraph"
,
std
::
make_unique
<
metacg
::
Callgraph
>
());
nlohmann
::
json
j
=
fs
.
get
().
at
(
"_CG"
);
std
::
cout
<<
j
.
dump
(
4
);
metacg
::
io
::
VersionTwoMetaCGReader
::
upgradeV2FormatToV3Format
(
j
);
std
::
cout
<<
j
.
dump
(
4
);
mcgReader
->
read
();
auto
&
cg
=
*
mcgManager
.
getCallgraph
();
std
::
cout
<<
cg
.
size
()
<<
"
\n
"
;
//Add extraction point gotten via the CLI
for
(
const
auto
&
extractionFunc
:
extractionPoints
){
if
(
cg
.
hasNode
(
extractionFunc
))
{
...
...
@@ -162,8 +230,10 @@ int main(int argc, const char **argv) {
markFunctionsAlongCallpaths
(
cg
);
tool
.
run
(
clang
::
tooling
::
newFrontendActionFactory
<
CTUApexFactory
>
(
new
CTUApexFactory
(
*
mcgManager
.
getCallgraph
())).
get
());
tool
.
run
(
clang
::
tooling
::
newFrontendActionFactory
<
CTUApexFrontendAction
>
(
new
CTUApexFrontendAction
(
*
mcgManager
.
getCallgraph
())).
get
());
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment