This is an archive of the discontinued LLVM Phabricator instance.

[Support] Add APInt support for LEB128 encoding/decoding
Needs ReviewPublic

Authored by nlguillemot on Apr 24 2020, 11:19 PM.

Details

Summary

This specializes the LEB128CodecInfo template for APInt, which allows
the input/output iterators used for LEB128 encoding/decoding to be used
with APInt. As a convenience, the encode[U|S]LEB128() functions in
LEB128.h have been overloaded for APInt. The decode[U|S]LEB128()
functions were not customized for APInt. If one wants to decode an
APInt, they can do so with the more general decodeLEB128<T> function.

For testing, new unit tests were created based on the existing LEB128
tests. These tests run the previously existing test inputs, and they
also run a "big" version of the previous inputs. The "big" versions are
created by adding a "big prefix" to the previous "small" inputs. These
"big" versions of the tests exercise the ability of APInt to be usable
to encode and decode values bigger than 64 bits.

Diff Detail