SAW REPL Reference

The primary mechanism for interacting with SAW is through the saw executable included as part of the standard binary distribution. With no arguments, saw starts a read-evaluate-print loop (REPL) that allows the user to interactively evaluate commands in the SAWScript language.

REPL Commands

There are a number of REPL-specific commands that can be accessed by typing a colon and the command name, and perhaps some arguments.

  • :? prints the list of :-commands with brief descriptions. If given an argument, it instead looks up a SAWScript builtin and prints its type and help text.

  • :cd changes the REPL’s current directory.

  • :env displays the values and types of all currently bound variables, including built-in functions and commands.

  • :help or :h is the same as :?.

  • :llvmdis disassembles an LLVM module. See separate subsection below.

  • :pwd prints the REPL’s current directory.

  • :quit or :q exits the REPL. (If the REPL was started as a subshell, it only exits that subshell, not the whole of SAW.)

  • :search with one or more types (complex types go in parentheses) prints matching currently bound variables. See separate subsection below.

  • :tenv displays the values and types of all currently bound types and type aliases, including many (but currently not all) built-in types.

  • :type or :t checks and prints the type of an arbitrary SAWScript expression:

    sawscript> :t show
    {a.0} a.0 -> String
    

Using :llvmdis

:llvmdis disassembles LLVM bitcode or prints other metadata from an LLVMModule. The first argument is the name of a SAWScript-level LLVMModule that has been loaded.

The second argument selects an object to disassemble. If it is a ! followed by a number N, the _N_th unnamed metadata reference is extracted and printed. If it contains a :, it is treated as a filename and line number and the code or data structure associated with that location is extracted and printed. Otherwise it is treated as a function name to disassemble.

The output is comparable to LLVM’s llvm-dis tool but is based on SAW’s internal representation and knowledge of the LLVM module.

Examples:

sawscript> bc <- llvm_load_module "intTests/testmulti/foo.bc"
sawscript> :llvmdis bc foo.c:2
  ... shows just line 2 of foo.c in LLVM textual format
sawscript> :llvmdis bc !10
  ... shows the metadata at index 10
sawscript> :llvmdis bc foo
  ... shows the foo function in LLVM textual format