*** empty log message ***
[fw/sdcc] / doc / random-notes.txt
1 Random notes
2 ------------
3 A random set of notes about sdcc and how it works.
4
5 Sandeep:
6 --------
7 Adding memory maps for AVR, setup default map for
8 local & global variables in port.h will be initialised
9 by the _<port>_finaliseOptions() [good functions]..some
10 kludges remain because of the "overlay" segment for 8051.
11
12 The memory segment stuff will have to be made more flexible.
13 Currently there does not seem to be a 1-to-1 correspondence 
14 between storage class & memory map. (should there be??).
15
16 Also Added check for memory map in SDCCmem.c allocLocal
17 and allocglobal for "eeprom" memory space (AVR).
18
19
20
21 Michael:
22 --------
23 Tracing parmBytes and function calls.
24
25 Bug:
26 void printf(const char *format);
27
28 void puts(const char *s)
29 {
30         printf(s);
31 }
32
33 Generates the pseudo-code:
34           hl = s
35           push hl
36           call printf
37           pop l (not hl - so parmBytes is too small)
38
39 parmBytes for a function call seems to be setup in geniCodeCall in
40 SDCCicode.c.
41
42 geniCodeCall:
43 * Takes care of calls with side effects (?)
44 * Generates the icode to push the parameters (this also computes the 
45   resulting stack size)
46 * Generates a CALL or PCALL depending on if its a function or pointer to.
47 * Computes the result
48 * Adds the code for the call to the chain.
49
50 My bug is probably in geniCodeParms - it's probably computing the
51 size of pointers wrong.
52
53 geniCodeParms:
54 * A 'parm' node causes this to be run on the tree branches.
55 * It switches on the stack mode and sendto mode, and adds the
56   instructions required to push or put.
57 * A push adds the result of 'getSize' to the stack size.
58
59 So the bug is probably in getSize.  's' is not an aggregate, so the
60 bug is in getSize().
61
62 It seems that IS_SPEC() is being set, deferencing *s so that it's size
63 is sizeof(char) == 1.  It's either a SPECIFIER or a DECLARATOR - seems that
64 were the wrong way around.  This is set in SDCCsymt.c, SDCCval.c, and the 
65 yacc file. SDCCsymt.c and SDCCval.c havnt really changed in 5 days - must
66 be SDCC.y.  Nope, no changes.  diff against 5 days ago shows only intersting
67 changes are in SDCCicode.  Same with -14 days.
68
69 Michael
70 -------
71 Next bug is global function parameters not being pushed correctly. i.e
72
73 unsigned int counter;
74
75 void print(void)
76 {
77         printf("Counter is %u\n", counter);
78 }
79 generates:
80 _print::
81         ld hl,#_counter
82         push hl
83         ld hl,#str_1
84         push hl
85         call printf
86         fix, ret
87
88 which is more like:
89         printf("Counter is %u\n", &counter);
90         
91 First looking in SDCCicode.c for the stuff that generates function calls:
92 Probably a bug in geniCodeParams.
93 Nope, a bug in my stuff :)