Exemplo n.º 1
0
    def compile(self, id, name, source):
        src = '%s.c' % (name)
        with open(src, 'w') as f:
            f.write(source)

        try:
            work = sh.gcc(src, '-O2', '--static', '-Wall', '-lm', '-std=c99',
                          o=name, _ok_code=[0])
            work.wait()
            sh.rm(src).wait()
            return (0, '', '')
        except sh.ErrorReturnCode_1 as e:
            return (self.result_code[11], '', e.stderr.decode('utf-8'))
Exemplo n.º 2
0
def check_gcc(os='Linux'):
    '''Check that gcc is installed'''
    print('Check gcc (c++) compiler...')
    from sh import which
    shOut = which('gcc')
    print(shOut)
    if not shOut is None:
        from sh import gcc
        #print(gcc('--version'))
        return str(gcc('--version'))
    else:
        print(
            'ERROR: you must install gcc version 5.1 or above before continuing'
        )
Exemplo n.º 3
0
def check_gcc():
    '''Check that gcc is installed'''
    from sh import which
    shOut = which('gcc')
    #print('Check gcc (c++) compiler...')
    #print(shOut)
    if not shOut is None:
        from sh import gcc
        version = str(gcc('--version'))
        #print(version)
        return (version, True)
    else:
        print(
            'ERROR: you must install gcc version 5.1 or above before continuing'
        )
        return (None, False)
Exemplo n.º 4
0
def get_gcc_includes(source, include_directives, pkg, ignore=[]):
    from sh import gcc
    includes =  flatten([ln.strip('\ ').split() for ln in \
                        gcc(*include_directives, '-std=c++14', '-MM', '-MG', source).split('\n')])[1:]
    if not ignore:
        return includes

    result = []
    for include in includes:
        skip = False
        for path in ignore:
            if include.startswith(path):
                skip = True
        if skip is False:
            result.append(include)
    return result
Exemplo n.º 5
0
from sh import riscv64_unknown_elf_gcc as gcc
from sh import riscv64_unknown_elf_objdump as objdump
from sh import rm

import re

gcc("test.S", "-c", "-o", "test.o", "-march=rv32ima", "-mabi=ilp32")
for line in objdump("-d", "test.o"):
    m = re.match(r"^\s+([0-9a-f]+):\s+([0-9a-f]+)\s+(.*)$", line)
    if m:
        offset = int(m.group(1), 16)
        code = int(m.group(2), 16)
        assembly = m.group(3)

        bin_string = ""

        for index, bin_digit in enumerate("{:032b}".format(code)[::-1]):

            if index % 4 == 0 and index != 0:
                bin_string += "_"
            bin_string += bin_digit

        bin_string = bin_string[::-1]

        d = "{:032b}".format(code)[::-1]

        r_type = "_".join(
            (d[0:7], d[7:12], d[12:15], d[15:20], d[20:25], d[25:32]))[::-1]
        u_type = "_".join((d[0:7], d[7:12], d[12:32]))[::-1]

        print("r: 0b{} u: 0b{} {}".format(r_type, u_type, assembly))
Exemplo n.º 6
0
objs=[]


#even:
name="objs/even"
source=name+".c"
with open(source, "w") as f:
     for i in xrange(0,n,2):
        if(i==n-1):
            f.write("int fun{0}(){{return 42;}}\n".format(i))
        else:
            f.write("int fun{0}(); int fun{1}(){{return fun{0}();}}\n".format(i+1, i))
            
target= name+".o"
objs.append(target)
output=sh.gcc([source,"-c", "-o", target])


#odd:
name="objs/odd"
source=name+".c"
with open(source, "w") as f:
     for i in xrange(1,n,2):
        if(i==n-1):
            f.write("int fun{0}(){{return 42;}}\n".format(i))
        else:
            f.write("int fun{0}(); int fun{1}(){{return fun{0}();}}\n".format(i+1, i))
            
            
target= name+".o"
objs.append(target)