gallivm: Ensure PIPE_OS_xxx are defined.
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_misc.cpp
1 /**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 **************************************************************************/
27
28
29 #ifndef __STDC_LIMIT_MACROS
30 #define __STDC_LIMIT_MACROS
31 #endif
32
33 #ifndef __STDC_CONSTANT_MACROS
34 #define __STDC_CONSTANT_MACROS
35 #endif
36
37 #include "llvm-c/Core.h"
38
39 #include "pipe/p_config.h"
40 #include "util/u_debug.h"
41
42
43 #if (defined(PIPE_OS_WINDOWS) && !defined(PIPE_CC_MSVC)) || defined(PIPE_OS_EMBDDED)
44
45 #include "llvm/Support/raw_ostream.h"
46
47 class raw_debug_ostream :
48 public llvm::raw_ostream
49 {
50 uint64_t pos;
51
52 void write_impl(const char *Ptr, size_t Size);
53 uint64_t current_pos() { return pos; }
54 uint64_t current_pos() const { return pos; }
55
56 #if HAVE_LLVM >= 0x207
57 uint64_t preferred_buffer_size() { return 512; }
58 #else
59 size_t preferred_buffer_size() { return 512; }
60 #endif
61 };
62
63
64 void
65 raw_debug_ostream::write_impl(const char *Ptr, size_t Size)
66 {
67 if (Size > 0) {
68 char *lastPtr = (char *)&Ptr[Size];
69 char last = *lastPtr;
70 *lastPtr = 0;
71 _debug_printf("%*s", Size, Ptr);
72 *lastPtr = last;
73 pos += Size;
74 }
75 }
76
77
78 /**
79 * Same as LLVMDumpValue, but through our debugging channels.
80 */
81 extern "C" void
82 lp_debug_dump_value(LLVMValueRef value)
83 {
84 raw_debug_ostream os;
85 llvm::unwrap(value)->print(os);
86 os.flush();
87 }
88
89
90 #else
91
92
93 extern "C" void
94 lp_debug_dump_value(LLVMValueRef value)
95 {
96 LLVMDumpValue(value);
97 }
98
99
100 #endif