11#![ deny( warnings) ]
22
3- extern crate core;
4- extern crate proc_macro;
5- extern crate proc_macro2;
6- extern crate quote;
7- extern crate syn;
8-
9- use std:: vec;
10-
3+ use proc_macro:: TokenStream ;
114use proc_macro2:: { Span , TokenStream as TokenStream2 } ;
125use quote:: quote;
136use syn:: {
@@ -18,8 +11,6 @@ use syn::{
1811 FnArg , ItemFn , LitInt , LitStr , PatType , Path , ReturnType , Token , Type , Visibility ,
1912} ;
2013
21- use proc_macro:: TokenStream ;
22-
2314/// Attribute to declare the entry point of the program
2415///
2516/// **IMPORTANT**: This attribute must appear exactly *once* in the dependency graph. Also, if you
@@ -381,6 +372,17 @@ impl syn::parse::Parse for RiscvArch {
381372}
382373
383374impl RiscvArch {
375+ fn try_from_env ( ) -> Option < Self > {
376+ let arch = std:: env:: var ( "RISCV_RT_BASE_ISA" ) . ok ( ) ?;
377+ match arch. as_str ( ) {
378+ "rv32i" => Some ( Self :: Rv32I ) ,
379+ "rv32e" => Some ( Self :: Rv32E ) ,
380+ "rv64i" => Some ( Self :: Rv64I ) ,
381+ "rv64e" => Some ( Self :: Rv64E ) ,
382+ _ => None ,
383+ }
384+ }
385+
384386 fn width ( & self ) -> usize {
385387 match self {
386388 Self :: Rv32I | Self :: Rv32E => 4 ,
@@ -643,94 +645,14 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
643645/// loop{};
644646/// }
645647/// ```
646- pub fn core_interrupt_rv32i ( args : TokenStream , input : TokenStream ) -> TokenStream {
648+ pub fn core_interrupt ( args : TokenStream , input : TokenStream ) -> TokenStream {
647649 let arch = match ( ) {
648- #[ cfg( feature = "v-trap" ) ]
649- ( ) => Some ( RiscvArch :: Rv32I ) ,
650650 #[ cfg( not( feature = "v-trap" ) ) ]
651651 ( ) => None ,
652- } ;
653- trap ( args, input, RiscvPacItem :: CoreInterrupt , arch)
654- }
655-
656- #[ proc_macro_attribute]
657- /// Attribute to declare a core interrupt handler.
658- ///
659- /// The function must have the signature `[unsafe] fn() [-> !]`.
660- ///
661- /// The argument of the macro must be a path to a variant of an enum that implements the `riscv_rt::CoreInterruptNumber` trait.
662- ///
663- /// If the `v-trap` feature is enabled, this macro generates the corresponding interrupt trap handler in assembly.
664- ///
665- /// # Example
666- ///
667- /// ``` ignore,no_run
668- /// #[riscv_rt::core_interrupt(riscv::interrupt::Interrupt::SupervisorSoft)]
669- /// fn supervisor_soft() -> ! {
670- /// loop{};
671- /// }
672- /// ```
673- pub fn core_interrupt_rv32e ( args : TokenStream , input : TokenStream ) -> TokenStream {
674- let arch = match ( ) {
675- #[ cfg( feature = "v-trap" ) ]
676- ( ) => Some ( RiscvArch :: Rv32E ) ,
677- #[ cfg( not( feature = "v-trap" ) ) ]
678- ( ) => None ,
679- } ;
680- trap ( args, input, RiscvPacItem :: CoreInterrupt , arch)
681- }
682-
683- #[ proc_macro_attribute]
684- /// Attribute to declare a core interrupt handler.
685- ///
686- /// The function must have the signature `[unsafe] fn() [-> !]`.
687- ///
688- /// The argument of the macro must be a path to a variant of an enum that implements the `riscv_rt::CoreInterruptNumber` trait.
689- ///
690- /// If the `v-trap` feature is enabled, this macro generates the corresponding interrupt trap handler in assembly.
691- ///
692- /// # Example
693- ///
694- /// ``` ignore,no_run
695- /// #[riscv_rt::core_interrupt(riscv::interrupt::Interrupt::SupervisorSoft)]
696- /// fn supervisor_soft() -> ! {
697- /// loop{};
698- /// }
699- /// ```
700- pub fn core_interrupt_rv64i ( args : TokenStream , input : TokenStream ) -> TokenStream {
701- let arch = match ( ) {
702652 #[ cfg( feature = "v-trap" ) ]
703- ( ) => Some ( RiscvArch :: Rv64I ) ,
704- #[ cfg( not( feature = "v-trap" ) ) ]
705- ( ) => None ,
653+ ( ) => RiscvArch :: try_from_env ( ) ,
706654 } ;
707- trap ( args, input, RiscvPacItem :: CoreInterrupt , arch)
708- }
709655
710- #[ proc_macro_attribute]
711- /// Attribute to declare a core interrupt handler.
712- ///
713- /// The function must have the signature `[unsafe] fn() [-> !]`.
714- ///
715- /// The argument of the macro must be a path to a variant of an enum that implements the `riscv_rt::CoreInterruptNumber` trait.
716- ///
717- /// If the `v-trap` feature is enabled, this macro generates the corresponding interrupt trap handler in assembly.
718- ///
719- /// # Example
720- ///
721- /// ``` ignore,no_run
722- /// #[riscv_rt::core_interrupt(riscv::interrupt::Interrupt::SupervisorSoft)]
723- /// fn supervisor_soft() -> ! {
724- /// loop{};
725- /// }
726- /// ```
727- pub fn core_interrupt_rv64e ( args : TokenStream , input : TokenStream ) -> TokenStream {
728- let arch = match ( ) {
729- #[ cfg( feature = "v-trap" ) ]
730- ( ) => Some ( RiscvArch :: Rv64E ) ,
731- #[ cfg( not( feature = "v-trap" ) ) ]
732- ( ) => None ,
733- } ;
734656 trap ( args, input, RiscvPacItem :: CoreInterrupt , arch)
735657}
736658
@@ -790,7 +712,6 @@ fn trap(
790712 Some ( arch) => {
791713 let trap = start_interrupt_trap ( int_ident, arch) ;
792714 quote ! {
793- #[ cfg( any( target_arch = "riscv32" , target_arch = "riscv64" ) ) ]
794715 #trap
795716 }
796717 }
0 commit comments