Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

feat(cli): alternative compilation entrypoint #221

Merged
merged 3 commits into from
Oct 25, 2022
Merged

Conversation

Maddiaa0
Copy link
Member

@Maddiaa0 Maddiaa0 commented Oct 23, 2022

Overview

This PR adds a flag alternative-main -m --alt-main which allows the user to define an alternative macro as their runtime bytecode entry point.

Usage
Given a test huff file that looks like the following:

#define macro MAIN() {
    0x01
}

#define macro ALT_MAIN(){
    0x02
}

running huffc --bin-runtime -m ALT_MAIN will output 6002.

If a macro name is provided that does not exist it will panic with a macro not found error.

Rational

I am beginning to look at seriously implementing a huff lsp, from this i would like there to be a way to have tags on a macro / huff test definitions in the IDE that would allow directly triggering an interactive debugger (similar to how test appears over rust test blocks). Having this behaviour within the compiler will greatly reduce the amount of code that would be required to enable macro level debugging.
Ideal use-case would be something like this:

hevm/forge debug --code ${huffc <file>.huff --bin-runtime -m <MACRO_NAME>}

Where this would launch the user immediately into an interactive debugger.

Even better would be integrating this with a test.

#[test(calldata=<something>)]
macro HUFF_TEST = {
    ...
}

Where the test could be instantly compiled with the --calldata added as an arg to forge/hevm debug.

Requested feedback points

  1. Do we want this feature?
  2. As to how the current PR is implemented, please let me know if you would prefer an alternative approach to providing this functionality. I've had to change a whole lot of tests for the current usage. This feels slightly messy to me but I'm not sure if it is less messy than the alternatives.

@Maddiaa0 Maddiaa0 changed the title feat: alternative compilation entrypoint feat(cli): alternative compilation entrypoint Oct 23, 2022
Copy link
Collaborator

@refcell refcell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 Killer job!

@refcell
Copy link
Collaborator

refcell commented Oct 25, 2022

Similarly, opened up issue #222

@refcell refcell merged commit 5f6b94d into stage Oct 25, 2022
@refcell refcell mentioned this pull request Nov 1, 2022
@refcell refcell deleted the md/alt-entrypoint branch February 26, 2023 19:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants