Skip to content

Commit d5395fb

Browse files
committed
Initial commit.
llvm-svn: 147756
1 parent 11faafe commit d5395fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1680
-0
lines changed

libclc/CREDITS.TXT

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
N: Peter Collingbourne
2+
E: peter@pcc.me.uk

libclc/LICENSE.TXT

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Copyright (c) 2011 by the contributors listed in CREDITS.TXT
2+
3+
All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal with
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
* Redistributions of source code must retain the above copyright notice,
13+
this list of conditions and the following disclaimers.
14+
15+
* Redistributions in binary form must reproduce the above copyright notice,
16+
this list of conditions and the following disclaimers in the
17+
documentation and/or other materials provided with the distribution.
18+
19+
* The names of the contributors may not be used to endorse or promote
20+
products derived from this Software without specific prior written
21+
permission.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
29+
SOFTWARE.

libclc/README.TXT

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
libclc
2+
------
3+
4+
libclc is an open source, BSD licensed implementation of the library
5+
requirements of the OpenCL C programming language, as specified by the
6+
OpenCL 1.1 Specification. The following sections of the specification
7+
impose library requirements:
8+
9+
* 6.1: Supported Data Types
10+
* 6.2.3: Explicit Conversions
11+
* 6.2.4.2: Reinterpreting Types Using as_type() and as_typen()
12+
* 6.9: Preprocessor Directives and Macros
13+
* 6.11: Built-in Functions
14+
* 9.3: Double Precision Floating-Point
15+
* 9.4: 64-bit Atomics
16+
* 9.5: Writing to 3D image memory objects
17+
* 9.6: Half Precision Floating-Point
18+
19+
libclc is intended to be used with the Clang compiler's OpenCL frontend.
20+
21+
libclc is designed to be portable and extensible. To this end, it provides
22+
generic implementations of most library requirements, allowing the target
23+
to override the generic implementation at the granularity of individual
24+
functions.
25+
26+
libclc currently only supports the PTX target, but support for more
27+
targets is welcome.
28+
29+
Compiling
30+
---------
31+
32+
./configure.py --with-llvm-config=/path/to/llvm-config && make
33+
34+
Website
35+
-------
36+
37+
http://www.pcc.me.uk/~peter/libclc/

libclc/build/metabuild.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import ninja_syntax
2+
import os
3+
4+
# Simple meta-build system.
5+
6+
class Make(object):
7+
def __init__(self):
8+
self.output = open(self.output_filename(), 'w')
9+
self.rules = {}
10+
self.rule_text = ''
11+
self.all_targets = []
12+
self.clean_files = []
13+
self.distclean_files = []
14+
self.output.write("""all::
15+
16+
ifndef VERBOSE
17+
Verb = @
18+
endif
19+
20+
""")
21+
22+
def output_filename(self):
23+
return 'Makefile'
24+
25+
def rule(self, name, command, description=None, depfile=None,
26+
generator=False):
27+
self.rules[name] = {'command': command, 'description': description,
28+
'depfile': depfile, 'generator': generator}
29+
30+
def build(self, output, rule, inputs=[], implicit=[], order_only=[]):
31+
inputs = self._as_list(inputs)
32+
implicit = self._as_list(implicit)
33+
order_only = self._as_list(order_only)
34+
35+
output_dir = os.path.dirname(output)
36+
if output_dir != '' and not os.path.isdir(output_dir):
37+
os.makedirs(output_dir)
38+
39+
dollar_in = ' '.join(inputs)
40+
subst = lambda text: text.replace('$in', dollar_in).replace('$out', output)
41+
42+
deps = ' '.join(inputs + implicit)
43+
if order_only:
44+
deps += ' | '
45+
deps += ' '.join(order_only)
46+
self.output.write('%s: %s\n' % (output, deps))
47+
48+
r = self.rules[rule]
49+
command = subst(r['command'])
50+
if r['description']:
51+
desc = subst(r['description'])
52+
self.output.write('\t@echo %s\n\t$(Verb) %s\n' % (desc, command))
53+
else:
54+
self.output.write('\t%s\n' % command)
55+
if r['depfile']:
56+
depfile = subst(r['depfile'])
57+
self.output.write('-include '+depfile+'\n')
58+
self.output.write('\n')
59+
60+
self.all_targets.append(output)
61+
if r['generator']:
62+
self.distclean_files.append(output)
63+
else:
64+
self.clean_files.append(output)
65+
66+
def _as_list(self, input):
67+
if isinstance(input, list):
68+
return input
69+
return [input]
70+
71+
def finish(self):
72+
self.output.write('all:: %s\n\n' % ' '.join(self.all_targets))
73+
self.output.write('clean: \n\trm -f %s\n\n' % ' '.join(self.clean_files))
74+
self.output.write('distclean: clean\n\trm -f %s\n' % ' '.join(self.distclean_files))
75+
76+
class Ninja(ninja_syntax.Writer):
77+
def __init__(self):
78+
ninja_syntax.Writer.__init__(self, open(self.output_filename(), 'w'))
79+
80+
def output_filename(self):
81+
return 'build.ninja'
82+
83+
def finish(self):
84+
pass
85+
86+
def from_name(name):
87+
if name == 'make':
88+
return Make()
89+
if name == 'ninja':
90+
return Ninja()
91+
raise LookupError, 'unknown generator: %s; supported generators are make and ninja' % name

libclc/build/ninja_syntax.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/python
2+
3+
"""Python module for generating .ninja files.
4+
5+
Note that this is emphatically not a required piece of Ninja; it's
6+
just a helpful utility for build-file-generation systems that already
7+
use Python.
8+
"""
9+
10+
import textwrap
11+
12+
class Writer(object):
13+
def __init__(self, output, width=78):
14+
self.output = output
15+
self.width = width
16+
17+
def newline(self):
18+
self.output.write('\n')
19+
20+
def comment(self, text):
21+
for line in textwrap.wrap(text, self.width - 2):
22+
self.output.write('# ' + line + '\n')
23+
24+
def variable(self, key, value, indent=0):
25+
if value is None:
26+
return
27+
if isinstance(value, list):
28+
value = ' '.join(value)
29+
self._line('%s = %s' % (key, value), indent)
30+
31+
def rule(self, name, command, description=None, depfile=None,
32+
generator=False):
33+
self._line('rule %s' % name)
34+
self.variable('command', command, indent=1)
35+
if description:
36+
self.variable('description', description, indent=1)
37+
if depfile:
38+
self.variable('depfile', depfile, indent=1)
39+
if generator:
40+
self.variable('generator', '1', indent=1)
41+
42+
def build(self, outputs, rule, inputs=None, implicit=None, order_only=None,
43+
variables=None):
44+
outputs = self._as_list(outputs)
45+
all_inputs = self._as_list(inputs)[:]
46+
47+
if implicit:
48+
all_inputs.append('|')
49+
all_inputs.extend(self._as_list(implicit))
50+
if order_only:
51+
all_inputs.append('||')
52+
all_inputs.extend(self._as_list(order_only))
53+
54+
self._line('build %s: %s %s' % (' '.join(outputs),
55+
rule,
56+
' '.join(all_inputs)))
57+
58+
if variables:
59+
for key, val in variables:
60+
self.variable(key, val, indent=1)
61+
62+
return outputs
63+
64+
def include(self, path):
65+
self._line('include %s' % path)
66+
67+
def subninja(self, path):
68+
self._line('subninja %s' % path)
69+
70+
def default(self, paths):
71+
self._line('default %s' % ' '.join(self._as_list(paths)))
72+
73+
def _line(self, text, indent=0):
74+
"""Write 'text' word-wrapped at self.width characters."""
75+
leading_space = ' ' * indent
76+
while len(text) > self.width:
77+
# The text is too wide; wrap if possible.
78+
79+
# Find the rightmost space that would obey our width constraint.
80+
available_space = self.width - len(leading_space) - len(' $')
81+
space = text.rfind(' ', 0, available_space)
82+
if space < 0:
83+
# No such space; just use the first space we can find.
84+
space = text.find(' ', available_space)
85+
if space < 0:
86+
# Give up on breaking.
87+
break
88+
89+
self.output.write(leading_space + text[0:space] + ' $\n')
90+
text = text[space+1:]
91+
92+
# Subsequent lines are continuations, so indent them.
93+
leading_space = ' ' * (indent+2)
94+
95+
self.output.write(leading_space + text + '\n')
96+
97+
def _as_list(self, input):
98+
if input is None:
99+
return []
100+
if isinstance(input, list):
101+
return input
102+
return [input]
103+
104+
105+
def escape(string):
106+
"""Escape a string such that it can be embedded into a Ninja file without
107+
further interpretation."""
108+
assert '\n' not in string, 'Ninja syntax does not allow newlines'
109+
# We only have one special metacharacter: '$'.
110+
return string.replace('$', '$$')

libclc/compile-test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
clang -ccc-host-triple ptx32--nvidiacl -Iptx-nvidiacl/include -Igeneric/include -Xclang -mlink-bitcode-file -Xclang ptx32--nvidiacl/lib/builtins.bc -include clc/clc.h -Dcl_clang_storage_class_specifiers "$@"

0 commit comments

Comments
 (0)