From 6a61bba39e1b2586d7a8c84cae85dc4587d6d606 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 27 Feb 2020 16:45:18 -0500 Subject: [PATCH] Allow modules to have names of arbitrary bytes (#1410) This is useful for me because I name the module after the file, which comes from the filesystem and may not be valid UTF8. This change is backwards-compatible. --- cranelift/object/src/backend.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cranelift/object/src/backend.rs b/cranelift/object/src/backend.rs index 044fdca815..dae26ea230 100644 --- a/cranelift/object/src/backend.rs +++ b/cranelift/object/src/backend.rs @@ -32,7 +32,7 @@ pub enum ObjectTrapCollection { /// A builder for `ObjectBackend`. pub struct ObjectBuilder { isa: Box, - name: String, + name: Vec, collect_traps: ObjectTrapCollection, libcall_names: Box String>, function_alignment: u64, @@ -49,15 +49,15 @@ impl ObjectBuilder { /// enum to symbols. LibCalls are inserted in the IR as part of the legalization for certain /// floating point instructions, and for stack probes. If you don't know what to use for this /// argument, use `cranelift_module::default_libcall_names()`. - pub fn new( + pub fn new>>( isa: Box, - name: String, + name: V, collect_traps: ObjectTrapCollection, libcall_names: Box String>, ) -> Self { Self { isa, - name, + name: name.into(), collect_traps, libcall_names, function_alignment: 1, @@ -104,7 +104,7 @@ impl Backend for ObjectBackend { fn new(builder: ObjectBuilder) -> Self { let triple = builder.isa.triple(); let mut object = Object::new(triple.binary_format, triple.architecture); - object.add_file_symbol(builder.name.as_bytes().to_vec()); + object.add_file_symbol(builder.name); Self { isa: builder.isa, object,