MCPcopy Create free account
hub / github.com/numpy/numpy / parse_targets

Method parse_targets

numpy/distutils/ccompiler_opt.py:1840–1892  ·  view source on GitHub ↗

Fetch and parse configuration statements that required for defining the targeted CPU features, statements should be declared in the top of source in between **C** comment and start with a special mark **@targets**. Configuration statements are sort of keywor

(self, source)

Source from the content-addressed store, hash-verified

1838 self.parse_is_cached = True
1839
1840 def parse_targets(self, source):
1841 """
1842 Fetch and parse configuration statements that required for
1843 defining the targeted CPU features, statements should be declared
1844 in the top of source in between **C** comment and start
1845 with a special mark **@targets**.
1846
1847 Configuration statements are sort of keywords representing
1848 CPU features names, group of statements and policies, combined
1849 together to determine the required optimization.
1850
1851 Parameters
1852 ----------
1853 source : str
1854 the path of **C** source file.
1855
1856 Returns
1857 -------
1858 - bool, True if group has the 'baseline' option
1859 - list, list of CPU features
1860 - list, list of extra compiler flags
1861 """
1862 self.dist_log("looking for '@targets' inside -> ", source)
1863 # get lines between /*@targets and */
1864 with open(source) as fd:
1865 tokens = ""
1866 max_to_reach = 1000 # good enough, isn't?
1867 start_with = "@targets"
1868 start_pos = -1
1869 end_with = "*/"
1870 end_pos = -1
1871 for current_line, line in enumerate(fd):
1872 if current_line == max_to_reach:
1873 self.dist_fatal("reached the max of lines")
1874 break
1875 if start_pos == -1:
1876 start_pos = line.find(start_with)
1877 if start_pos == -1:
1878 continue
1879 start_pos += len(start_with)
1880 tokens += line
1881 end_pos = line.find(end_with)
1882 if end_pos != -1:
1883 end_pos += len(tokens) - len(line)
1884 break
1885
1886 if start_pos == -1:
1887 self.dist_fatal("expected to find '%s' within a C comment" % start_with)
1888 if end_pos == -1:
1889 self.dist_fatal("expected to end with '%s'" % end_with)
1890
1891 tokens = tokens[start_pos:end_pos]
1892 return self._parse_target_tokens(tokens)
1893
1894 _parse_regex_arg = re.compile(r'\s|,|([+-])')
1895 def _parse_arg_features(self, arg_name, req_features):

Callers 1

try_dispatchMethod · 0.80

Calls 5

_parse_target_tokensMethod · 0.95
openFunction · 0.85
dist_fatalMethod · 0.80
findMethod · 0.80
dist_logMethod · 0.45

Tested by

no test coverage detected