Skip to content

Commit 82ba195

Browse files
committed
added output file option
1 parent a4c2430 commit 82ba195

File tree

6 files changed

+55
-146
lines changed

6 files changed

+55
-146
lines changed

build.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

3-
rm -r build/
3+
rm -rf build/
44
mkdir build
55
cd build/
6-
# cmake .. -DCMAKE_BUILD_TYPE=Release
7-
cmake .. -DCMAKE_BUILD_TYPE=Debug
6+
cmake .. -DCMAKE_BUILD_TYPE=Release
7+
# cmake .. -DCMAKE_BUILD_TYPE=Debug
88
make -j
99
cd ../

run.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
DIR=$(dirname "$0")
2-
LIB="$DIR/build/src/rose/librose.so"
3-
PLUGIN="-rose"
4-
FILENAME=$1;
2+
LIB="$DIR/build/src/libompdart.so"
3+
PLUGIN="ompdart"
4+
INFILENAME=$1
5+
OUTFILENAME=$2
56

67
set -x
7-
clang -Xclang -load -Xclang $LIB -Xclang -plugin -Xclang $PLUGIN -fopenmp -c $FILENAME
8+
# help
9+
# clang -Xclang -load -Xclang $LIB -Xclang -plugin -Xclang $PLUGIN -Xclang -plugin-arg-$PLUGIN -Xclang --help -fopenmp -c $FILENAME
10+
clang -Xclang -load -Xclang $LIB -Xclang -plugin -Xclang $PLUGIN -Xclang -plugin-arg-$PLUGIN -Xclang --output -Xclang -plugin-arg-$PLUGIN -Xclang "$OUTFILENAME" -fopenmp -c $INFILENAME
811
# gdb --args clang -Xclang -load -Xclang $LIB -Xclang -plugin -Xclang $PLUGIN -fopenmp -c $FILENAME

src/FindDecl.cpp

-123
This file was deleted.

src/OmpDart.cpp

+27-5
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,44 @@
44
#include "OmpDartASTConsumer.h"
55

66
class OmpDartASTAction : public PluginASTAction {
7+
private:
8+
std::string OutFilePath;
79
protected:
810
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
911
llvm::StringRef) override {
10-
return std::make_unique<OmpDartASTConsumer>(&CI);
12+
return std::make_unique<OmpDartASTConsumer>(&CI, &OutFilePath);
1113
}
1214

1315
bool ParseArgs(const CompilerInstance &CI,
1416
const std::vector<std::string> &args) override {
17+
for (unsigned i = 0, e = args.size(); i != e; ++i) {
18+
llvm::errs() << "arg " << i << ": " << args[i] << "\n";
19+
20+
DiagnosticsEngine &D = CI.getDiagnostics();
21+
if (args[i] == "-o" || args[i] == "--output") {
22+
if (i + 1 >= e) {
23+
D.Report(
24+
D.getCustomDiagID(DiagnosticsEngine::Error, "missing argument"));
25+
return false;
26+
}
27+
++i;
28+
// record output preference
29+
OutFilePath = args[i];
30+
}
31+
if (args[i] == "-h" || args[i] == "--help") {
32+
PrintHelp(llvm::errs());
33+
return false;
34+
}
35+
}
36+
1537
return true;
1638
}
17-
void PrintHelp(llvm::raw_ostream& ros) {
18-
ros << "TODO:: Help goes here\n";
39+
void PrintHelp(llvm::raw_ostream &ros) {
40+
ros << "TODO help goes here\n";
1941
return;
2042
}
2143

2244
}; // end class OmpDartASTAction
2345

24-
static FrontendPluginRegistry::Add<OmpDartASTAction>
25-
X("-ompdart", "target data analysis");
46+
static FrontendPluginRegistry::Add<OmpDartASTAction> X("ompdart",
47+
"target data analysis");

src/OmpDartASTConsumer.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
#include "AnalysisUtils.h"
44
#include "DirectiveRewriter.h"
5+
#include <string>
56

67
using namespace clang;
78

8-
OmpDartASTConsumer::OmpDartASTConsumer(CompilerInstance *CI)
9+
OmpDartASTConsumer::OmpDartASTConsumer(CompilerInstance *CI,
10+
const std::string *OutFilePath)
911
: Context(&(CI->getASTContext())), SM(&(Context->getSourceManager())),
1012
Visitor(new OmpDartASTVisitor(CI)),
1113
FunctionTrackers(Visitor->getFunctionTrackers()),
1214
Kernels(Visitor->getTargetRegions()) {
1315
TheRewriter.setSourceMgr(*SM, Context->getLangOpts());
16+
this->OutFilePath = *OutFilePath;
1417
}
1518

1619
void OmpDartASTConsumer::HandleTranslationUnit(ASTContext &Context) {
@@ -74,15 +77,18 @@ void OmpDartASTConsumer::HandleTranslationUnit(ASTContext &Context) {
7477
}
7578

7679
FileID FID = SM->getMainFileID();
77-
std::string ParsedFilename =
78-
SM->getFilename(SM->getLocForStartOfFile(FID)).str();
79-
char *CParsedFilename = strdup(ParsedFilename.c_str());
80-
char *Basename = basename(CParsedFilename);
80+
if (OutFilePath.empty()) {
81+
std::string ParsedFilename =
82+
SM->getFilename(SM->getLocForStartOfFile(FID)).str();
83+
char *CParsedFilename = strdup(ParsedFilename.c_str());
84+
char *Basename = basename(CParsedFilename);
8185

82-
std::string Filename = "/tmp/" + std::string(Basename);
83-
llvm::outs() << "Modified File at " << Filename << "\n";
86+
OutFilePath = "/tmp/" + std::string(Basename);
87+
free(CParsedFilename);
88+
}
89+
llvm::outs() << "Modified File at " << OutFilePath << "\n";
8490
std::error_code ErrorCode;
85-
llvm::raw_fd_ostream OutFile(Filename, ErrorCode, llvm::sys::fs::OF_None);
91+
llvm::raw_fd_ostream OutFile(OutFilePath, ErrorCode, llvm::sys::fs::OF_None);
8692
if (!ErrorCode) {
8793
// print to terminal
8894
// TheRewriter.getEditBuffer(SM.getMainFileID()).write(llvm::outs());
@@ -92,5 +98,4 @@ void OmpDartASTConsumer::HandleTranslationUnit(ASTContext &Context) {
9298
llvm::outs() << "Could not create file\n";
9399
}
94100
OutFile.close();
95-
free(CParsedFilename);
96101
}

src/OmpDartASTConsumer.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ class OmpDartASTConsumer : public ASTConsumer {
1212
SourceManager *SM;
1313
OmpDartASTVisitor *Visitor;
1414
Rewriter TheRewriter;
15+
std::string OutFilePath;
1516

1617
std::vector<DataTracker *> &FunctionTrackers;
1718
std::vector<Kernel *> &Kernels;
1819

1920
public:
20-
explicit OmpDartASTConsumer(CompilerInstance *CI);
21-
21+
explicit OmpDartASTConsumer(CompilerInstance *CI,
22+
const std::string *OutFilePath);
23+
2224
virtual void HandleTranslationUnit(ASTContext &Context);
2325

2426
}; // end class OmpDartASTConsumer

0 commit comments

Comments
 (0)