Exemplo n.º 1
0
 def given_source(self, source):
     """ Lex a given source and prepare the parser """
     clexer = CLexer(COptions())
     f = io.StringIO(source)
     source_file = SourceFile("<snippet>")
     tokens = clexer.lex(f, source_file)
     tokens = prepare_for_parsing(tokens, self.parser.keywords)
     self.parser.init_lexer(tokens)
Exemplo n.º 2
0
 def test_hello(self):
     """ Convert C to Ir, and then this IR to C """
     src = r"""
     void printf(char*);
     void main(int b) {
       printf("Hello" "world\n");
     }
     """
     arch = ExampleArch()
     builder = CBuilder(arch.info, COptions())
     f = io.StringIO(src)
     ir_module = builder.build(f, None)
     assert isinstance(ir_module, ir.Module)
     verify_module(ir_module)
     synthesizer = CSynthesizer()
     synthesizer.syn_module(ir_module)
Exemplo n.º 3
0
 def setUp(self):
     arch = get_arch("x86_64")
     coptions = COptions()
     self.context = CContext(coptions, arch.info)
Exemplo n.º 4
0
 def setUp(self):
     coptions = COptions()
     self.semantics = mock.Mock(spec=CSemantics, name="semantics")
     self.parser = CParser(coptions, self.semantics)
Exemplo n.º 5
0
 def setUp(self):
     coptions = COptions()
     self.lexer = CLexer(coptions)
     coptions.enable("trigraphs")
Exemplo n.º 6
0
import os
import sys
from ppci import api
from ppci.common import CompilerError
from ppci.utils.reporting import html_reporter
from ppci.lang.c.options import COptions, coptions_parser
from ppci.binutils.objectfile import merge_memories

this_dir = os.path.abspath(os.path.dirname(__file__))
libc_includes = os.path.join(this_dir, '..', '..', 'librt', 'libc')

parser = argparse.ArgumentParser(parents=[coptions_parser])
parser.add_argument('-v', action='count', default=0)
args = parser.parse_args()

coptions = COptions.from_args(args)
coptions.add_include_path(libc_includes)
report_html = os.path.join(this_dir, 'compilation_report.html')
if args.v > 0:
    logging.basicConfig(level=logging.DEBUG)
else:
    logging.basicConfig(level=logging.INFO)

arch = api.get_arch('riscv')

with html_reporter(report_html) as reporter:

    def cc(filename):
        logging.info('Compiling %s', filename)
        with open(os.path.join(this_dir, filename)) as f:
            try:
Exemplo n.º 7
0
 def setUp(self):
     arch = ExampleArch()
     self.builder = CBuilder(arch.info, COptions())