예제 #1
0
    def test_function(self):
        coptions = COptions()
        coptions.enable("trigraphs")
        coptions.add_include_path(test_t_directory)
        libc_dir = os.path.join(this_dir, "..", "..", "..", "librt", "libc")
        coptions.add_include_path(libc_dir)

        output_file = io.StringIO()
        with open(filename, "r") as f:
            preprocess(f, output_file, coptions)
        # TODO: check output for correct values:
        print(output_file.getvalue())
예제 #2
0
def perform_test(filename):
    """ Try to compile the given snippet. """
    logger.info("Step 1: Compile %s!", filename)
    march = "x86_64"
    coptions = COptions()
    libc_include = os.path.join(this_dir, "..", "..", "..", "librt", "libc")
    coptions.add_include_path(libc_include)
    coptions.enable('freestanding')
    with open(filename, "r") as f:
        try:
            obj = api.cc(f, march, coptions=coptions)
        except CompilerError as ex:
            ex.print()
            raise
    logger.info("Compilation complete, %s", obj)

    logger.info("Step 2: Run it!")
    logger.error("Running not yet implemented")
예제 #3
0
def main():
    t1 = time.time()
    failed = 0
    passed = 0
    include_paths = [
        # os.path.join(newlib_folder, 'libc', 'include'),
        # TODO: not sure about the include path below for stddef.h:
        # '/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/include'
        libc_includes,
        micropython_folder,
        port_folder,
    ]
    coptions = COptions()
    coptions.add_include_paths(include_paths)
    coptions.enable('freestanding')
    coptions.add_define('NO_QSTR', '1')
    file_pattern = os.path.join(micropython_folder, 'py', '*.c')
    objs = []
    for filename in glob.iglob(file_pattern):
        print('==> Compiling', filename)
        try:
            obj = do_compile(filename, coptions)
        except CompilerError as ex:
            print('Error:', ex.msg, ex.loc)
            ex.print()
            print_exc()
            failed += 1
            # break
        except Exception as ex:
            print('General exception:', ex)
            print_exc()
            failed += 1
            # break
        else:
            print('Great success!', obj)
            passed += 1
            objs.append(obj)

    t2 = time.time()
    elapsed = t2 - t1
    print('Passed:', passed, 'failed:', failed, 'in', elapsed, 'seconds')
예제 #4
0
 def setUp(self):
     coptions = COptions()
     coptions.enable('verbose')
     self.preprocessor = CPreProcessor(coptions)
예제 #5
0
파일: compile_nos.py 프로젝트: ttwj/ppci
from ppci.api import cc
from ppci.utils.reporting import html_reporter
from ppci.lang.c import COptions
from ppci.common import CompilerError, logformat

home = os.environ['HOME']
nos_folder = os.path.join(home, 'GIT', 'nOS')
nos_inc_folder = os.path.join(nos_folder, 'inc')
nos_src_folder = os.path.join(nos_folder, 'src')
this_dir = os.path.abspath(os.path.dirname(__file__))
report_filename = os.path.join(this_dir, 'report_nos.html')
libc_path = os.path.join(this_dir, '..', 'librt', 'libc')
libc_includes = os.path.join(libc_path, 'include')
arch = 'msp430'
coptions = COptions()
coptions.enable('freestanding')
include_paths = [
    libc_includes, nos_inc_folder,
    os.path.join(nos_inc_folder, 'port', 'GCC', 'MSP430')
]
coptions.add_include_paths(include_paths)


def do_compile(filename, reporter):
    with open(filename, 'r') as f:
        obj = cc(f, arch, coptions=coptions, reporter=reporter)
    print(filename, 'compiled into', obj)
    return obj


def main():