home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
languages
/
headergen
/
Doc
next >
Wrap
Text File
|
1995-06-23
|
10KB
|
240 lines
HeaderGen 1.00
Documentation
____________________________________________________________________________________
HeaderGen is a coding tool for use with Acorn ANSI C and ObjAsm.
HeaderGen is (c) Frank Föhl. This version is PD and may be copied freely, as long as
all files are included and unaltered.
• Purpose:
Generate header files of C and Assembler source files, and convert Assembler sources
to C headers as well as C headers to Assembler headers.
• Syntax:
HeaderGen -CtoC [keyword args] <C source> <C header>
HeaderGen -ASMtoASM [keyword args] <ASM source> <ASM header>
HeaderGen -ASMtoC [keyword args] <ASM source> <C header>
HeaderGen -CtoASM [keyword args] <C header> <ASM header>
Keyword options:
-ExtIdent <string> Use <string> to identify external labels (with -ASMtoASM,-ASMtoC)
or to identify external functions/variables (with -CtoC, -CtoASM)
-I <dir>[,<dir>...] Include <dir>s on the include file search path (with -CtoASM)
-typedef Declare 'typedef' structures explicitly (with -CtoASM)
• Limitations
Parsing of C source files is not perfect (I haven't bothered to look up the syntax
diagrams), but I think it's now fairly sufficient. If anything goes wrong with
parsing C sources you will get errors or warnings from HeaderGen, as usual.
Bitfields are not supported.
HeaderGen has no C++ support.
Most preprocessor statements are ignored, only the #include's and #define's are
recognized with the -CtoASM action (see below), the #define's only to a limited
degree.
HeaderGen -CtoASM parses all Clib and RISC_OSlib headers fine (provided there's no
C++ stuff contained), with the exceptions 'signal.h', 'kernel.h' and 'colourpick.h',
which is mainly because a *very* odd syntax was used. :-)
The length of the words and syntax structures scanned in the input files is limited to
2048 characters, so there might be problems with very long character strings for
example. You'll get a 'word overflow' error if this should occur. Identifiers are
truncated to 256 characters.
• How to use HeaderGen
All four actions have in common that the generated code is appended to the target
file immediately after the first occurrence of the sequence '/* Auto */' (in C files)
or '; Auto' (in ASM files), deleting everything following it. If the sequence is not
found in the file, then it will be appended along with the generated code. The header
file is generated if it isn't already there.
The makefile skeleton shows how HeaderGen can be effectively incorporated into
makefiles.
In the following section the four actions are described in detail.
HeaderGen -CtoC
=================
generates prototypes of external functions and variables and appends them to the
named C header.
Functions and global variables are considered to be external if they contain the
'ExtIdent' string (see keyword options). This is to allow for global objects that are
only visible within the program module where they are defined. The default ExtIdent
string is the empty string, which will match any symbol. If you wish to use this
feature, then I'd recommend using the name of the program module as ExtIdent string,
as shown in the sample makefile. You can then use this string as a prefix of your
external symbols.
• One little problem with -CtoC
If you declare a (comma-separated) list of global variables of the same type, the
ExtIdent string will only be checked against the first variable name. According to
the result, the whole list is either 'extern'ed or not. If this causes inconvenience,
split the list up into single <type> <var> declarations.
HeaderGen -ASMtoASM
=====================
appends all external labels defined in the ASM source to the ASM header, each preceded
by an IMPORT/EXPORT directive. The directive is implemented as an Asm variable which
is defined at the beginning of the header. This variable expands to 'EXPORT' if the
Asm variable __<file>_s has already been defined, to 'IMPORT' otherwise, where <file>
is the name of the program module. You need to write a 'GBLA __file_s' in every source
file, before it 'GET's its own header, for the header to 'know' whether it is supposed
to IMPORT or to EXPORT the external labels. They are EXPORTed when the header is
included from its own source file, IMPORTed otherwise.
Consequently, you don't need to worry about importing or exporting externals, just
sign your external labels as external, include the ASM header into its own source file
and into any source file where the externals shall be visible, and everything's ok.
Labels found in the source file are considered to be external if they contain the
ExtIdent string.
If additional 'EXPORT <label>' statements are present in the Asm source, then the
corresponding 'IMPORT's will be appended to the header, regardless of the ExtIdent
string, so even if you don't wish to use an external identifier string, you can still
use -ASMtoASM.
$-prefixed symbols and lines with Asm directives are ignored by this operation.
HeaderGen -ASMtoC
===================
appends all external labels to the C header, preceded by 'extern'. A label is
considered to be external, either if it contains the ExtIdent string or if it is
explicitly EXPORTed.
If there's a comment of the form '; (<type>)' following the label, then <type> is
considered to be the type of the object at the label's address. The default type
is 'int'. If a comment of the form '; (<type>) (<arg0>,,,<argN>)' is found, then the
label is converted to a function prototype with the given type and argument list, eg:
this is converted to this
-------------------------------------------|------------------------------------------
counter DCD 0 ; (int) | extern int counter;
|
DotPlot ; (void) (int x,int y) | extern void DotPlot(int x,int y);
|
EXPORT DrawLine ; (void) (void) | extern void DrawLine(void);
|
Note that when 'EXPORT' is used, the (type) and (arg list) comments must follow the
'EXPORT' statement, and NOT be in the label definition line.
Storage areas, data structures and ASM directives are ignored. If you want to declare
constants, or lay out data structures, then do it in a C header (that's the point of
the entire program, BTW ;-)
HeaderGen -CtoASM
===================
This is the most complex action. It is used to convert all 'typedef', 'struct',
'union' and 'enum' definitions and (to a limited degree) macro definitions within a
C header into appropriate ASM code. It also IMPORTs all functions and variables that
are signed as external in the C header.
The program recognizes enum/struct/union templates as well as typedefs. The templates
are referred to in the ASM code with the prefixes 'struct_' or 'union_' or 'enum_'
to avoid ambiguity. Normally only the *non-anonymous* *templates* are converted
to an explicit Asm structure, so if you define a structured type with 'typedef'
plus an anonymous template, eg.
typedef struct { int a,b; } dummy;
then only the size of the type 'dummy' will be declared in the Asm header, unless you
add some template identifier, eg.
typedef struct dummy { int a,b; } dummy;
In this case HeaderGen will also declare offsets to the two structure members a and b.
However, you can change this to taste by calling HeaderGen with the option '-typedef',
which means HeaderGen will explicitly lay out both template structures and typedef
structures. However, this may cause a bit of an overhead.
Structure members are aligned correctly, ie char's are byte-aligned, short int's
are half-word-aligned and all the rest is word-aligned. Alignment gaps are inserted
into the ASM structure code as appropriate.
The members of enumerated data types may optionally have an expression assigned,
which may contain hex and decimal integers and the operators + - * / % << >>.
Union members are not converted (as their offsets are all zero, if I've got it right).
Thus the size of a union is declared as the maximum