Lines Matching +full:rev +full:- +full:parse

1 #!/usr/bin/awk -f
3 #-
4 # Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
39 print "usage: bhnd_nvram_map.awk <input map> [-hd] [-o output file]"
69 # Parse arguments
74 if (ARGV[_i] == "--debug") {
76 } else if (ARGV[_i] == "-d" && OUT_T == null) {
78 } else if (ARGV[_i] == "-h" && OUT_T == null) {
80 } else if (ARGV[_i] == "-v") {
82 } else if (ARGV[_i] == "-o") {
88 } else if (ARGV[_i] == "--") {
91 } else if (ARGV[_i] !~ /^-/) {
102 print("error: one of -d or -h required")
111 if (OUTPUT_FILE == "-") {
127 UINT_REGEX = "^(0|[1-9][0-9]*)$"
128 HEX_REGEX = "^(0x[A-Fa-f0-9]+)$"
129 OFF_REGEX = "^(0|[1-9][0-9]*)|^(0x[A-Fa-f0-9]+)"
130 REL_OFF_REGEX = "^\\+(0|[1-9][0-9]*)|^\\+(0x[A-Fa-f0-9]+)"
132 ARRAY_REGEX = "\\[(0|[1-9][0-9]*)\\]"
135 IDENT_REGEX = "[A-Za-z_][A-Za-z0-9_]*"
195 SPROM_OP_BIND_SKIP_IN_MIN = -3 # minimum SKIP_IN value
199 SPROM_OP_REV_RANGE_MAX = 15 # maximum SROM rev range value
267 # User-specifiable value formats
294 Int8Min = -128
296 Int16Min = -32768
298 Int32Min = -2147483648
348 VAccessInternal = obj_new(VAccess) # Implementation-Internal
400 class_add_prop(SromLayout, p_output_var_counts, # Map<int, int> (rev->count)
428 # Create the parse state stack
432 # Push the root parse state
454 # This also has a side-effect of generating a unique monotonic ID
574 output_depth--
593 # Write all top-level bhnd_sprom_layout entries
602 output_depth--
635 output_depth--
639 # Write a top-level bhnd_sprom_layout entry for the given revision
682 errorx("'sromrev' entry has non-u8 type '" \
694 emit(".rev = "revision",\n")
722 output_depth--
785 # opc: The standard opcode for non-IMM encoded data, or null if none
799 # SHIFT_IMM -- the imm value must be positive and divisible by
808 # OFFSET_REL_IMM -- the imm value must be positive, divisible
820 _delta = value - _offset
826 sprintf("/* %#x + %#x -> %#x */\n", _offset,
845 # Can't encode as immediate; do we have a non-immediate form?
848 "non-immediate form was provided")
930 if (_vid_prev <= _vid && (_vid - _vid_prev) <= SPROM_OP_IMM_MAX) {
933 _vid - _vid_prev, null)
958 # Sanity-check range values
997 # Encode (possibly a relative, 1-byte form) of the offset opcode
1101 "range %d-%d", skip_in,
1107 "range %d-%d", skip_out,
1168 _delta = _seg_offset - _bind_off
1201 # skip_out values of 1, and must contain no buffered post-BIND opcodes
1321 # The one-byte BINDN form requires encoding the count
1325 _count -= _count
1339 _count -= _written
1342 # The 1-byte BIND form can encode the same SKIP values
1343 # as the 2-byte BINDN, with a implicit count of 1
1350 _count--
1357 # Write any buffered post-BIND opcodes
1373 # Check the per-variable bind count to determine whether
1405 sprintf("/* bind (%s @ %#x -> %#x) */\n",
1468 # Write entry-specific array length (SROM layouts may define array
1485 output_depth--
1540 output_depth--
1576 _tab_align += (TAB_WIDTH - (_tab_align % TAB_WIDTH)) % TAB_WIDTH
1589 _lead -= (_lead % TAB_WIDTH);
1594 _pad = align_to - _lead;
1613 # Calculate the tab alignment to be used with a given integer-indexed array
1702 # Generic parse failure
1757 # Check class<->prop cache
1772 # Found; add to class<->prop cache
1819 # Return the property ID for a given class-defined property
1832 # Return the property ID for a given class-defined property name
2130 errorx("prop_to_path() called with non-property head")
2140 errorx("prop_path() called with non-property head")
2143 errorx("prop_path() called with non-property tail")
2151 errorx("prop_path_append() called with non-property tail")
2188 # Parse the head/tail of the property path and add to cache
2302 # If `prop_path*` is non-NULL, the corresponding property path (or property ID)
2319 _qsort(array, prop_path0, prop_path1, prop_path2, 0, _size-1)
2351 return (-1)
2365 _qpivot = int(first + int((last-first+1) * rand()))
2382 _qright--
2394 _qright--
2407 # If `prop_path` is non-NULL, the corresponding property path (or property ID)
2449 return (array_get(array, _size-1))
2540 # Handle Type equality -- we just check for trivial identity
2628 # The lhs type must be able to represent -at least- as
2659 # Parse a type string to either the Type, ArrayType, or null if
2665 _count = substr(str, RSTART+1, RLENGTH-2)
2679 # Parse a variable name in the form of 'name' or 'name[len]', returning
2686 _count = substr(str, RSTART+1, RLENGTH-2)
2750 # Parse an input string and return a new string constant
2758 # Parse and apend an additional line to this string constant
2764 errorx("can't append to non-continuation string '" \
2784 line = substr(line, 1, RLENGTH-1)
2825 # Return true if the requested rev is covered by revrange, false otherwise
2826 function revrange_contains(range, rev) {
2829 if (rev < get(range, p_start))
2831 else if (rev > get(range, p_end)) {
2852 return (_start "-" _end)
2969 # Return true if var is internal-only, and should not be included
3086 # The name is gauranteed to be unique across SROM layouts with non-overlapping
3099 function srom_layout_has_rev(layout, rev) {
3101 return (revrange_contains(get(layout, p_revisions), rev))
3107 function srom_layout_num_output_vars(layout, rev, _counts)
3112 if (!map_contains(_counts, rev))
3115 return (map_get(_counts, rev))
3213 function srom_entry_should_output(entry, rev, _var, _revs)
3225 if (!revrange_contains(_revs, rev))
3232 # Return the single, non-shifted, non-masked offset/segment for the given
3235 # This is used to fetch special-cased variable definitions that are required
3356 # Return a human-readable representation of a Segment instance
3422 return (i < 0 ? -i : i)
3440 # Parse a hex string
3446 # Populate hex parsing lookup table on-demand
3464 # Parse the hex_digits
3486 # Parse an offset string, stripping any leading '+' or trailing ':' or ','
3500 # Parse the cleaned up string
3571 # Advance to the next non-comment input record
3591 return (-1)
3608 for (_i = 1; _i <= NF-n; _i++) {
3611 NF = NF - n
3632 errorx("parser_state_get() called with empty parse stack")
3640 errorx("parser_state_pop() called with empty parse stack")
3645 _g_parse_stack_depth--
3669 _state = _g_parse_stack[_g_parse_stack_depth - _i]
3679 "found in parse stack")
3683 # Find opening brace and push a new parser state for a brace-delimited block.
3697 # brace-delimited block is discarded.
3701 error("internal error - no closing brace")
3725 # Parse and return a revision range from the current line.
3728 # 4-10 # revisions 4-10, inclusive
3738 if ($2 ~ "[0-9]*-[0-9*]") {
3739 split($2, _g_rev_range, "[ \t]*-[ \t]*")
3742 } else if ($2 ~ "(>|>=|<|<=)" && $3 ~ "[1-9][0-9]*") {
3751 _end = int($3)-1
3754 _end = int($3)-1
3758 } else if ($2 ~ "[1-9][0-9]*") {
3769 # Parse a variable group block starting at the current line
3784 # Parse the first line
3787 # Incrementally parse line continuations
3806 # Parse a variable definition block starting at the current line
3833 # Parse (and trim) any array specifier from the variable name
3861 # Return a string containing the human-readable list of valid Fmt names
3887 # Parse a variable parameter from the current line
3951 # Parse the first line
3954 # Incrementally parse line continuations
3971 # Parse a top-level SROM layout block starting at the current line
3973 # srom 4-7 {
3981 # Parse revision descriptor and register SROM
3995 # Parse a nested srom range filter block starting at the current line
3996 # srom 4-7 {
4006 # Parse revision descriptor
4020 # Parse a SROM offset segment's attribute list from the current line
4046 # parse attributes
4052 _attrs = substr($0, RSTART+1, RLENGTH-2)
4055 $0 = substr($0, RSTART+RLENGTH, length($0) - RSTART+RLENGTH)
4057 # parse attributes
4065 _shift = - parse_uint_string(_attr)
4080 # Parse a SROM offset's segment declaration from the current line
4125 # we need to parse the type.
4136 # Parse the trailing (... attributes ...), if any
4141 # Parse a SROM variable entry from the current line
4165 # Parse the base offset
4168 # Parse the base type
4172 # Parse (and trim) any array specifier from the variable name
4204 # Otherwise, we're using the simplified syntax -- create and
4209 # Parse and register simplified segment syntax
4219 # Parse all SromSegment entry segments readable starting at the current line
4235 # Parse all offsets
4243 # Parse all segments