SFIDF

The following represents the current state of the Swordfish Intermediate Debug File (IDF) which is currently being implemented. As such, it is work in progress. The IDF is a structured text based file which will enable the compiler to support simulation and debugging. In addition, information contained in the file would allow plugins to display both ROM and RAM usage for subroutines, functions, events and interrupt routines.

Sample Code

// simple xy structure...
Structure TXY
   x,y As Byte
End Structure 

// a type of TXY structure...
Type TMyType = TXY

// big structure...
Structure TStructure
   a,b,c As Byte
   xy As TMyType Union
   Alias As c
End Structure

// a function that return a structure...
Public Function MyFunc(pIndex As Byte) As TStructure
   Dim lValue As Byte
   lValue = pIndex
   result.a = lvalue
End Function

// module level variables...   
Dim MyStructure As TStructure
Dim OK,NotOK As Boolean
Dim Index As Byte
Dim Str As String
Dim AliasStr As Str
Dim ch As Str(10)

// main program...   
Index = 10
MyStructure = MyFunc(Index)
OK = true
NotOK = false
ch = "a"

Debug Output

The following shows the IDF output for the above program.

 .exe
   $000000 | $EF04 sys | 
   $000002 | $F000 sys | 
   $000008 | $8C18 sys | 
   $00000A | $D005 sys | 
   $00000C | $C019 000 | 000 00045 C00001 
   $00000E | $F01A 000 | 
   $000010 | $C01A 000 | 000 00046 C00001 
   $000012 | $F01B 000 | 
   $000014 | $0012 000 | 
   $000016 | $0E0A 000 | 000 00058 
   $000018 | $6E22 000 | 
   $00001A | $C022 000 | 000 00059 
   $00001C | $F019 000 | 
   $00001E | $DFF6 000 | 
   $000020 | $EE00 000 | 
   $000022 | $F01F 000 | 
   $000024 | $EE10 000 | 
   $000026 | $F01B 000 | 
   $000028 | $0E03 000 | 
   $00002A | $CFE6 000 | 
   $00002C | $FFEE 000 | 
   $00002E | $2EE8 000 | 
   $000030 | $D7FC 000 | 
   $000032 | $801E 000 | 000 00060 
   $000034 | $921E 000 | 000 00061 
   $000036 | $0E61 000 | 000 00062 
   $000038 | $6E2D 000 | 
   $00003C | $D7FE end | 
 .end

 .file
   001 SystemTypes "C:\Programming\Borland\Swordfish\Compiler\Swordfish\Includes\18F4680.BAS"
   000 MAIN "C:\Programming\Borland\Swordfish\Compiler\Swordfish\TestPrograms\debug\Debug.bas"
 .end

 .module 001 SystemTypes
   .var PUB $0D79 00 0000 0000 U08    RXF6SIDH
   .var PUB $0D7A 00 0000 0000 U08    RXF6SIDL
   ... and so on
   .var PUB $0F99 00 0000 0000 U08    PORTA
 .end

 .module 000 
   .import 001 SystemTypes
   .structure PRI 00001 0002 TXY
   .var 0000 0000 0000 U08    x
   .var 0008 0000 0000 U08    y
   .end
   .structure PRI 00002 0003 TStructure
   .var 0000 0000 0000 U08    a
   .var 0008 0000 0000 U08    b
   .var 0016 0000 0000 U08    c
   .var 0000 0000 0000 *00001 xy
   .var 0016 0000 0000 U08    Alias
   .end
   .func PUB 00001 $0000C 00010 $0019 0005 C000 00045 00046 MyFunc
   .var VAL $0019 00 0000 0000 U08    pIndex
   .var PRI $001A 00 0000 0000 U08    lValue
   .ret PUB $001B 00 0000 0000 *00002 MyFunc
   .end
   .var PRI $001E 00 0000 0000 U01    OK
   .var PRI $001E 01 0000 0000 U01    NotOK
   .var PRI $001F 00 0000 0000 *00002 MyStructure
   .var PRI $0022 00 0000 0000 U08    Index
   .var PRI $0023 00 0024 0000 U08    Str
   .var PRI $002D 00 0000 0000 U08    ch
 .end

Overview

Please note the following is preliminary and is likely to change.

.exe Section

The first section is the .exe block. For example,

F0F1F2F3F4F5
$00000A$0E0A0000000058 
$000012$C0190000000045I00001
  • F0 - ROM address
  • F1 - Executable ROM code
  • F2 - The physical module that the executable ROM code is located. For example, a subroutine may be located in module 002 (see F3 below), but the code may be generated inline. For example, a physical module ID of 000 indicates that the code was generated inline in the main program. A "sys" descriptor denotes system or non-module code. For example, DelayMS()

The next three fields are optional. If present, they give information relating to a high level instruction. For example, "a = 10" or "if index < 10 then..."

  • F3 - The module ID that contains the high level instruction. See the files block for more information.
  • F4 - The instruction line number
  • F5 - A unique procedure, function, event or interrupt ID. The routine is inline if the ID is preceded with an "I", called if preceded with "C".

.file Section

The file section gives a unique module ID, module name and a fully qualifies path to the source file. For example,

   001 SystemTypes "C:\Programming\Borland\Swordfish\Compiler\Swordfish\Includes\18F4680.BAS"

.module Section

The modules section begins with a unique module ID followed by the module name. Every module section terminates with .end. For example,

 .module 002 MyModule
 .end

A module section can hold multiple debug types. For example, structures, variables and procedures.

.import

The .import keyword denotes modules that have been included. The .import keyword is followed by a unique module ID and module name.

.proc, .func, .event and .isr Section

The procedure section is always terminated with .end. For example,

 .func PUB 00001 $0000C 00010 $0019 0005 00045 00046 MyFunc
 .end

A procedure section can hold multiple debug types. For example, structures and variables. A procedure section consists of the following fields

F0F1F2F3F4F5F6F7F8
Scope00001$0000C00010$001900050004500046MyFunc
  • F0 - Scope identifier. Can be PRI or PUB.
  • F1 - Unique procedure ID
  • F2 - ROM start address in bytes
  • F3 - Total number of ROM bytes used
  • F4 - RAM start address in bytes
  • F5 - RAM used in bytes
  • F6 - Line start
  • F7 - Line end
  • F8 - Procedure name

.con

All information pertaining to a .con debug item is held on a single line and consists of the following fields

F0F1F2F3F4F5
Scope$000001A00110000U08CString
  • F0 - Scope identifier. Can be PRI or PUB.
  • F1 - The starting ROM address of the variable.
  • F2 - The number of elements for first dimension. For example, an array or a string.
  • F3 - The number of elements for the second dimension. For example, an array of strings.
  • F4 - The element size in bits which is preceded by "U", "S" and "F" denoting unsigned, signed and floating point respectively.
  • F5 - The constant name.

Please note that .con debug items will only be generated for constants that are held in the compilers constant ROM table. These are typically strings and arrays. Constant debug entries are not made for single constant values that are generated within the main executable block.

.var

All information pertaining to a .var debug item is held on a single line and consists of the following fields

F0F1F2F3F4F5F6
Scope$00190000000000U08pIndex
  • F0 - Scope identifier. Can be PRI or PUB. For procedure arguments, a scope identifier can be VAL, REF or CON.
  • F1 - The starting RAM address of the variable.
  • F2 - Bit offset for the variable. Bits and booleans are typically packed into bytes. This field gives the bit offset.
  • F3 - The number of elements for first dimension. For example, an array or a string.
  • F4 - The number of elements for the second dimension. For example, an array of strings.
  • F5 - The element size in bits which is preceded by "U", "S" and "F" denoting unsigned, signed and floating point respectively. If preceded with a "*", the number is a pointer to a unique structure ID.
  • F6 - The variable name

.structure Section

A structure section is always terminated with .end. For example,

   .structure PRI 0001 002 TXY
   .end 

A structure section can hold multiple .var types. A structure section consists of the following fields

F0F1F2F3
Scope00001002TXY
  • F0 - The structure scope. Can be PRI or PUB.
  • F1 - A unique structure ID
  • F2 - The total size of the structure in bytes
  • F3 - The structure name

A structure .var item has a slightly different format from other .var items, as no address information is present. For structure .var items, the fields are

F1F2F3F4F5
000000000000U08MyVar
  • F0 - The offset of the variable contained in the structure, in bits.
  • F1 - The number of elements for first dimension. For example, an array or a string.
  • F2 - The number of elements for the second dimension. For example, an array of strings.
  • F3 - The element size in bits which is preceded by "U", "S" and "F" denoting unsigned, signed and floating point respectively. If preceded with a "*", the number is a pointer to a unique structure ID.
  • F4 - The variable name