diff --git a/src/Console.huff b/src/Console.huff new file mode 100644 index 0000000..2a7db4b --- /dev/null +++ b/src/Console.huff @@ -0,0 +1,472 @@ +/// @title Console +/// @notice SPDX-License-Identifier: MIT +/// @author AmadiMichael +/// @notice Console.log functionalities for huff/bytecode written contracts compiled using foundry + + + + +////////////////////// STYLE=STD CONSTANTS ///////////////////////////// + + +#define constant RED = 0x1b5b39316d000000000000000000000000000000000000000000000000000000 +#define constant GREEN = 0x1b5b39326d000000000000000000000000000000000000000000000000000000 +#define constant YELLOW = 0x1b5b39336d000000000000000000000000000000000000000000000000000000 +#define constant BLUE = 0x1b5b39346d000000000000000000000000000000000000000000000000000000 +#define constant MAGENTA = 0x1b5b39356d000000000000000000000000000000000000000000000000000000 +#define constant CYAN = 0x1b5b39366d000000000000000000000000000000000000000000000000000000 +#define constant BOLD = 0x1b5b316d00000000000000000000000000000000000000000000000000000000 +#define constant DIM = 0x1b5b326d00000000000000000000000000000000000000000000000000000000 +#define constant ITALIC = 0x1b5b336d00000000000000000000000000000000000000000000000000000000 +#define constant UNDERLINE = 0x1b5b346d00000000000000000000000000000000000000000000000000000000 +#define constant INVERSE = 0x1b5b376d00000000000000000000000000000000000000000000000000000000 +#define constant RESET = 0x1b5b306d00000000000000000000000000000000000000000000000000000000 + + + + + + +////////////////////// EXPERIMENTAL (STYLE-STD) ///////////////////////////// + + +/// @notice EXPERIMENTAL FEATURE +/// @notice can be used to create a line break to help differentiate between different logs +/// @dev @param start is the offset to pre store line break bytecode in memory +/// @dev @param mem_ptr is free memory location to be used for logging operations (would take more than 32 bytes) +#define macro LINE_BREAK(start, mem_ptr) = { + // "0a" is hex for "\n" which breaks into a new line + __RIGHTPAD(0x0a) mstore + // logs out memory as bytes from offset 0x00 till offset 0x00 + 0x06 bytes and uses memory offset 0x20 for logging operations + LOG_MEMORY_AS_STRING(, 0x01, ) +} + + +/// @notice EXPERIMENTAL FEATURE +/// @notice styled logs is still experimental +/// @notice console log the first item of the stack +/// @dev @param style is the offset in memory where the color signature is stored +#define macro LOG_MEMORY_AS_STRING_STYLE(start, size, mem_ptr, style) = { + 0x41304fac00000000000000000000000000000000000000000000000000000000 mstore + + 0x20 0x04 add mstore + 0x09 add 0x24 add mstore + +