class PlatformInfo(object):
def __init__(self, json):
self._platform = json['platform']
- self._intrinsic_prefix = json['intrinsic_prefix']
- def intrinsic_prefix(self):
- return self._intrinsic_prefix
+ def platform_prefix(self):
+ return self._platform
class IntrinsicSet(object):
def __init__(self, platform, json):
self._intrinsics = json['intrinsics']
self._widths = json['width_info']
self._platform = platform
+ self._intrinsic_prefix = json['intrinsic_prefix']
def intrinsics(self):
for raw in self._intrinsics:
def platform(self):
return self._platform
+ def intrinsic_prefix(self):
+ return self._intrinsic_prefix
+
def llvm_prefix(self):
return self._llvm_prefix
*self._args,
width = self._width)
+ def platform_prefix(self):
+ return self._platform.platform().platform_prefix()
+
+ def intrinsic_set_name(self):
+ return self._platform.intrinsic_prefix()
+
def intrinsic_name(self):
- return self._platform.platform().intrinsic_prefix() + self.intrinsic_suffix()
+ return self._platform.intrinsic_prefix() + self.intrinsic_suffix()
def compiler_args(self):
return ', '.join(arg.compiler_ctor_ref() for arg in self._args_raw)
formatter_class = argparse.RawDescriptionHelpFormatter,
description = 'Render an intrinsic definition JSON to various formats.',
epilog = textwrap.dedent('''\
+ Quick How-To:
+
+ There are two operating modes: single file and multiple files.
+
+ For example, ARM is specified as a single file. To generate the
+ compiler-definitions for ARM just pass the script the "arm.json" file:
+
+ python generator.py --format compiler-defs arm.json
+
+ The X86 architecture is specified as multiple files (for the different
+ instruction sets that x86 supports). To generate the compiler
+ definitions one needs to pass the script a "platform information file"
+ (with the -i flag) next to the files of the different intruction sets.
+ For example, to generate the X86 compiler-definitions for SSE4.2, just:
+
+ python generator.py --format compiler-defs -i x86/info.json sse42.json
+
+ And to generate the compiler-definitions for SSE4.1 and SSE4.2, just:
+
+ python generator.py --format compiler-defs -i x86/info.json sse41.json sse42.json
+
An intrinsic definition consists of a map with fields:
- intrinsic: pattern for the name(s) of the vendor's C intrinsic(s)
- llvm: pattern for the name(s) of the internal llvm intrinsic(s)
return 'extern "platform-intrinsic" {'
def render(self, mono):
- return ' fn {}{};'.format(mono.intrinsic_name(),
- mono.intrinsic_signature())
+ return ' fn {}{}{};'.format(mono.platform_prefix(),
+ mono.intrinsic_name(),
+ mono.intrinsic_signature())
def close(self):
return '}'
#[inline(never)]
pub fn find(name: &str) -> Option<Intrinsic> {{
if !name.starts_with("{0}") {{ return None }}
- Some(match &name["{0}".len()..] {{'''.format(platform.intrinsic_prefix())
+ Some(match &name["{0}".len()..] {{'''.format(platform.platform_prefix())
def render(self, mono):
return '''\
inputs: {{ static INPUTS: [&'static Type; {}] = [{}]; &INPUTS }},
output: {},
definition: Named("{}")
- }},'''.format(mono.intrinsic_suffix(),
+ }},'''.format(mono.intrinsic_set_name() + mono.intrinsic_suffix(),
len(mono._args_raw),
mono.compiler_args(),
mono.compiler_ret(),