@@ -161,4 +161,79 @@ def get_extension_list(isa):
161161
162162 return (extension_list , err , err_list )
163163
164+ def get_march_mabi (isa : str ):
165+ '''
166+ This function returns the corresponding march and mabi argument values
167+ for RISC-V GCC
164168
169+ arguments:
170+ isa: (string) this is the isa string in canonical order
171+
172+ returns:
173+ march: (string) this is the string to be passed to -march to gcc for a given isa
174+ mabi: (string) this is the string to be passed to -mabi for given isa
175+ march_list: (list) gives march as a list of all extensions as elements
176+ None: if ISA validation throws error
177+ '''
178+
179+ # march generation
180+
181+ march = 'rv32' if '32' in isa else 'rv64'
182+ march_list = []
183+ march_list .append (march )
184+
185+ # get extension list
186+ (ext_list , err , err_list ) = get_extension_list (isa )
187+
188+ # if isa validation throws errors, return None
189+ if err :
190+ return None
191+
192+ # extensions to be nullified
193+ null_ext = [
194+ # privilege modes
195+ 'U' ,
196+ 'S' ,
197+
198+ # rnmi
199+ 'Smrnmi' ,
200+
201+ # debug mode
202+ 'Sdext' ,
203+
204+ # performance counter
205+ 'Zicntr' ,
206+ 'Zihpm' ,
207+
208+ # unratified Zb* extensions
209+ 'Zbe' ,
210+ 'Zbf' ,
211+ 'Zbm' ,
212+ 'Zbr' ,
213+ ]
214+
215+ # add Zbp and Zbt to null_ext if Zbpbo is present
216+ if 'Zbpbo' in ext_list :
217+ null_ext += ['Zbp' , 'Zbt' ]
218+ # construct march
219+ for ext in ext_list :
220+ if ext not in null_ext :
221+ march_list .append (ext .lower ())
222+ # suffix multicharacter extensions with '_'
223+ if len (ext ) == 1 :
224+ march += ext .lower ()
225+ else :
226+ # suffix multiline extensions with '_'
227+ march = march + '_' + ext .lower ()
228+
229+ # mabi generation
230+ mabi = 'ilp32'
231+ if 'F' in ext_list and 'D' in ext_list :
232+ mabi += 'd'
233+ elif 'F' in ext_list :
234+ mabi += 'f'
235+
236+ if 'rv64' in march :
237+ mabi = mabi .replace ('ilp32' , 'lp64' )
238+
239+ return (march , mabi , march_list )
0 commit comments