@@ -30,6 +30,7 @@ def parse_opt(argv):
3030 parser .add_argument ('-march' , '--with-arch' , type = str , dest = 'march' )
3131 parser .add_argument ('-selftest' , action = 'store_true' )
3232 parser .add_argument ('--get-riscv-tag' , type = str )
33+ parser .add_argument ('--get-elf-class' , type = str )
3334 opt = parser .parse_args ()
3435 return opt
3536
@@ -160,11 +161,19 @@ class TestArchStringParse(unittest.TestCase):
160161def selftest ():
161162 unittest .main (argv = sys .argv [1 :])
162163
163- def read_arch_attr (path ):
164+ def open_elf (path ):
164165 try :
165166 elffile = elftools .elf .elffile .ELFFile (open (path , 'rb' ))
166167 except elftools .common .exceptions .ELFError :
167168 raise Exception ("%s is not ELF file!" % path )
169+ return elffile
170+
171+ def read_elf_class (path ):
172+ elffile = open_elf (path )
173+ return elffile .elfclass
174+
175+ def read_arch_attr (path ):
176+ elffile = open_elf (path )
168177
169178 attr_sec = elffile .get_section_by_name (".riscv.attributes" )
170179 if attr_sec :
@@ -200,8 +209,12 @@ def main(argv):
200209 if opt .selftest :
201210 selftest ()
202211 return 0
203- if (opt .with_elf ):
204- march = read_arch_attr (opt .with_elf )
212+ if (opt .get_elf_class ):
213+ elf_class = read_elf_class (opt .get_elf_class )
214+ print (elf_class )
215+ return
216+ if (opt .get_riscv_tag ):
217+ march = read_arch_attr (opt .get_riscv_tag )
205218 else :
206219 march = opt .march
207220 cpu_opt = conver_arch_to_qemu_cpu_opt (march )
0 commit comments