Skip to content

Commit 62e346a

Browse files
committed
Support void in platform intrinsic generator.
1 parent add0430 commit 62e346a

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

src/etc/platform-intrinsics/generator.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import itertools
1818

1919
SPEC = re.compile(
20-
r'^(?:(?P<id>[iusfIUSF])(?:\((?P<start>\d+)-(?P<end>\d+)\)|'
20+
r'^(?:(?P<void>V)|(?P<id>[iusfIUSF])(?:\((?P<start>\d+)-(?P<end>\d+)\)|'
2121
r'(?P<width>\d+)(:?/(?P<llvm_width>\d+))?)'
2222
r'|(?P<reference>\d+)(?P<modifiers>[vShdnwusDMC]*)(?P<force_width>x\d+)?)'
2323
r'(?:(?P<pointer>Pm|Pc)(?P<llvm_pointer>/.*)?)?$'
@@ -97,6 +97,19 @@ def bitwidth(self):
9797
def modify(self, spec, width):
9898
raise NotImplementedError()
9999

100+
class Void(Type):
101+
def __init__(self):
102+
Type.__init__(self, 0)
103+
104+
def compiler_ctor(self):
105+
return 'void()'
106+
107+
def rust_name(self):
108+
return '()'
109+
110+
def type_info(self, platform_info):
111+
return None
112+
100113
class Number(Type):
101114
def __init__(self, bitwidth):
102115
Type.__init__(self, bitwidth)
@@ -289,7 +302,10 @@ def enumerate(self, width, previous):
289302
id = match.group('id')
290303
reference = match.group('reference')
291304

292-
if id is not None:
305+
if match.group('void') is not None:
306+
assert spec == 'V'
307+
yield Void()
308+
elif id is not None:
293309
is_vector = id.islower()
294310
type_ctors = TYPE_ID_LOOKUP[id.lower()]
295311

@@ -436,11 +452,15 @@ def parse_args():
436452
## Type specifier grammar
437453
438454
```
439-
type := ( vector | scalar | aggregate | reference ) pointer?
455+
type := core_type pointer?
456+
457+
core_type := void | vector | scalar | aggregate | reference
440458
441459
pointer := 'Pm' llvm_pointer? | 'Pc' llvm_pointer?
442460
llvm_pointer := '/' type
443461
462+
void := 'V'
463+
444464
vector := vector_elem width |
445465
vector_elem := 'i' | 'u' | 's' | 'f'
446466
@@ -472,6 +492,11 @@ def parse_args():
472492
in Rust, but is `i8*` in LLVM. (This defaults to the main
473493
type).
474494
495+
## Void
496+
497+
The `V` type corresponds to `void` in LLVM (`()` in
498+
Rust). It's likely to only work in return position.
499+
475500
## Vectors
476501
477502
The vector grammar is a pattern describing many possibilities
@@ -586,7 +611,7 @@ def open(self, platform):
586611
587612
#![allow(unused_imports)]
588613
589-
use {{Intrinsic, i, i_, u, u_, f, v, agg, p}};
614+
use {{Intrinsic, i, i_, u, u_, f, v, agg, p, void}};
590615
use IntrinsicDef::Named;
591616
use rustc::middle::ty;
592617

src/librustc_platform_intrinsics/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub struct Intrinsic {
3030

3131
#[derive(Clone, Hash, Eq, PartialEq)]
3232
pub enum Type {
33+
Void,
3334
Integer(/* signed */ bool, u8, /* llvm width */ u8),
3435
Float(u8),
3536
Pointer(Box<Type>, Option<Box<Type>>, /* const */ bool),
@@ -54,6 +55,9 @@ fn agg(flatten: bool, types: Vec<Type>) -> Type {
5455
fn p(const_: bool, elem: Type, llvm_elem: Option<Type>) -> Type {
5556
Type::Pointer(Box::new(elem), llvm_elem.map(Box::new), const_)
5657
}
58+
fn void() -> Type {
59+
Type::Void
60+
}
5761

5862
mod x86;
5963
mod arm;

src/librustc_platform_intrinsics/x86.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#![allow(unused_imports)]
1515

16-
use {Intrinsic, i, i_, u, u_, f, v, agg, p};
16+
use {Intrinsic, i, i_, u, u_, f, v, agg, p, void};
1717
use IntrinsicDef::Named;
1818
use rustc::middle::ty;
1919

src/librustc_trans/trans/intrinsic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
936936
any_changes_needed: &mut bool) -> Vec<Type> {
937937
use intrinsics::Type::*;
938938
match *t {
939+
Void => vec![Type::void(ccx)],
939940
Integer(_signed, width, llvm_width) => {
940941
*any_changes_needed |= width != llvm_width;
941942
vec![Type::ix(ccx, llvm_width as u64)]

src/librustc_typeck/check/intrinsic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ fn match_intrinsic_type_to_type<'tcx, 'a>(
464464
};
465465

466466
match *expected {
467+
Void => match t.sty {
468+
ty::TyTuple(ref v) if v.is_empty() => {},
469+
_ => simple_error(&format!("`{}`", t), "()"),
470+
},
467471
// (The width we pass to LLVM doesn't concern the type checker.)
468472
Integer(signed, bits, _llvm_width) => match (signed, bits, &t.sty) {
469473
(true, 8, &ty::TyInt(hir::IntTy::TyI8)) |

0 commit comments

Comments
 (0)