blob: 21fd7d26250f8640516e954225cd9426992fb5da [file] [log] [blame]
Sean Callananf18d91c2010-09-01 00:58:00 +00001//===-- IRDynamicChecks.cpp -------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Expression/IRDynamicChecks.h"
11#include "lldb/Expression/ClangUtilityFunction.h"
12
13#include "lldb/Core/Log.h"
14
15#include "llvm/Support/raw_ostream.h"
16#include "llvm/Function.h"
17#include "llvm/Module.h"
18#include "llvm/Value.h"
19
20using namespace llvm;
21using namespace lldb_private;
22
23static char ID;
24
25static const char valid_pointer_check_text[] =
26 "extern \"C\" void "
27 "___clang_valid_pointer_check (unsigned char *ptr)"
28 "{"
29 "unsigned char val = *ptr;"
30 "}";
31
32static const char valid_pointer_check_name[] =
33 "___clang_valid_pointer_check";
34
35DynamicCheckerFunctions::DynamicCheckerFunctions ()
36{
37 m_valid_pointer_check.reset(new ClangUtilityFunction(valid_pointer_check_text,
38 valid_pointer_check_name));
39}
40
41DynamicCheckerFunctions::~DynamicCheckerFunctions ()
42{
43}
44
45bool
46DynamicCheckerFunctions::Install(Stream &error_stream,
47 ExecutionContext &exe_ctx)
48{
49 if (!m_valid_pointer_check->Install(error_stream, exe_ctx))
50 return false;
51
52 return true;
53}
54
55IRDynamicChecks::IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
56 const char *func_name) :
57 ModulePass(&ID),
58 m_checker_functions(checker_functions),
59 m_func_name(func_name)
60{
61}
62
63/* A handy utility function used at several places in the code */
64
65static std::string
66PrintValue(llvm::Value *V, bool truncate = false)
67{
68 std::string s;
69 raw_string_ostream rso(s);
70 V->print(rso);
71 rso.flush();
72 if (truncate)
73 s.resize(s.length() - 1);
74 return s;
75}
76
77IRDynamicChecks::~IRDynamicChecks()
78{
79}
80
81bool
82IRDynamicChecks::runOnModule(llvm::Module &M)
83{
84 lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
85
86 llvm::Function* function = M.getFunction(StringRef(m_func_name.c_str()));
87
88 if (!function)
89 {
90 if (log)
91 log->Printf("Couldn't find %s() in the module", m_func_name.c_str());
92
93 return false;
94 }
95
96 llvm::Function::iterator bbi;
97
98 for (bbi = function->begin();
99 bbi != function->end();
100 ++bbi)
101 {
102 }
103
104 return true;
105}
106
107void
108IRDynamicChecks::assignPassManager(PMStack &PMS,
109 PassManagerType T)
110{
111}
112
113PassManagerType
114IRDynamicChecks::getPotentialPassManagerType() const
115{
116 return PMT_ModulePassManager;
117}