]> git.lizzy.rs Git - rust.git/commitdiff
Support void in platform intrinsic generator.
authorHuon Wilson <dbau.pp+github@gmail.com>
Wed, 2 Sep 2015 23:55:28 +0000 (16:55 -0700)
committerHuon Wilson <dbau.pp+github@gmail.com>
Fri, 4 Sep 2015 16:14:13 +0000 (09:14 -0700)
src/etc/platform-intrinsics/generator.py
src/librustc_platform_intrinsics/lib.rs
src/librustc_platform_intrinsics/x86.rs
src/librustc_trans/trans/intrinsic.rs
src/librustc_typeck/check/intrinsic.rs

index 2102bd9c488ba3fe8b69d0eed8a4f6212a043026..b62c35246cab8d661abbc642ce477944ef6d8270 100644 (file)
@@ -17,7 +17,7 @@ import textwrap
 import itertools
 
 SPEC = re.compile(
-    r'^(?:(?P<id>[iusfIUSF])(?:\((?P<start>\d+)-(?P<end>\d+)\)|'
+    r'^(?:(?P<void>V)|(?P<id>[iusfIUSF])(?:\((?P<start>\d+)-(?P<end>\d+)\)|'
     r'(?P<width>\d+)(:?/(?P<llvm_width>\d+))?)'
     r'|(?P<reference>\d+)(?P<modifiers>[vShdnwusDMC]*)(?P<force_width>x\d+)?)'
     r'(?:(?P<pointer>Pm|Pc)(?P<llvm_pointer>/.*)?)?$'
@@ -97,6 +97,19 @@ class Type(object):
     def modify(self, spec, width):
         raise NotImplementedError()
 
+class Void(Type):
+    def __init__(self):
+        Type.__init__(self, 0)
+
+    def compiler_ctor(self):
+        return 'void()'
+
+    def rust_name(self):
+        return '()'
+
+    def type_info(self, platform_info):
+        return None
+
 class Number(Type):
     def __init__(self, bitwidth):
         Type.__init__(self, bitwidth)
@@ -289,7 +302,10 @@ class TypeSpec(object):
                 id = match.group('id')
                 reference = match.group('reference')
 
-                if id is not None:
+                if match.group('void') is not None:
+                    assert spec == 'V'
+                    yield Void()
+                elif id is not None:
                     is_vector = id.islower()
                     type_ctors = TYPE_ID_LOOKUP[id.lower()]
 
@@ -436,11 +452,15 @@ def parse_args():
         ## Type specifier grammar
 
         ```
-        type := ( vector | scalar | aggregate | reference ) pointer?
+        type := core_type pointer?
+
+        core_type := void | vector | scalar | aggregate | reference
 
         pointer := 'Pm' llvm_pointer? | 'Pc' llvm_pointer?
         llvm_pointer := '/' type
 
+        void := 'V'
+
         vector := vector_elem width |
         vector_elem := 'i' | 'u' | 's' | 'f'
 
@@ -472,6 +492,11 @@ def parse_args():
         in Rust, but is `i8*` in LLVM. (This defaults to the main
         type).
 
+        ## Void
+
+        The `V` type corresponds to `void` in LLVM (`()` in
+        Rust). It's likely to only work in return position.
+
         ## Vectors
 
         The vector grammar is a pattern describing many possibilities
@@ -586,7 +611,7 @@ class CompilerDefs(object):
 
 #![allow(unused_imports)]
 
-use {{Intrinsic, i, i_, u, u_, f, v, agg, p}};
+use {{Intrinsic, i, i_, u, u_, f, v, agg, p, void}};
 use IntrinsicDef::Named;
 use rustc::middle::ty;
 
index 8c8beb031ebad111b2756589b2557d5d71d5fff5..95da12a237829dd06f41152be2efafb9c9f8be86 100755 (executable)
@@ -30,6 +30,7 @@ pub struct Intrinsic {
 
 #[derive(Clone, Hash, Eq, PartialEq)]
 pub enum Type {
+    Void,
     Integer(/* signed */ bool, u8, /* llvm width */ u8),
     Float(u8),
     Pointer(Box<Type>, Option<Box<Type>>, /* const */ bool),
@@ -54,6 +55,9 @@ fn agg(flatten: bool, types: Vec<Type>) -> Type {
 fn p(const_: bool, elem: Type, llvm_elem: Option<Type>) -> Type {
     Type::Pointer(Box::new(elem), llvm_elem.map(Box::new), const_)
 }
+fn void() -> Type {
+    Type::Void
+}
 
 mod x86;
 mod arm;
index 661603866ae02b338bf0be7e59f4e21e427d9da1..26421cb3e80ee001c23e8178234555d8cae9ac31 100644 (file)
@@ -13,7 +13,7 @@
 
 #![allow(unused_imports)]
 
-use {Intrinsic, i, i_, u, u_, f, v, agg, p};
+use {Intrinsic, i, i_, u, u_, f, v, agg, p, void};
 use IntrinsicDef::Named;
 use rustc::middle::ty;
 
index c2dee20b3bb9367d270259355206b404ce8be449..a6816a99d28aea410810097b3660cec3bbdb2032 100644 (file)
@@ -936,6 +936,7 @@ fn ty_to_type(ccx: &CrateContext, t: &intrinsics::Type,
                           any_changes_needed: &mut bool) -> Vec<Type> {
                 use intrinsics::Type::*;
                 match *t {
+                    Void => vec![Type::void(ccx)],
                     Integer(_signed, width, llvm_width) => {
                         *any_changes_needed |= width != llvm_width;
                         vec![Type::ix(ccx, llvm_width as u64)]
index 54f6ec0f0eda4614e945871978d0bc9992cef1e9..4501d1c618a72f7e1afa39485f1bb7663cd78002 100644 (file)
@@ -464,6 +464,10 @@ fn match_intrinsic_type_to_type<'tcx, 'a>(
     };
 
     match *expected {
+        Void => match t.sty {
+            ty::TyTuple(ref v) if v.is_empty() => {},
+            _ => simple_error(&format!("`{}`", t), "()"),
+        },
         // (The width we pass to LLVM doesn't concern the type checker.)
         Integer(signed, bits, _llvm_width) => match (signed, bits, &t.sty) {
             (true,  8,  &ty::TyInt(hir::IntTy::TyI8)) |