As one of the people using the Ophis assembler (
https://github.com/michaelcmartin/Ophis), I'm stuck with lots of code that is written in a more "standard" syntax. So I've put together a small Python script to help me convert from one format to another: asm2ophis (included).
What it does is convert things like "ALIAS = NUMBER" to ".alias ALIAS NUMBER", add semicolons to labels, and justify comments the way I prefer them, etc. One of the biggest problems was converting "unmarked" inline comments -- remarks that don't start with a ";" such as in VTL2 -- to the Ophis syntax. It's only half-automatic, the end result needs to be edited by hand for a whole bunch of things, but it does relieve me of a lot of the time-consuming grunt work. What it does
not do is include any of the more advanced Ophis features. As a Python program, it should run on any platform. I've tried to comment as much as I can.
So far, I've only used it with VTL 2.0 and FIG Forth, two of the large programs I hope to incorporate in the Übersquirrel. Anything else is bound to create new problems. A more serious version of this tool would have to first figure out which assembler format is being used first and then approach the whole problem appropriately, but for the moment, I'm getting by with this -- pardon my German -- half-assed script.
I've included a file with the raw output of processing the VTL02a2b source so people can get a feeling for what this can't or cannot do. Below is the listing of the problems asm2ophis spit out on the command line when this was generated. You'll notice a bunch of warnings about "inc" instructions -- there are so many variations even in the syntax of those two files I just ask the user to handle them ("inc", "inc a", "inc <alias>", "inc <address>"). This is true for lsr, asl, dec, and a few others.
There is a whole bunch of stuff that could be improved very quickly, but I'll be doing other things for the next couple of days and thought I'd offer what I had here in case somebody could use this. Of course, I'm grateful for suggestions and corrections.
Code:
Line 2: Error: Found unexpected dot-command .lf
Line 3: Error: Found unexpected dot-command .cr
Line 4: Error: Found unexpected dot-command .tf
Line 157: Error: Found unexpected dot-command .or
Line 163: Warning: Found '/', convert manually.
Line 167: Warning: Found '/', convert manually.
Line 270: Warning: Opcode 'dec' found, convert manually
Line 284: Warning: Opcode 'inc' found, convert manually
Line 286: Warning: Opcode 'inc' found, convert manually
Line 320: Warning: Opcode 'dec' found, convert manually
Line 321: Warning: Opcode 'dec' found, convert manually
Line 400: Warning: Opcode 'inc' found, convert manually
Line 401: Warning: Opcode 'inc' found, convert manually
Line 415: Warning: Opcode 'inc' found, convert manually
Line 480: Warning: Opcode 'rol' found, convert manually
Line 486: Warning: Opcode 'rol' found, convert manually
Line 570: Warning: Opcode 'dec' found, convert manually
Line 595: Warning: Opcode 'inc' found, convert manually
Line 604: Warning: Opcode 'inc' found, convert manually
Line 606: Warning: Opcode 'inc' found, convert manually
Line 661: Warning: Opcode 'lsr' found, convert manually
Line 663: Warning: Opcode 'ror' found, convert manually
Line 663: Warning: Found '/', convert manually.
Line 666: Warning: Opcode 'asl' found, convert manually
Line 668: Warning: Opcode 'rol' found, convert manually
Line 687: Warning: Opcode 'asl' found, convert manually
Line 689: Warning: Opcode 'rol' found, convert manually
Line 690: Warning: Opcode 'rol' found, convert manually
Line 691: Warning: Opcode 'rol' found, convert manually
Line 701: Warning: Opcode 'inc' found, convert manually
Line 702: Warning: Opcode 'dec' found, convert manually
Line 716: Warning: Opcode 'inc' found, convert manually
Line 724: Warning: Opcode 'inc' found, convert manually
Line 728: Warning: Opcode 'rol' found, convert manually
Line 747: Warning: Opcode 'asl' found, convert manually
Line 752: Warning: Opcode 'asl' found, convert manually
Line 753: Warning: Opcode 'rol' found, convert manually
Line 809: Warning: Found '/', convert manually.
Line 815: Warning: Opcode 'inc' found, convert manually
Line 838: Warning: Found '/', convert manually.
Line 850: Warning: Opcode 'inc' found, convert manually
Warning: File may contain unmarked comments (line 752 for instance).
Done. Wrote 870 lines.