Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #67 from rust-accel/syn-1.0
Browse files Browse the repository at this point in the history
Update syn, quote to 1.0
  • Loading branch information
termoshtt authored Jan 1, 2020
2 parents 29972b6 + efc9446 commit 7e64dfa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
6 changes: 4 additions & 2 deletions accel-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "accel-derive"
version = "0.2.1-alpha.0"
authors = ["Toshiki Teramura <toshiki.teramura@gmail.com>"]
edition = "2018"

description = "Procedual macro for writing GPGPU kernel"
documentation = "https://docs.rs/accel-derive/"
Expand All @@ -15,9 +16,10 @@ categories = []
proc-macro = true

[dependencies]
quote = "0.5"
proc-macro2 = "1.0"
quote = "1.0"
nvptx = "0.2.2"

[dependencies.syn]
version = "0.13"
version = "1.0"
features = ["full", "extra-traits"]
33 changes: 14 additions & 19 deletions accel-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! proc_macro for accel's #[kernel]
#![recursion_limit = "128"]

extern crate nvptx;
extern crate proc_macro;
#[macro_use]
extern crate quote;
extern crate syn;

use nvptx::manifest::Crate;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
use std::fs;

#[proc_macro_attribute]
Expand Down Expand Up @@ -56,8 +54,7 @@ const QUOTE: &[char] = &[' ', '"'];
fn parse_crate(attr: &syn::Attribute) -> Crate {
let path = &attr.path;
let path = quote! {#path}.to_string();
let tts = &attr.tts;
let tts = quote! {#tts}.to_string();
let tts = attr.tokens.to_string();
let tokens: Vec<_> = tts
.trim_matches(PENE)
.split('=')
Expand Down Expand Up @@ -100,7 +97,7 @@ fn parse_crate(attr: &syn::Attribute) -> Crate {
fn header(crates: &[Crate]) -> String {
let crates: Vec<syn::Ident> = crates
.iter()
.map(|c| syn::Ident::from(c.name.replace("-", "_")))
.map(|c| syn::Ident::new(&c.name.replace("-", "_"), Span::call_site()))
.collect();
let tt = quote! {
#![feature(abi_ptx)]
Expand All @@ -113,14 +110,13 @@ fn header(crates: &[Crate]) -> String {
/// Kernel part of lib.rs
fn ptx_kernel(func: &syn::ItemFn) -> String {
let vis = &func.vis;
let ident = &func.ident;
let unsafety = &func.unsafety;
let ident = &func.sig.ident;
let unsafety = &func.sig.unsafety;
let block = &func.block;

let decl = &func.decl;
let fn_token = &decl.fn_token;
let inputs = &decl.inputs;
let output = &decl.output;
let fn_token = &func.sig.fn_token;
let inputs = &func.sig.inputs;
let output = &func.sig.output;

let kernel = quote! {
#[no_mangle]
Expand All @@ -139,17 +135,16 @@ fn func2kernel(func: &syn::ItemFn) -> String {

fn func2caller(ptx_str: &str, func: &syn::ItemFn) -> TokenStream {
let vis = &func.vis;
let ident = &func.ident;
let ident = &func.sig.ident;

let decl = &func.decl;
let inputs = &decl.inputs;
let output = &decl.output;
let fn_token = &decl.fn_token;
let fn_token = &func.sig.fn_token;
let inputs = &func.sig.inputs;
let output = &func.sig.output;

let input_values: Vec<_> = inputs
.iter()
.map(|arg| match arg {
&syn::FnArg::Captured(ref val) => &val.pat,
&syn::FnArg::Typed(ref val) => &val.pat,
_ => unreachable!(""),
})
.collect();
Expand Down

0 comments on commit 7e64dfa

Please sign in to comment.