2
0

add-cfi.common.awk 482 B

1234567891011121314151617181920212223242526
  1. function hex2int(str, i) {
  2. str = tolower(str)
  3. for (i = 1; i <= 16; i++) {
  4. char = substr("0123456789abcdef", i, 1)
  5. lookup[char] = i-1
  6. }
  7. result = 0
  8. for (i = 1; i <= length(str); i++) {
  9. result = result * 16
  10. char = substr(str, i, 1)
  11. result = result + lookup[char]
  12. }
  13. return result
  14. }
  15. function parse_const(str) {
  16. sign = sub(/^-/, "", str)
  17. hex = sub(/^0x/, "", str)
  18. if (hex)
  19. n = hex2int(str)
  20. else
  21. n = str+0
  22. return sign ? -n : n
  23. }