Chromium Code Reviews| Index: src/trusted/validator_arm/dgen_input.py |
| =================================================================== |
| --- src/trusted/validator_arm/dgen_input.py (revision 8201) |
| +++ src/trusted/validator_arm/dgen_input.py (working copy) |
| @@ -1,8 +1,8 @@ |
| #!/usr/bin/python |
| # |
| -# Copyright 2012 The Native Client Authors. All rights reserved. |
| -# Use of this source code is governed by a BSD-style license that can |
| -# be found in the LICENSE file. |
| +# Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| # |
| """ |
| @@ -22,9 +22,15 @@ |
| CITATION = "(" /[^)]+/ ")" |
| BITRANGE = /[0-9]+/ (":" /[0-9]+/)? |
| PATTERN = /[10x_]+/ |
| -ACTION = ( "=" IDENT | "->" IDENT ) ( "(" IDENT ")" )? |
| +ACTION = ( "=" IDENT | "->" IDENT ) ( "(" IDENT ")" )? IDENT* |
| NL = a newline |
| BLANK_LINE = what you might expect it to be |
| + |
| +If ACTION has more than one IDENT, the interpretation is as follows: |
| + IDENT[0] = action (plus optional architecture) to apply. |
| + IDENT[1] = Arm rule action corresponds to. |
| + IDENT[2] = Bit pattern of rule. |
| + IDENT[3] = Name defining additional constraints for match. |
| """ |
| import re |
| @@ -101,9 +107,33 @@ |
| if row[i] == '"': row[i] = _last_row[i] |
| _last_row = row |
| - action = row[-1] |
| - patterns = row[:-1] |
| - table.add_row(patterns, action) |
| + # Pull out action and set of following symbols, and |
| + # remerge them into a single string operation (separated |
| + # by a single space). |
| + action_index = 0 |
| + action_type = None |
| + for w in row: |
| + if w.startswith('='): |
| + action_type = '=' |
| + break; |
| + elif w.startswith('->'): |
| + action_type = '->' |
| + break; |
| + else: |
| + action_index += 1 |
| + |
| + # verify we have a properly defined input. |
| + if action_index == len(row): unexpected() |
| + |
| + action = row[action_index:] |
| + patterns = row[:action_index] |
| + |
| + # verify we don't have too many fields for an action. |
| + if len(action) > 4: unexpected() |
| + if action_type == '->' and len(action) != 1: unexpected() |
| + |
| + # Recompose the action into a single token and add. |
| + table.add_row(patterns, ' '.join(action)) |
| next_line() |
| @@ -112,23 +142,29 @@ |
| def next_line(): |
| - "Reads the next non-comment line" |
| + """Reads the next non-comment line""" |
| global _line_no, _line |
| _line_no += 1 |
| _line = _in.readline() |
| while True: |
| if _line: |
| - if _line[0] == '#': |
| + if _line.startswith("#"): |
| # skip comment line and continue search. |
| _line_no += 1 |
| _line = _in.readline() |
| continue |
| _line = re.sub(r'#.*', '', _line).strip() |
|
robertm
2012/04/11 01:28:43
does this line sill make sense, since you are alre
Karl
2012/04/16 23:18:10
Since the parser is now free-form, it is no longer
|
| + if _line.endswith('\\'): |
| + # continuation. continue on next line. |
| + _line_no += 1 |
| + _line = _line[:-1] + ' ' + _in.readline() |
| + continue |
| else: |
| _line = None |
| # if reached, found line. |
| return |
| + |
| def unexpected(): |
| raise Exception('Line %d: Unexpected line in input: %s' % (_line_no, _line)) |