Use compressed code if the target supports it.
[riscv-tests.git] / debug / targets.py
index ca075ecfcb776682ece1295fec62ade3ae365b02..bcebc0b613ef83797a01fc4dc7d9d77370bf0223 100644 (file)
@@ -11,6 +11,8 @@ class Target(object):
     temporary_files = []
     temporary_binary = None
     openocd_config = []
+    use_fpu = False
+    misa = None
 
     def __init__(self, cmd, run, isolate):
         self.cmd = cmd
@@ -38,17 +40,27 @@ class Target(object):
                     prefix=binary_name + "_")
             binary_name = self.temporary_binary.name
             Target.temporary_files.append(self.temporary_binary)
+        march = "rv%dima" % self.xlen
+        if self.use_fpu:
+            march += "fd"
+        if self.extensionSupported("c"):
+            march += "c"
         testlib.compile(sources +
                 ("programs/entry.S", "programs/init.c",
                     "-I", "../env",
-                    "-march=RV%dIMAF" % self.xlen,
+                    "-march=%s" % march,
                     "-T", "targets/%s/link.lds" % (self.directory or self.name),
                     "-nostartfiles",
                     "-mcmodel=medany",
+                    "-DXLEN=%d" % self.xlen,
                     "-o", binary_name),
                 xlen=self.xlen)
         return binary_name
 
+    def extensionSupported(self, letter):
+        # target.misa is set by testlib.ExamineTarget
+        return self.misa & (1 << (ord(letter.upper()) - ord('A')))
+
 class SpikeTarget(Target):
     # pylint: disable=abstract-method
     directory = "spike"
@@ -60,6 +72,7 @@ class SpikeTarget(Target):
 class Spike64Target(SpikeTarget):
     name = "spike64"
     xlen = 64
+    use_fpu = True
 
     def server(self):
         return testlib.Spike(self.cmd, halted=True)