grigory-rechistov / interpreters-comparison

Sample programs for comparison of different VM interpretation techniques
BSD 3-Clause "New" or "Revised" License
27 stars 9 forks source link

Add ability to load programs from external file #11

Closed grigory-rechistov closed 8 years ago

grigory-rechistov commented 8 years ago

At the moment the only program the simulator can execute is statically defined as Program array during compilation. It would be great to be able to load external programs from files. That would add a lot of flexibility to the simulator.

Steps required:

  1. Add a new option to argc, argv parsing for optional file name, like ./switched 1000 file.raw
    1. If the option is present, the file contents is loaded to the program memory as-is starting from address 0x0
    2. If no option is present, the default program is used
  2. Proper error checking should be implemented:
    1. If the file cannot be read (missing/no permissions), an error is reported
    2. If the file is shorter than memory length, the rest of it should be padded with zeroes
    3. If file is too big (contains more words than program memory should hold), an error or at least a warning should be produced. At no circumstances buffer overflow may happen.
    4. (optional) If file contains instructions that are not valid for the processor, a warning (not error) should be produced
  3. A test should be prepared that showcases the new functionality with at least one external file with some sort of a valid program.

The file loading functionality is generic, i.e., it does not depend on used interpreter mode, so it can/should be done for all variants of the interpreter/translator

grigory-rechistov commented 8 years ago

Closed in #18