forked from M-Labs/artiq
1
0
Fork 0

compiler: swap the order of ptr/len fields in lists.

This is to make them match the Rust slices.
Once the cslice crate becomes #![no_std] we'll also use its (tidier)
conversion functions.
This commit is contained in:
whitequark 2017-01-31 21:53:37 +00:00
parent ab71c9a0ba
commit ee1b2fa3ea
3 changed files with 13 additions and 13 deletions

View File

@ -220,7 +220,7 @@ class LLVMIRGenerator:
return llptr return llptr
elif builtins.is_listish(typ): elif builtins.is_listish(typ):
lleltty = self.llty_of_type(builtins.get_iterable_elt(typ)) lleltty = self.llty_of_type(builtins.get_iterable_elt(typ))
return ll.LiteralStructType([lli32, lleltty.as_pointer()]) return ll.LiteralStructType([lleltty.as_pointer(), lli32])
elif builtins.is_range(typ): elif builtins.is_range(typ):
lleltty = self.llty_of_type(builtins.get_iterable_elt(typ)) lleltty = self.llty_of_type(builtins.get_iterable_elt(typ))
return ll.LiteralStructType([lleltty, lleltty, lleltty]) return ll.LiteralStructType([lleltty, lleltty, lleltty])
@ -621,11 +621,11 @@ class LLVMIRGenerator:
return llvalue return llvalue
elif builtins.is_listish(insn.type): elif builtins.is_listish(insn.type):
llsize = self.map(insn.operands[0]) llsize = self.map(insn.operands[0])
lleltty = self.llty_of_type(builtins.get_iterable_elt(insn.type))
llalloc = self.llbuilder.alloca(lleltty, size=llsize)
llvalue = ll.Constant(self.llty_of_type(insn.type), ll.Undefined) llvalue = ll.Constant(self.llty_of_type(insn.type), ll.Undefined)
llvalue = self.llbuilder.insert_value(llvalue, llsize, 0) llvalue = self.llbuilder.insert_value(llvalue, llalloc, 0, name=insn.name)
llalloc = self.llbuilder.alloca(self.llty_of_type(builtins.get_iterable_elt(insn.type)), llvalue = self.llbuilder.insert_value(llvalue, llsize, 1)
size=llsize)
llvalue = self.llbuilder.insert_value(llvalue, llalloc, 1, name=insn.name)
return llvalue return llvalue
elif not builtins.is_allocated(insn.type) or ir.is_keyword(insn.type): elif not builtins.is_allocated(insn.type) or ir.is_keyword(insn.type):
llvalue = ll.Constant(self.llty_of_type(insn.type), ll.Undefined) llvalue = ll.Constant(self.llty_of_type(insn.type), ll.Undefined)
@ -833,7 +833,7 @@ class LLVMIRGenerator:
llelt = self.llbuilder.gep(lllst, [llidx], inbounds=True) llelt = self.llbuilder.gep(lllst, [llidx], inbounds=True)
llvalue = self.llbuilder.load(llelt) llvalue = self.llbuilder.load(llelt)
else: else:
llelts = self.llbuilder.extract_value(lllst, 1) llelts = self.llbuilder.extract_value(lllst, 0)
llelt = self.llbuilder.gep(llelts, [llidx], inbounds=True) llelt = self.llbuilder.gep(llelts, [llidx], inbounds=True)
llvalue = self.llbuilder.load(llelt) llvalue = self.llbuilder.load(llelt)
if isinstance(llvalue.type, ll.PointerType): if isinstance(llvalue.type, ll.PointerType):
@ -846,7 +846,7 @@ class LLVMIRGenerator:
if builtins.is_str(lst.type): if builtins.is_str(lst.type):
llelt = self.llbuilder.gep(lllst, [llidx], inbounds=True) llelt = self.llbuilder.gep(lllst, [llidx], inbounds=True)
else: else:
llelts = self.llbuilder.extract_value(lllst, 1) llelts = self.llbuilder.extract_value(lllst, 0)
llelt = self.llbuilder.gep(llelts, [llidx], inbounds=True) llelt = self.llbuilder.gep(llelts, [llidx], inbounds=True)
return self.llbuilder.store(self.map(insn.value()), llelt) return self.llbuilder.store(self.map(insn.value()), llelt)
@ -1069,7 +1069,7 @@ class LLVMIRGenerator:
if builtins.is_str(collection.type): if builtins.is_str(collection.type):
return self.llbuilder.call(self.llbuiltin("strlen"), [self.map(collection)]) return self.llbuilder.call(self.llbuiltin("strlen"), [self.map(collection)])
else: else:
return self.llbuilder.extract_value(self.map(collection), 0) return self.llbuilder.extract_value(self.map(collection), 1)
elif insn.op in ("printf", "rtio_log"): elif insn.op in ("printf", "rtio_log"):
# We only get integers, floats, pointers and strings here. # We only get integers, floats, pointers and strings here.
llargs = map(self.map, insn.operands) llargs = map(self.map, insn.operands)
@ -1463,7 +1463,7 @@ class LLVMIRGenerator:
llglobal.linkage = "private" llglobal.linkage = "private"
lleltsptr = llglobal.bitcast(lleltsary.type.element.as_pointer()) lleltsptr = llglobal.bitcast(lleltsary.type.element.as_pointer())
llconst = ll.Constant(llty, [ll.Constant(lli32, len(llelts)), lleltsptr]) llconst = ll.Constant(llty, [lleltsptr, ll.Constant(lli32, len(llelts))])
return llconst return llconst
elif types.is_rpc(typ) or types.is_c_function(typ): elif types.is_rpc(typ) or types.is_c_function(typ):
# RPC and C functions have no runtime representation. # RPC and C functions have no runtime representation.

View File

@ -101,8 +101,8 @@ pub extern fn panic_fmt(args: core::fmt::Arguments, file: &'static str, line: u3
#[repr(C)] #[repr(C)]
pub struct ArtiqList<T> { pub struct ArtiqList<T> {
len: usize, ptr: *const T,
ptr: *const T len: usize
} }
impl<T> ArtiqList<T> { impl<T> ArtiqList<T> {

View File

@ -47,7 +47,7 @@ unsafe fn recv_value(reader: &mut Read, tag: Tag, data: &mut *mut (),
Ok(()) Ok(())
} }
Tag::List(it) | Tag::Array(it) => { Tag::List(it) | Tag::Array(it) => {
struct List { length: u32, elements: *mut () }; struct List { elements: *mut (), length: u32 };
consume_value!(List, |ptr| { consume_value!(List, |ptr| {
(*ptr).length = try!(read_u32(reader)); (*ptr).length = try!(read_u32(reader));
@ -126,7 +126,7 @@ unsafe fn send_value(writer: &mut Write, tag: Tag, data: &mut *const ()) -> io::
Ok(()) Ok(())
} }
Tag::List(it) | Tag::Array(it) => { Tag::List(it) | Tag::Array(it) => {
struct List { length: u32, elements: *const () }; struct List { elements: *const (), length: u32 };
consume_value!(List, |ptr| { consume_value!(List, |ptr| {
try!(write_u32(writer, (*ptr).length)); try!(write_u32(writer, (*ptr).length));
let tag = it.clone().next().expect("truncated tag"); let tag = it.clone().next().expect("truncated tag");