[PATCH v2] RISC-V: Add support for RISC-V Profiles.

Andreas Schwab schwab@linux-m68k.org
Fri Aug 2 13:01:25 GMT 2024


On Aug 02 2024, Jiawei wrote:

> @@ -2144,6 +2175,40 @@ riscv_set_default_arch (riscv_parse_subset_t *rps)
>      }
>  }
>  
> +const char *
> +riscv_handle_profiles (const char * p){
> +  /* Checking if input string contains a Profiles.
> +     There are two cases use Profiles in -march option
> +
> +       1. Only use Profiles as -march input
> +       2. Mixed Profiles with other extensions
> +
> +     use '+' to split Profiles and other extension.  */
> +  for (int i = 0; riscv_profiles_table[i].profile_name != NULL; ++i) {
> +    const char* match = strstr(p, riscv_profiles_table[i].profile_name);
> +    const char* plus_ext = strchr(p, '+');
> +    /* Find profile at the begin.  */
> +    if (match != NULL && match == p) {
> +      /* If there's no '+' sign, return the profile_string directly.  */
> +      if(!plus_ext)
> +	return riscv_profiles_table[i].profile_string;
> +      /* If there's a '+' sign, need to add profiles with other ext.  */
> +      else {
> +	size_t arch_len = strlen(riscv_profiles_table[i].profile_string)+
> +		  strlen(plus_ext);
> +	/* Reset the input string with Profiles mandatory extensions,
> +	   end with '_' to connect other additional extensions.  */
> +	char* result = (char*)malloc(arch_len + 2);
> +	strcpy(result, riscv_profiles_table[i].profile_string);
> +	strcat(result, "_");
> +	strcat(result, plus_ext + 1); /* skip the '+'.  */
> +	return result;
> +      }
> +    }
> +  }
> +  return p;
> +}
> +

Please reformat according to the GNU coding standard.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."


More information about the Binutils mailing list