Go to the first, previous, next, last section, table of contents.


The `jsdas' Program

The jsdas program is a disassembler and a manipulator for the JavaScript byte-code files. The program can be used to view, disassemble and manipulate the byte-code files.

Invoking The `jsdas' Program

The jsdas program is invoked as:

jsdas option... file...

The program reads the options and processes the byte-code files file... according to the options. The options can be one or more of the following command line options:

-c
--code
Print the code section of the byte-code files. This is the default action that is preformed if no options are given for the jsdas program.
-C
--constants
Print the constants section of the byte-code file.
-d
--debug
Print the debug section of the byte-code file.
-h
--help
Print a short help message that describes the options that can be given to the jsdas program.
-i
--info
Print the byte-code file information.
-l type data
--link type data
Link a new section to the byte-code file. The section's type is type and its contents is read from file data.
-r type
--remove type
Remove section of type type from the byte-code files.
-s
--symtab
Print the symbol table section of the byte-code file.
-S
--strip
Remove the debug section from the byte-code files.
-V
--version
Print the version number of the jsdas program.

Viewing Byte-Code Files

In this section we assume that we have a source file `hello.js' with the following contents:

function main ()
{
  System.print ("Hello, world!\n");
}

main ();

The file has been compiled to byte-code file `hello.jsc' with the following command:

$ js -Wall -g -c hello.js

The option `--info' is used to view the contents of the byte-code file. For example, our example file contains the following information:

$ jsdas --info hello.jsc
hello.jsc:

* byte-code file information

  section 0: type=0 (code), length=34
  section 1: type=1 (constants), length=40
  section 2: type=2 (symtab), length=25
  section 3: type=3 (debug), length=40

We see that the byte-code file has four sections: code, constants, symtab and debug. The listing shows also their lengths. The sections are:

code
the byte-code instructions of the file
constants
the constant values of the file
symtab
the symbol table
debug
the debugging information

Next, we would like to see a assembler listing of the byte-code, defined in the code section of the file. This can be viewed with the option `--code' that is the jsdas's default option (so no options for the following example).

$ jsdas hello.jsc
hello.jsc:

* section `Code'

main:
  0     load_arg        1
  2     add_2_i
  3     min_args        2
  5     const           "Hello, world!\n"
  10    const_i1
  11    load_global     System
  16    call_method     print
  21    pop_n           4
  23    const_undefined
  24    return

.global:
  25    const_i0
  26    const_null
  27    jsr             main
  32    apop            2

The constants section holds the constant data the byte-code instructions need. These constants are pushed to the stack with the const byte-code operand, or they are used to name a symbol in method invocation or in subroutine call.

The constant section can be viewed with the `--constants' option.

$ jsdas --constants hello.jsc
hello.jsc:

* section `Constants'

  0:    "Hello, world!\n"
  1:    System
  2:    print
  3:    main

Our example file defines four constants. A string `Hello, world!\n' and three symbols `System', `print', and `main'.

The debugging information holds line number information about the source file from which the file was compiled. The debugging section can be viewed with the option `--debug':

$ jsdas --debug hello.jsc
hello.jsc:

* section `Debug'

  2     hello.js:2
  10    hello.js:3
  26    hello.js:6

The symbol table hold the information about the global symbols the byte-code file defines. For each symbol, the symbol table has an offset that points to the appropriate location in the byte-code instruction stream.

The symbol table information can be viewed with the `--symtab' option:

$ jsdas --symtab hello.jsc
hello.jsc:

* section `Symtab'

  main                                    0
  .global                                 25

Manipulating Byte-Code Files

$ jsdas --link 7001 hello.js hello.jsc
hello.jsc:
jsdas: linking 67 bytes of data to section 7001
$ jsdas --info hello.jsc
hello.jsc:

* byte-code file information

  section 0: type=0 (code), length=34
  section 1: type=1 (constants), length=40
  section 2: type=2 (symtab), length=25
  section 3: type=3 (debug), length=40
  section 4: type=7001, length=67
$ jsdas --remove 3 hello.jsc
hello.jsc:
jsdas: removing section 3
$ jsdas --remove 7001 hello.jsc
hello.jsc:
jsdas: removing section 7001
$ jsdas -i hello.jsc
hello.jsc:

* byte-code file information

  section 0: type=0 (code), length=34
  section 1: type=1 (constants), length=40
  section 2: type=2 (symtab), length=25


Go to the first, previous, next, last section, table of contents.