Skip to content

Commit c1186f2

Browse files
authored
cranelift-isle: no_std support (#12236)
* cranelift-isle: no_std support * add extern crate alloc, and remove unnessesary imports * allow unused imports * remove extern crate alloc * add an import of core::marker::PhantomData * add extern crate alloc and core
1 parent 63330f1 commit c1186f2

File tree

8 files changed

+30
-9
lines changed

8 files changed

+30
-9
lines changed

cranelift/isle/isle/isle_examples/link/borrows_main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
extern crate alloc;
2+
extern crate core;
3+
14
mod borrows;
25

36
#[derive(Clone)]

cranelift/isle/isle/isle_examples/link/iflets_main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
extern crate alloc;
2+
extern crate core;
3+
14
mod iflets;
25

36
struct Context;

cranelift/isle/isle/isle_examples/link/multi_constructor_main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
extern crate alloc;
2+
extern crate core;
3+
14
mod multi_constructor;
25
use multi_constructor::{ContextIter, IntoContextIter};
36

cranelift/isle/isle/isle_examples/link/multi_extractor_main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
extern crate alloc;
2+
extern crate core;
3+
14
mod multi_extractor;
25

36
use multi_extractor::{ContextIter, IntoContextIter};

cranelift/isle/isle/isle_examples/link/test_main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
extern crate alloc;
2+
extern crate core;
3+
14
mod test;
25

36
struct Context;

cranelift/isle/isle/isle_examples/run/iconst_main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
extern crate alloc;
2+
extern crate core;
3+
14
mod iconst;
25

36
struct Context;

cranelift/isle/isle/isle_examples/run/let_shadowing_main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
extern crate alloc;
2+
extern crate core;
3+
14
mod let_shadowing;
25

36
struct Context;

cranelift/isle/isle/src/codegen.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a> Codegen<'a> {
166166
}
167167

168168
writeln!(code, "\nuse super::*; // Pulls in all external types.").unwrap();
169-
writeln!(code, "use std::marker::PhantomData;").unwrap();
169+
writeln!(code, "use core::marker::PhantomData;").unwrap();
170170
}
171171

172172
fn generate_trait_sig(&self, code: &mut String, indent: &str, sig: &ExternalSig) {
@@ -271,38 +271,38 @@ pub trait Length {{
271271
fn len(&self) -> usize;
272272
}}
273273
274-
impl<T> Length for std::vec::Vec<T> {{
274+
impl<T> Length for alloc::vec::Vec<T> {{
275275
fn len(&self) -> usize {{
276-
std::vec::Vec::len(self)
276+
alloc::vec::Vec::len(self)
277277
}}
278278
}}
279279
280280
pub struct ContextIterWrapper<I, C> {{
281281
iter: I,
282-
_ctx: std::marker::PhantomData<C>,
282+
_ctx: core::marker::PhantomData<C>,
283283
}}
284284
impl<I: Default, C> Default for ContextIterWrapper<I, C> {{
285285
fn default() -> Self {{
286286
ContextIterWrapper {{
287287
iter: I::default(),
288-
_ctx: std::marker::PhantomData
288+
_ctx: core::marker::PhantomData
289289
}}
290290
}}
291291
}}
292-
impl<I, C> std::ops::Deref for ContextIterWrapper<I, C> {{
292+
impl<I, C> core::ops::Deref for ContextIterWrapper<I, C> {{
293293
type Target = I;
294294
fn deref(&self) -> &I {{
295295
&self.iter
296296
}}
297297
}}
298-
impl<I, C> std::ops::DerefMut for ContextIterWrapper<I, C> {{
298+
impl<I, C> core::ops::DerefMut for ContextIterWrapper<I, C> {{
299299
fn deref_mut(&mut self) -> &mut I {{
300300
&mut self.iter
301301
}}
302302
}}
303303
impl<I: Iterator, C: Context> From<I> for ContextIterWrapper<I, C> {{
304304
fn from(iter: I) -> Self {{
305-
Self {{ iter, _ctx: std::marker::PhantomData }}
305+
Self {{ iter, _ctx: core::marker::PhantomData }}
306306
}}
307307
}}
308308
impl<I: Iterator, C: Context> ContextIter for ContextIterWrapper<I, C> {{
@@ -322,7 +322,7 @@ impl<I: IntoIterator, C: Context> IntoContextIter for ContextIterWrapper<I, C> {
322322
fn into_context_iter(self) -> Self::IntoIter {{
323323
ContextIterWrapper {{
324324
iter: self.iter.into_iter(),
325-
_ctx: std::marker::PhantomData
325+
_ctx: core::marker::PhantomData
326326
}}
327327
}}
328328
}}

0 commit comments

Comments
 (0)