vishapoberon / compiler

vishap oberon compiler
http://oberon.vishap.am
GNU General Public License v3.0
186 stars 25 forks source link

What is the difference and use of .h and .sym files in voc? #24

Closed snayaksnayak closed 8 years ago

snayaksnayak commented 8 years ago

What is the difference and use of .h and .sym files in voc? I see many .h files in voc-1.1 directory. I can generate .sym file using voc -s. What is the difference between .h file and .sym file? Do these files have any use for programmer or they are only meant for voc's internal use?

norayr commented 8 years ago

.sym files are symbol files every Oberon compiler has to generate. voc's frontend is op2 compiler from oberon system. op2 generates symbol files in the oberon system.

in order to compile a module M, which imports module M0, it is not necessary to have module M0 source, but necessary to have M0.sym file, so that compiler can know M0's interface. It's like a modula-2 definition file, but in the form of the index. It's easier and faster to parse for a compiler.

You can get a human readable form of any symbol file by using "showdef" command.

For example,

/opt/voc/bin/showdef /opt/voc/lib/voc/sym/Strings.sym

will show:

DEFINITION Strings;

  PROCEDURE Append(extra: ARRAY OF CHAR; VAR dest: ARRAY OF CHAR);
  PROCEDURE Cap(VAR s: ARRAY OF CHAR);
  PROCEDURE Delete(VAR s: ARRAY OF CHAR; pos: INTEGER; n: INTEGER);
  PROCEDURE Extract(source: ARRAY OF CHAR; pos: INTEGER; n: INTEGER; VAR dest: ARRAY OF CHAR);
  PROCEDURE Insert(source: ARRAY OF CHAR; pos: INTEGER; VAR dest: ARRAY OF CHAR);
  PROCEDURE Length(s: ARRAY OF CHAR): INTEGER;
  PROCEDURE Match(string: ARRAY OF CHAR; pattern: ARRAY OF CHAR): BOOLEAN;
  PROCEDURE Pos(pattern: ARRAY OF CHAR; s: ARRAY OF CHAR; pos: INTEGER): INTEGER;
  PROCEDURE Replace(source: ARRAY OF CHAR; pos: INTEGER; VAR dest: ARRAY OF CHAR);

END Strings.
norayr commented 8 years ago

Header files are part of generated C code. When we generate C code, we have to generate one header file (with .h extension) and one C source file (with .c extension) files for one module. When we generate assembler code, one assembler file (usually with .s extension) for module is enough.

then, C compiler or assembler creates object file (with extension .o) for every module.

snayaksnayak commented 8 years ago

showdef is indeed nice. When I compiled my Hello.Mod file, I didn't see the symbol file created in the directory. Why?

norayr commented 8 years ago

because you have compiled it with -m or -M option, which implies that it's a main module, and therefore no symbol file is necessary.

snayaksnayak commented 8 years ago

Oh, now I see.