Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_opt no longer works effectively #1068

Open
ghost opened this issue Feb 10, 2021 · 6 comments
Open

get_opt no longer works effectively #1068

ghost opened this issue Feb 10, 2021 · 6 comments
Labels
needs design Technical design work is needed for issue to progress needs test Issues for which we should add a regression test regression Something that used to work, but now doesn't type: feature request Issues requesting a new feature or capability
Milestone

Comments

@ghost
Copy link

ghost commented Feb 10, 2021

How do I invoke saw with an extra argument for get_opt?

$ cat opt.saw
print (get_opt 0);
print (get_opt 1);
print (get_opt 2);

$ saw opt.saw argument
Multiple files not yet supported.
@brianhuffman
Copy link
Contributor

That's a very good question! We should probably reopen #143, because the feature is not very useful in its current state, is it?

Maybe the current design, where get_opt just takes a single Int parameter for the argument number, is not the right one. We probably need to design it to go along with a corresponding saw command-line flag that lets you supply arbitrary strings. How would you like it to work? We could keep the Int parameter, and have it select the string from the nth occurrence of a "user string" command line option. Or maybe the command-line option could support key/value pairs, and the saw-script function could take a key string instead of an int. Any of those would probably be pretty easy to implement.

@ghost
Copy link
Author

ghost commented Feb 11, 2021

A command-line flag to indicate that there are additional arguments seems reasonable, sort of like gdb's --args.

I like the idea of key/value pairs. The key string could give some contextual help when an argument is missing, more so than:

$ # same opt.saw as before, no third argument:
$ saw opt.saw
[00:36:23.445] Loading file "opt.saw"
[00:36:23.456] saw
[00:36:23.456] opt.saw
[00:36:23.456] Stack trace:
"get_opt" (opt.saw:3:8-3:15):
nth: index too large

On a related note, would it be possible to have a get_opt analogue for passing integers as command-line arguments? It would be useful for verifications like the llvm/dotprod_struct.saw example where the (vector) size is effectively an argument.

@brianhuffman brianhuffman added the needs design Technical design work is needed for issue to progress label Feb 12, 2021
@weaversa
Copy link
Contributor

Bit of a hack, but you can currently do:

$ saw opt.saw -v 0x1234

And skip over the -v strings. Might want to end the command with the verbosity you actually desire :-)

@weaversa
Copy link
Contributor

Here's some magic to get environment variables:

/** part of `nul_terminated_value` string before `nul` (`\0`) */
let unterminate (nul_terminated_value: String) : TopLevel String = do {
    unterminated_value <- exec "echo" ["-n", nul_terminated_value] "";
    return unterminated_value;
};

/** value of environment variable identified by `key` */
let get_env (key: String) : TopLevel String = do {
    terminated_value <- exec "printenv" ["-0", key] "";
    unterminated_value <- unterminate terminated_value;
    return unterminated_value;
};

@WeeknightMVP
Copy link

WeeknightMVP commented Mar 10, 2021

@weaversa On Linux (and maybe macOS) anyway. One could perhaps define other implementations for Windows Command Prompt, Powershell, etc., but it would be more portable to write an executable script (e.g. in Haskell or Python, but this would introduce a dependency). Of course, just having native get_env and get_opt definitions would be convenient. But this would lead to requests for other String manipulations (split, strip, substr, etc.)... These were all considerations in my hesitation to share these definitions. In the end, this would just be better-in-python.

@weaversa
Copy link
Contributor

@weaversa On Linux (and maybe macOS) anyway. One could perhaps define other implementations for Windows Command Prompt, Powershell, etc., but it would be more portable to write an executable script (e.g. in Haskell or Python, but this would introduce a dependency). Of course, just having native get_env and get_opt definitions would be convenient. But this would lead to requests for other String manipulations (split, strip, substr, etc.)... These were all considerations in my hesitation to share these definitions. In the end, this would just be better-in-python.

Well...there isn't a Windows build for SAW. Though, the commands likely work in the Docker container. :-)

@sauclovian-g sauclovian-g added needs test Issues for which we should add a regression test type: feature request Issues requesting a new feature or capability regression Something that used to work, but now doesn't labels Oct 30, 2024
@sauclovian-g sauclovian-g added this to the Someday milestone Oct 30, 2024
@sauclovian-g sauclovian-g changed the title Question about get_opt get_opt no longer works effectively Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs design Technical design work is needed for issue to progress needs test Issues for which we should add a regression test regression Something that used to work, but now doesn't type: feature request Issues requesting a new feature or capability
Projects
None yet
Development

No branches or pull requests

4 participants