Commit d95030ec authored by Kevin Modzelewski's avatar Kevin Modzelewski

Starting to work on the refcount checker again

parent 18d1bb83
......@@ -51,6 +51,7 @@ ETAGS := ctags-exuberant -e
NINJA := ninja
CMAKE_DIR_DBG := $(BUILD_DIR)/Debug
CMAKE_DIR_DBG_TO_SRC := ../.. # Relative path from $(CAMKE_DIR_DBG) to $(SRC_DIR). Not sure how to calculate this automatically.
CMAKE_DIR_RELEASE := $(BUILD_DIR)/Release
CMAKE_DIR_GCC := $(BUILD_DIR)/Debug-gcc
CMAKE_DIR_RELEASE_GCC := $(BUILD_DIR)/Release-gcc
......@@ -1074,8 +1075,22 @@ lint_%: %.cpp plugins/clang_linter.so
$(ECHO) Linting $<
$(VERB) $(CLANG_CXX) -Xclang -load -Xclang plugins/clang_linter.so -Xclang -plugin -Xclang pyston-linter src/runtime/float.cpp $< -c -Isrc/ -Ifrom_cpython/Include -Ibuild/Debug/from_cpython/Include $(shell $(LLVM_BIN_DBG)/llvm-config --cxxflags) $(COMMON_CXXFLAGS) -no-pedantic -Wno-unused-variable -DNVALGRIND -Wno-invalid-offsetof -Wno-mismatched-tags -Wno-unused-function -Wno-unused-private-field -Wno-sign-compare -DLLVMREV=$(LLVM_REVISION) -Ibuild_deps/lz4/lib -DBINARY_SUFFIX= -DBINARY_STRIPPED_SUFFIX=_stripped -Ibuild_deps/libpypa/src/ -Wno-covered-switch-default -Ibuild/Debug/libunwind/include -Wno-extern-c-compat -Wno-unused-local-typedef -Wno-inconsistent-missing-override
refcount_checker:
$(NINJA) -C $(CMAKE_DIR_DBG) refcount_checker
REFCOUNT_CHECKER_BUILD_PATH := $(CMAKE_DIR_DBG)/plugins/refcount_checker/llvm/bin/refcount_checker
REFCOUNT_CHECKER_RUN_PATH := $(CMAKE_DIR_DBG)/llvm/bin/refcount_checker
$(REFCOUNT_CHECKER_BUILD_PATH): plugins/refcount_checker/refcount_checker.cpp
$(NINJA) -C $(CMAKE_DIR_DBG) refcount_checker $(NINJAFLAGS)
cp $(REFCOUNT_CHECKER_BUILD_PATH) $(REFCOUNT_CHECKER_RUN_PATH)
.PHONY: refcount_checker
refcount_checker: $(REFCOUNT_CHECKER_RUN_PATH)
.PHONY: refcheck_%
refcheck_%: %.cpp refcount_checker
cd $(CMAKE_DIR_DBG); $(REFCOUNT_CHECKER_RUN_PATH) ../../$<
.PHONY: dbg_refcheck_%
dbg_refcheck_%: %.cpp refcount_checker
cd $(CMAKE_DIR_DBG); $(GDB) --args $(REFCOUNT_CHECKER_RUN_PATH) ../../$<
.PHONY: clang_lint
clang_lint: $(foreach FN,$(MAIN_SRCS),$(dir $(FN))lint_$(notdir $(FN:.cpp=)))
......
......@@ -5,6 +5,9 @@ set(LLVM_LIBRARY_OUTPUT_INTDIR llvm/lib${LLVM_LIBDIR_SUFFIX})
# Pyston addition:
include_directories("${DEPS_DIR}/llvm-trunk/tools/clang/include")
include_directories("${CMAKE_BINARY_DIR}/llvm/tools/clang/include")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(LIBUNWIND_DEBUG_CFLAGS "CFLAGS=-O0 -g")
endif()
# From llvm-trunk/tools/clang/tools/clang-check/CMakeLists.txt
set(LLVM_LINK_COMPONENTS
......
// Declares clang::SyntaxOnlyAction.
// Copyright (c) 2014-2016 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Includes code from the following examples/tutorials:
// - http://clang.llvm.org/docs/LibASTMatchersTutorial.html
// - http://clang.llvm.org/docs/RAVFrontendAction.html
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
// Declares llvm::cl::extrahelp.
#include "llvm/Support/CommandLine.h"
using namespace clang;
using namespace clang::tooling;
using namespace llvm;
......@@ -20,9 +40,46 @@ static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
// A help message for this specific tool can be added afterwards.
static cl::extrahelp MoreHelp("\nMore help text...");
class MyVisitor : public RecursiveASTVisitor<MyVisitor> {
private:
ASTContext *Context;
public:
explicit MyVisitor(ASTContext *Context) : Context(Context) {
}
virtual ~MyVisitor() {
}
virtual bool VisitFunctionDecl(FunctionDecl* func) {
errs() << func->getNameInfo().getName() << '\n';
return true;
}
};
class MyASTConsumer : public ASTConsumer {
private:
MyVisitor visitor;
public:
explicit MyASTConsumer(ASTContext *Context) : visitor(Context) {
}
virtual void HandleTranslationUnit(ASTContext &Context) {
visitor.TraverseDecl(Context.getTranslationUnitDecl());
}
};
class MyFrontendAction : public ASTFrontendAction {
public:
virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef fname) {
return std::unique_ptr<ASTConsumer>(new MyASTConsumer(&CI.getASTContext()));
}
};
int main(int argc, const char **argv) {
CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
return Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
return Tool.run(newFrontendActionFactory<MyFrontendAction>().get());
}
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