Lines Matching +full:string +full:- +full:array +full:- +full:property

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]"
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_]*"
141 # Property array keys
145 # Prop path array keys
149 # Object array keys
154 # Class array keys
195 SPROM_OP_BIND_SKIP_IN_MIN = -3 # minimum SKIP_IN value
227 # Array class definition
228 Array = class_new("Array")
229 class_add_prop(Array, p_count, "count")
239 MTypeVarMaxLen = macro_type_new("len", "_MAXLEN") # var max array length
265 FmtStr = fmt_new("string", "bhnd_nvram_val_bcm_string_fmt")
267 # User-specifiable value formats
294 Int8Min = -128
296 Int16Min = -32768
298 Int32Min = -2147483648
348 VAccessInternal = obj_new(VAccess) # Implementation-Internal
374 # String Constant
376 class_add_prop(StringConstant, p_value, "value") # string
382 class_add_prop(Var, p_name, "name") # string
398 class_add_prop(SromLayout, p_entries, "entries") # Array<SromEntry>
399 class_add_prop(SromLayout, p_revmap, "revmap") # Map<(string,int), SromEntry>
400 class_add_prop(SromLayout, p_output_var_counts, # Map<int, int> (rev->count)
454 # This also has a side-effect of generating a unique monotonic ID
503 # Produce our array of #defines
514 # Variable array length
544 # Write all layout binding opcodes, and build an array
574 output_depth--
590 "array type constant out of sync"))
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 '" \
722 output_depth--
755 # Write a string to the SROM opcode stream, either buffering the write,
757 function srom_ops_emit(opstream, string, _pending_bind, _buffer) {
763 array_append(_buffer, string)
768 emit(string)
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
1388 # Clear the property value
1405 sprintf("/* bind (%s @ %#x -> %#x) */\n",
1468 # Write entry-specific array length (SROM layouts may define array
1474 # If the array length differs from the variable default,
1485 output_depth--
1540 output_depth--
1551 # Produce our array of #defines
1566 emit("/* ID constants provide an index into the variable array */\n")
1576 _tab_align += (TAB_WIDTH - (_tab_align % TAB_WIDTH)) % TAB_WIDTH
1582 # Generate and return a tab string that can be appended to a string of
1585 # Note: If the string from which strlen was derived contains tabs, the result
1589 _lead -= (_lead % TAB_WIDTH);
1594 _pad = align_to - _lead;
1613 # Calculate the tab alignment to be used with a given integer-indexed array
1746 # Return true if the given property property ID is defined on class
1757 # Check class<->prop cache
1772 # Found; add to class<->prop cache
1780 # Return true if the given property prop is defined on class
1788 # Define a `prop` on `class` with the given `name` string
1793 # Check for duplicate property definition
1795 errorx("property " prop[PROP_NAME] " already defined on " \
1798 # Init property IDs
1802 # Get (or create) new property entry
1819 # Return the property ID for a given class-defined property
1825 errorx("requested undefined property '" prop[PROP_NAME] "on " \
1832 # Return the property ID for a given class-defined property name
1838 errorx("requested undefined property '" name "'")
1843 errorx("requested undefined property '" _g_props[_prop_id] \
1876 # obj_delete() support for Array instances
1878 obj_assert_class(obj, Array)
1890 # Handle classes that use external global array storage
1894 } else if (obj_is_instanceof(obj, Array)) {
1995 # Return a debug string representation of an object's unique ID, class, and
2026 # Return true if the given property prop is defined by the object's superclass
2035 # Return true if the given property ID is defined by the object's superclass
2044 # Return the line (NR) at which a given property ID was set on the object
2045 # Will throw an error if the property has not been set on obj
2051 errorx("requested undefined property '" _g_props[prop_id] \
2059 errorx("property '" _g_props[prop_id] "' (" prop_id ") not " \
2063 # Return the line (NR) at which a given property was set on the object
2064 # Will throw an error if the property has not been set on obj
2069 # Return an abstract property ID for a given property
2078 # Return the property ID for a given property name
2086 # Set a property on obj
2091 # Get a property value defined on obj
2096 # Set a property on obj, using a property ID returned by obj_get_prop_id() or
2100 errorx("setting property '" _g_props[prop_id] \
2109 errorx("requested undefined property '" _g_props[prop_id] \
2113 # Track the line on which the property was set
2118 # Convert a property ID to a property path.
2121 errorx("'" prop_id "' is not a property ID")
2123 # Convert to path string representation
2127 # Convert a property to a property path.
2130 errorx("prop_to_path() called with non-property head")
2135 # Create a property path from head and tail properties
2140 errorx("prop_path() called with non-property head")
2143 errorx("prop_path() called with non-property tail")
2148 # Append a property to the given property path
2151 errorx("prop_path_append() called with non-property tail")
2156 # Append a property ID to the given property path
2159 errorx("'" tail_id "' is not a property ID")
2164 # Fetch a value from obj using a property path previously returned by
2170 errorx("requested property path '" \
2188 # Parse the head/tail of the property path and add to cache
2191 errorx("empty property path")
2208 # Fetch a value property value from obj, using a property ID returned by
2212 errorx("requested property '" _g_props[prop_id] \
2221 errorx("requested undefined property '" _g_props[prop_id] \
2247 # Create an empty array; this uses _g_arrays to store integer
2248 # keys/values under the object's property prefix.
2250 _obj = obj_new(Array)
2256 # Return the number of elements in the array
2257 function array_size(array) {
2258 obj_assert_class(array, Array)
2259 return (get(array, p_count))
2262 # Return true if the array is empty
2263 function array_empty(array) {
2264 return (array_size(array) == 0)
2267 # Append a value to the array
2268 function array_append(array, value, _i) {
2269 obj_assert_class(array, Array)
2271 _i = get(array, p_count)
2272 _g_arrays[array,OBJ_PROP,_i] = value
2273 set(array, p_count, _i+1)
2276 # Set an array value
2277 # An error will be thrown if the idx is outside array bounds
2278 function array_set(array, idx, value) {
2279 obj_assert_class(array, Array)
2281 if (!((array,OBJ_PROP,idx) in _g_arrays))
2282 errorx(idx " out of range of array " obj_to_string(array))
2284 _g_arrays[array,OBJ_PROP,idx] = value
2287 # Return value at the given index from the array
2288 # An error will be thrown if 'idx' is outside the array bounds
2289 function array_get(array, idx) {
2290 obj_assert_class(array, Array)
2292 if (!((array,OBJ_PROP,idx) in _g_arrays))
2293 errorx(idx " out of range of array " obj_to_string(array))
2295 return (_g_arrays[array,OBJ_PROP,idx])
2300 # Sort an array, using standard awk comparison operators over its values.
2302 # If `prop_path*` is non-NULL, the corresponding property path (or property ID)
2303 # will be fetched from each array element and used as the sorting value.
2305 # If multiple property paths are specified, the array is first sorted by
2309 function array_sort(array, prop_path0, prop_path1, prop_path2, _size) {
2310 obj_assert_class(array, Array)
2313 errorx("no more than three property paths may be specified")
2315 _size = array_size(array)
2319 _qsort(array, prop_path0, prop_path1, prop_path2, 0, _size-1)
2322 function _qsort_get_key(array, idx, prop_path, _v) {
2323 _v = array_get(array, idx)
2331 function _qsort_compare(array, lhs_idx, rhs_val, ppath0, ppath1, ppath2,
2334 _lhs_val = _qsort_get_key(array, lhs_idx, ppath0)
2341 _lhs_val = _qsort_get_key(array, lhs_idx, ppath1)
2345 _lhs_val = _qsort_get_key(array, lhs_idx, ppath2)
2351 return (-1)
2358 function _qsort(array, ppath0, ppath1, ppath2, first, last, _qpivot,
2365 _qpivot = int(first + int((last-first+1) * rand()))
2369 _qpivot_val = array_get(array, _qpivot)
2373 while (_qsort_compare(array, _qleft, _qpivot_val, ppath0, ppath1,
2379 while (_qsort_compare(array, _qright, _qpivot_val, ppath0, ppath1,
2382 _qright--
2387 _qleft_val = array_get(array, _qleft)
2388 _qright_val = array_get(array, _qright)
2390 array_set(array, _qleft, _qright_val)
2391 array_set(array, _qright, _qleft_val)
2394 _qright--
2399 _qsort(array, ppath0, ppath1, ppath2, first, _qright)
2400 _qsort(array, ppath0, ppath1, ppath2, _qleft, last)
2405 # Join all array values with the given separator
2407 # If `prop_path` is non-NULL, the corresponding property path (or property ID)
2408 # will be fetched from each array value and included in the result, rather than
2409 # immediate array value
2411 function array_join(array, sep, prop_path, _i, _size, _value, _result) {
2412 obj_assert_class(array, Array)
2415 _size = array_size(array)
2417 # Fetch the value (and optionally, a target property)
2418 _value = array_get(array, _i)
2431 # Return the first value in the array, or null if empty
2432 function array_first(array) {
2433 obj_assert_class(array, Array)
2435 if (array_size(array) == 0)
2438 return (array_get(array, 0))
2441 # Return the last value in the array, or null if empty
2443 obj_assert_class(array, Array)
2445 _size = array_size(array)
2449 return (array_get(array, _size-1))
2452 # Create an empty hash table; this uses the _g_maps array to store arbitrary
2453 # keys/values under the object's property prefix.
2540 # Handle Type equality -- we just check for trivial identity
2546 # Return the type's default value mask. If the type is an array type,
2574 # Return an array type's element count, or 1 if the type is not
2575 # an array type
2607 # Return a string representation of the given type
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)
2680 # either the provided base_type if no array specifiers are found, or
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 '" \
2770 # If start of string, look for (and remove) initial double quote
2774 error("expected quoted string")
2784 line = substr(line, 1, RLENGTH-1)
2839 # Return a string representation of the given revision range
2852 return (_start "-" _end)
2969 # Return true if var is internal-only, and should not be included
2975 # Return true if `var` has an array type
2982 # Return the number of array elements defined by this variable's type,
2983 # or 1 if the variable does not have an array type.
3049 # Add to revision array
3086 # The name is gauranteed to be unique across SROM layouts with non-overlapping
3194 # Return true if the SromEntry has an array type
3201 # Return the number of array elements defined by this SromEntry's type,
3202 # or 1 if the entry does not have an array type.
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
3303 # Return true if the segment has an array type
3309 # Return the array count of the segment, or 1 if the segment does not have
3310 # an array type
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
3454 # Split input into an array
3474 # octal string
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
3645 _g_parse_stack_depth--
3669 _state = _g_parse_stack[_g_parse_stack_depth - _i]
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")
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]*") {
3781 # Seek to the start of the name string
3833 # Parse (and trim) any array specifier from the variable name
3861 # Return a string containing the human-readable list of valid Fmt names
3865 # Build up a string listing the valid formats
3891 # desc "quoted string"
3892 # help "quoted string"
3934 # Set variable property
3937 # Fetch an indirect property reference for either the 'desc'
3938 # or 'help' property
3948 # Seek to the start of the desc/help string
3965 error("unknown variable property type: '" param_name "'")
3971 # Parse a top-level SROM layout block starting at the current line
3973 # srom 4-7 {
3996 # srom 4-7 {
4052 _attrs = substr($0, RSTART+1, RLENGTH-2)
4055 $0 = substr($0, RSTART+RLENGTH, length($0) - RSTART+RLENGTH)
4065 _shift = - parse_uint_string(_attr)
4100 # Offset string must be one of:
4142 # <offset>: <type> <varname><array spec> ...
4172 # Parse (and trim) any array specifier from the variable name
4204 # Otherwise, we're using the simplified syntax -- create and