Commit 0c63ae2a authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

went down to clang hell, came back alive...

parent fab41620
......@@ -35,6 +35,10 @@ set (LIBRARY_NAME xacc-improved-scaffold)
file (GLOB HEADERS *.hpp)
file (GLOB SRC *.cpp)
set(CMAKE_CXX_FLAGS "-D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -O3 -w -fomit-frame-pointer -fvisibility-inlines-hidden -fPIC -Woverloaded-virtual -Wcast-qual")
set_source_files_properties(MyASTConsumer.cpp PROPERTIES COMPILE_FLAGS -fno-rtti)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate)
include_directories(/usr/local/scaffold/include)
include_directories(/usr/local/scaffold/build/include)
......@@ -50,5 +54,5 @@ link_directories("/usr/local/scaffold/build/Release+Asserts/lib")
#LLVMAsmParser;LLVMInstrumentation;LLVMLinker;LLVMArchive;LLVMBitReader;LLVMDebugInfo;LLVMJIT;LLVMipo;LLVMVectorize;LLVMBitWriter;LLVMTableGen;LLVMHexagonCodeGen;LLVMHexagonDesc;LLVMHexagonInfo;LLVMHexagonAsmPrinter;LLVMPTXCodeGen;LLVMPTXDesc;LLVMPTXInfo;LLVMPTXAsmPrinter;LLVMMBlazeDisassembler;LLVMMBlazeAsmParser;LLVMMBlazeCodeGen;LLVMMBlazeDesc;LLVMMBlazeInfo;LLVMMBlazeAsmPrinter;LLVMCppBackendCodeGen;LLVMCppBackendInfo;LLVMMSP430CodeGen;LLVMMSP430Desc;LLVMMSP430Info;LLVMMSP430AsmPrinter;LLVMXCoreCodeGen;LLVMXCoreDesc;LLVMXCoreInfo;LLVMCellSPUCodeGen;LLVMCellSPUDesc;LLVMCellSPUInfo;LLVMMipsDisassembler;LLVMMipsAsmParser;LLVMMipsCodeGen;LLVMMipsDesc;LLVMMipsInfo;LLVMMipsAsmPrinter;LLVMARMDisassembler;LLVMARMAsmParser;LLVMARMCodeGen;LLVMARMDesc;LLVMARMInfo;LLVMARMAsmPrinter;LLVMPowerPCCodeGen;LLVMPowerPCDesc;LLVMPowerPCInfo;LLVMPowerPCAsmPrinter;LLVMSparcCodeGen;LLVMSparcDesc;LLVMSparcInfo;LLVMX86AsmParser;LLVMX86Disassembler;LLVMX86CodeGen;LLVMSelectionDAG;LLVMAsmPrinter;LLVMX86Desc;LLVMX86Info;LLVMX86AsmPrinter;LLVMX86Utils;gtest_main;gtest;LLVMMCDisassembler;LLVMMCParser;LLVMInterpreter;LLVMCodeGen;LLVMScalarOpts;LLVMInstCombine;LLVMTransformUtils;LLVMipa;LLVMAnalysis;LLVMMCJIT;LLVMRuntimeDyld;LLVMExecutionEngine;LLVMTarget;LLVMMC;LLVMObject;LLVMCore;LLVMSupport
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "/usr/local/scaffold/include;/usr/local/scaffold/build/include;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_SOURCE_DIR}/quantum/gate/utils" "${LIBRARY_NAME};xacc-gateqir;clangTooling;clangFrontendTool;clangFrontend;clangDriver;clangSerialization;clangCodeGen;clangParse;clangSema;clangStaticAnalyzerFrontend;clangStaticAnalyzerCheckers;clangStaticAnalyzerCore;clangAnalysis;clangARCMigrate;clangEdit;clangAST;clangLex;clangBasic;LLVMAsmParser;LLVMInstrumentation;LLVMLinker;LLVMArchive;LLVMBitReader;LLVMDebugInfo;LLVMJIT;LLVMipo;LLVMVectorize;LLVMBitWriter;LLVMTableGen;LLVMHexagonCodeGen;LLVMHexagonDesc;LLVMHexagonInfo;LLVMHexagonAsmPrinter;LLVMPTXCodeGen;LLVMPTXDesc;LLVMPTXInfo;LLVMPTXAsmPrinter;LLVMMBlazeDisassembler;LLVMMBlazeAsmParser;LLVMMBlazeCodeGen;LLVMMBlazeDesc;LLVMMBlazeInfo;LLVMMBlazeAsmPrinter;LLVMCppBackendCodeGen;LLVMCppBackendInfo;LLVMMSP430CodeGen;LLVMMSP430Desc;LLVMMSP430Info;LLVMMSP430AsmPrinter;LLVMXCoreCodeGen;LLVMXCoreDesc;LLVMXCoreInfo;LLVMCellSPUCodeGen;LLVMCellSPUDesc;LLVMCellSPUInfo;LLVMMipsDisassembler;LLVMMipsAsmParser;LLVMMipsCodeGen;LLVMMipsDesc;LLVMMipsInfo;LLVMMipsAsmPrinter;LLVMARMDisassembler;LLVMARMAsmParser;LLVMARMCodeGen;LLVMARMDesc;LLVMARMInfo;LLVMARMAsmPrinter;LLVMPowerPCCodeGen;LLVMPowerPCDesc;LLVMPowerPCInfo;LLVMPowerPCAsmPrinter;LLVMSparcCodeGen;LLVMSparcDesc;LLVMSparcInfo;LLVMX86AsmParser;LLVMX86Disassembler;LLVMX86CodeGen;LLVMSelectionDAG;LLVMAsmPrinter;LLVMX86Desc;LLVMX86Info;LLVMX86AsmPrinter;LLVMX86Utils;gtest_main;gtest;LLVMMCDisassembler;LLVMMCParser;LLVMInterpreter;LLVMCodeGen;LLVMScalarOpts;LLVMInstCombine;LLVMTransformUtils;LLVMipa;LLVMAnalysis;LLVMMCJIT;LLVMRuntimeDyld;LLVMExecutionEngine;LLVMTarget;LLVMMC;LLVMObject;LLVMCore;LLVMSupport;dl")
add_tests("${test_files}" "/usr/local/scaffold/include;/usr/local/scaffold/build/include;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_SOURCE_DIR}/quantum/gate/utils" "${LIBRARY_NAME};xacc-gateqir;clangTooling;clangFrontendTool;clangFrontend;clangDriver;clangSerialization;clangCodeGen;clangParse;clangSema;clangStaticAnalyzerFrontend;clangStaticAnalyzerCheckers;clangStaticAnalyzerCore;clangAnalysis;clangARCMigrate;clangEdit;clangAST;clangLex;clangBasic;LLVMAsmParser;LLVMInstrumentation;LLVMLinker;LLVMArchive;LLVMBitReader;LLVMDebugInfo;LLVMJIT;LLVMipo;LLVMVectorize;LLVMBitWriter;LLVMTableGen;LLVMHexagonCodeGen;LLVMHexagonDesc;LLVMHexagonInfo;LLVMHexagonAsmPrinter;LLVMPTXCodeGen;LLVMPTXDesc;LLVMPTXInfo;LLVMPTXAsmPrinter;LLVMMBlazeDisassembler;LLVMMBlazeAsmParser;LLVMMBlazeCodeGen;LLVMMBlazeDesc;LLVMMBlazeInfo;LLVMMBlazeAsmPrinter;LLVMCppBackendCodeGen;LLVMCppBackendInfo;LLVMMSP430CodeGen;LLVMMSP430Desc;LLVMMSP430Info;LLVMMSP430AsmPrinter;LLVMXCoreCodeGen;LLVMXCoreDesc;LLVMXCoreInfo;LLVMCellSPUCodeGen;LLVMCellSPUDesc;LLVMCellSPUInfo;LLVMMipsDisassembler;LLVMMipsAsmParser;LLVMMipsCodeGen;LLVMMipsDesc;LLVMMipsInfo;LLVMMipsAsmPrinter;LLVMARMDisassembler;LLVMARMAsmParser;LLVMARMCodeGen;LLVMARMDesc;LLVMARMInfo;LLVMARMAsmPrinter;LLVMPowerPCCodeGen;LLVMPowerPCDesc;LLVMPowerPCInfo;LLVMPowerPCAsmPrinter;LLVMSparcCodeGen;LLVMSparcDesc;LLVMSparcInfo;LLVMX86AsmParser;LLVMX86Disassembler;LLVMX86CodeGen;LLVMSelectionDAG;LLVMAsmPrinter;LLVMX86Desc;LLVMX86Info;LLVMX86AsmPrinter;LLVMX86Utils;gtest_main;gtest;LLVMMCDisassembler;LLVMMCParser;LLVMInterpreter;LLVMCodeGen;LLVMScalarOpts;LLVMInstCombine;LLVMTransformUtils;LLVMipa;LLVMAnalysis;LLVMMCJIT;LLVMRuntimeDyld;LLVMExecutionEngine;LLVMTarget;LLVMMC;LLVMObject;LLVMCore;LLVMSupport;dl;pthread")
......@@ -62,53 +62,10 @@
#include "clang/Frontend/DiagnosticOptions.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
using namespace clang;
// By implementing RecursiveASTVisitor, we can specify which AST nodes
// we're interested in by overriding relevant methods.
class MyASTVisitor : public RecursiveASTVisitor<MyASTVisitor> {
public:
bool VisitStmt(Stmt *s) {
// Only care about If statements.
if (isa<IfStmt>(s)) {
IfStmt *IfStatement = cast<IfStmt>(s);
Stmt *Then = IfStatement->getThen();
IfStatement->dump();
}
return true;
}
#include "MyASTConsumer.hpp"
bool VisitFunctionDecl(FunctionDecl *f) {
// Only function definitions (with bodies), not declarations.
if (f->hasBody()) {
}
return true;
}
};
using namespace clang;
// Implementation of the ASTConsumer interface for reading an AST produced
// by the Clang parser.
class MyASTConsumer : public ASTConsumer {
public:
MyASTConsumer() : Visitor(std::make_shared<MyASTVisitor>()) {}
// Override the method that gets called for each parsed top-level
// declaration.
virtual bool HandleTopLevelDecl(DeclGroupRef DR) {
for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b)
// Traverse the declaration using our AST visitor.
Visitor->TraverseDecl(*b);
return true;
}
private:
std::shared_ptr<MyASTVisitor> Visitor;
};
namespace scaffold {
/**
......
/*
* MyASTConsumer.cpp
*
* Created on: Apr 19, 2017
* Author: aqw
*/
#include "MyASTConsumer.hpp"
MyASTConsumer::MyASTConsumer() :
Visitor(std::make_shared<MyASTVisitor>()) {
}
bool MyASTConsumer::HandleTopLevelDecl(DeclGroupRef DR) {
for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) {
// Traverse the declaration using our AST visitor.
Visitor->TraverseDecl(*b);
}
return true;
}
/*
* MyASTConsumer.hpp
*
* Created on: Apr 19, 2017
* Author: aqw
*/
#ifndef QUANTUM_GATE_COMPILERS_IMPROVEDSCAFFOLD_MYASTCONSUMER_HPP_
#define QUANTUM_GATE_COMPILERS_IMPROVEDSCAFFOLD_MYASTCONSUMER_HPP_
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Parse/ParseAST.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Frontend/DiagnosticOptions.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
using namespace clang;
// By implementing RecursiveASTVisitor, we can specify which AST nodes
// we're interested in by overriding relevant methods.
class MyASTVisitor : public RecursiveASTVisitor<MyASTVisitor> {
public:
bool VisitStmt(Stmt *s) {
// Only care about If statements.
if (isa<IfStmt>(s)) {
IfStmt *IfStatement = cast<IfStmt>(s);
Stmt *Then = IfStatement->getThen();
IfStatement->dump();
}
return true;
}
bool VisitFunctionDecl(FunctionDecl *f) {
// Only function definitions (with bodies), not declarations.
if (f->hasBody()) {
}
return true;
}
};
class MyASTConsumer : public ASTConsumer {
public:
MyASTConsumer();
// Override the method that gets called for each parsed top-level
// declaration.
virtual bool HandleTopLevelDecl(DeclGroupRef DR);
virtual ~MyASTConsumer() {}
private:
std::shared_ptr<MyASTVisitor> Visitor;
};
#endif /* QUANTUM_GATE_COMPILERS_IMPROVEDSCAFFOLD_MYASTCONSUMER_HPP_ */
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