Beispiel #1
0
def process(nodes):
    def warn(things):
        print(things)

    nodes, _ = model.evaluate_model(nodes, warn)
    CppGenerator().check_nodes(nodes)
    return nodes
Beispiel #2
0
def main():
    opts = options.parse_options()

    if opts.version:
        print "prophyc {}".format(__version__)
        sys.exit(0)

    if not opts.input_files:
        sys.exit("prophyc: error: missing input file")

    if opts.isar:
        from prophyc.parsers.isar import IsarParser
        parser = IsarParser()
        parse_error = None
    elif opts.sack:
        if not module_exists("clang"):
            sys.exit("Sack input requires clang and it's not installed")
        from prophyc.parsers.sack import SackParser
        parser = SackParser(opts.include_dirs)
        parse_error = None
    else:
        from prophyc.parsers.prophy import ProphyParser, ParseError
        parser = ProphyParser()
        parse_error = ParseError

    serializers = []
    if opts.python_out:
        from prophyc.generators.python import PythonGenerator
        serializers.append(PythonGenerator(opts.python_out))
    if opts.cpp_out:
        from prophyc.generators.cpp import CppGenerator
        serializers.append(CppGenerator(opts.cpp_out))

    if not serializers:
        sys.exit("Missing output directives")

    for input_file in opts.input_files:
        try:
            nodes = parser.parse(input_file)
        except parse_error as e:
            sys.exit('\n'.join(e.errors))

        if opts.patch:
            from prophyc import patch
            patches = patch.parse(opts.patch)
            patch.patch(nodes, patches)
        model.topological_sort(nodes)
        model.cross_reference(nodes)
        model.evaluate_kinds(nodes)

        for serializer in serializers:
            basename = get_basename(input_file)
            serializer.serialize(nodes, basename)
Beispiel #3
0
def get_serializers(opts):
    serializers = []
    if opts.python_out:
        from prophyc.generators.python import PythonGenerator
        serializers.append(PythonGenerator(opts.python_out))
    if opts.cpp_out:
        from prophyc.generators.cpp import CppGenerator
        serializers.append(CppGenerator(opts.cpp_out))
    if opts.cpp_full_out:
        from prophyc.generators.cpp_full import CppFullGenerator
        serializers.append(CppFullGenerator(opts.cpp_full_out))
    return serializers
Beispiel #4
0
def generate_definitions(nodes):
    process_nodes(nodes)
    return CppGenerator().generate_definitions(nodes)
Beispiel #5
0
def generate_cpp(nodes, basename):
    process_nodes(nodes)
    return CppGenerator().serialize_string_cpp(nodes, basename)
Beispiel #6
0
def generate_swap(nodes):
    process_nodes(nodes)
    return CppGenerator().generate_swap(nodes)
Beispiel #7
0
def generate_cpp(nodes, basename):
    return CppGenerator().serialize_string_cpp(nodes, basename)
Beispiel #8
0
def generate_swap(nodes):
    return CppGenerator().generate_swap(nodes)
Beispiel #9
0
def generate_swap_declarations(nodes):
    return CppGenerator().generate_swap_declarations(nodes)
Beispiel #10
0
def generate_definitions(nodes):
    return CppGenerator().generate_definitions(nodes)
Beispiel #11
0
def test_struct_size_error():
    nodes = [model.Struct('X', [model.StructMember('x', 'Unknown')])]

    with pytest.raises(GenerateError) as e:
        CppGenerator().check_nodes(nodes)
    assert "X byte size unknown" == str(e.value)