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)
| 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): |
no test coverage detected