-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathparser.py
More file actions
114 lines (102 loc) · 4.63 KB
/
parser.py
File metadata and controls
114 lines (102 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""Create parser for m2cpp."""
import argparse
from textwrap import dedent
import glob
import matlab2cpp
HELP_DESCRIPTION = """\
*** Matlab2cpp ***
The toolbox frontend of the Matlab2cpp library. Use this to try to do automatic
and semi-automatic translation from Matlab source file to C++. The program
will create files with the same name as the input, but with various extra
extensions. Scripts will receive the extension `.cpp`, headers and modules
`.hpp`. A file containing data type and header information will be stored in
a `.py` file. Any errors will be stored in `.log`.
"""
def matlab_file_completer(prefix, **kws):
"""Complete files with matlab extensions."""
return glob.glob("{}*.m".format(prefix))
def create_parser():
"""Create argument parser."""
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=dedent(HELP_DESCRIPTION))
parser.add_argument(
"filename", help="File containing valid Matlab code."
).completer = matlab_file_completer
parser.add_argument(
"-o", '--original', action="store_true", help=(
"Include original Matlab code line as comment before the "
"C++ translation of the code line"),
)
parser.add_argument(
"-c", '--comments', action="store_true", help=(
"Include Matlab comments in the generated C++ files."),
)
parser.add_argument(
"-s", '--suggest', action="store_true", help=(
"Automatically populate the `<filename>.py` file with datatype "
"with suggestions if possible."),
)
parser.add_argument(
"-S", '--matlab-suggest', action="store_true", help=(
"Creates a folder m2cpp_temp. In the folder the matlab file(s) to "
"be translated are also put. These matlab file(s) are slightly "
"modified so that they output data-type information of the "
"variables to file(s). This output can then be used to set the "
"datatypes for the translation."),
)
parser.add_argument(
"-r", '--reset', action="store_true", help=(
"Ignore the content of `<filename>.py` and make a fresh translation."),
)
parser.add_argument(
"-t", '--tree', action="store_true", help=(
"Print the underlying node tree. Each line in the output "
"represents a node and is formated as follows: \n\n"
"`<codeline> <position> <class> <backend> <datatype> <name> <translation>`\n\n"
"The indentation represents the tree structure."),
)
parser.add_argument(
"-T", "--tree-full", action="store_true", help=(
"Same as -t, but the full node tree, but include meta-nodes."),
)
parser.add_argument(
"-d", '--disp', action="store_true", help=(
"Print out the progress of the translation process."),
)
parser.add_argument(
"-p", "--paths_file", type=str, dest="paths_file", help=(
"Flag and paths_file (-p path_to_pathsfile). m2cpp will look for "
"matlab files in the location specified in the paths_file"),
)
parser.add_argument(
"-omp", '--enable-omp', action="store_true", help=(
"OpenMP code is inserted for Parfor and loops marked with the "
"pragma %%#PARFOR (in Matlab code) when this flag is set."),
)
parser.add_argument(
"-tbb", '--enable-tbb', action="store_true", help=(
"TBB code is inserted for Parfor and loops marked with the "
"pragma %%#PARFOR (in Matlab code) when this flag is set."),
)
parser.add_argument(
"-ref", '--reference', action="store_true", help=(
'For the generated C++ code, function input parameters are '
'"copied by value" as default. With this flag some input '
'parameters in the generated code can be const references. '
'There can be some performance advantage of using const '
'references instead of "copied by value". Note that Matlab '
'"copies by value". The Matlab code you try to translate to '
'C++ code could try read as well as write to this input variable. '
"The code generator doesn't perform an analysis to detect this "
'and then "copy by value" for this variable.'),
)
parser.add_argument(
"-l", '--line', type=int, dest="line", help=(
"Only display code related to code line number `<line>`."),
)
parser.add_argument(
"-n", '--nargin', action="store_true", help=(
"Don't remove if and switch branches which use nargin variable."),
)
return parser