GitLab will be upgraded on 30 Jan 2023 from 2.00 pm (AEDT) to 3.00 pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

mu.py 1.66 KB
Newer Older
John Zhang's avatar
John Zhang committed
1
2
3
4
import subprocess as subproc
import os
from pathlib import Path

John Zhang's avatar
John Zhang committed
5
6
7
from mubench.lang import Language
from mubench import CALLBACKS_DIR
from mubench.exceptions import ExecutionFailure
John Zhang's avatar
John Zhang committed
8
9
10
11
12
13
14
15
16
17


class Mu(Language):
    name = 'mu'
    src_ext = 'c'   # one or a folder of C files calling API to build the bundle
    compiled = True
    default_exec = 'clang'    # assume presence of clang

    @classmethod
    def compile(cls, src_file, target_dir=None, **compiler_conf):
John Zhang's avatar
John Zhang committed
18
        callback_dir = CALLBACKS_DIR / cls.name
John Zhang's avatar
John Zhang committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

        cmd = []
        cmd.append(os.path.expandvars(compiler_conf.get('exec', cls.default_exec)))

        # flags
        flags = []
        default_flags = ['-I%(callback_dir)s' % locals()]
        flags.extend(compiler_conf.get('flags', default_flags))
        target_dir = target_dir if target_dir else src_file.parent
        target = target_dir / src_file.name[:-2]
        flags.extend(['-o', str(target)])
        cmd.extend(flags)

        cmd.append(str(src_file))

        # callback selected at compile time, initialised at runtime
        callback_file = callback_dir / compiler_conf['callback']['name']
        cmd.append(str(callback_file))

        cls.run_in_subproc(cmd)

        assert target.exists()
        return target


    @classmethod
    def run(cls, target, iterations, args, result_file, **runner_conf):
        cmd = [str(target)]

        # first argument: callback param
        cmd.append(runner_conf['callback']['param'])

        # second argument: iterations
        cmd.append(str(iterations))

        # third argument: result file name
        cmd.append(str(result_file))

        cmd.extend(map(str, args))

        cls.run_in_subproc(cmd)