Blah. Pre 2.92.
[fw/sdcc] / doc / random-notes.txt
1 Random notes
2 ------------
3
4 A random set of notes about sdcc and how it works.
5
6 Michael:
7 --------
8 Tracing parmBytes and function calls.
9
10 Bug:
11 void printf(const char *format);
12
13 void puts(const char *s)
14 {
15         printf(s);
16 }
17
18 Generates the pseudo-code:
19           hl = s
20           push hl
21           call printf
22           pop l (not hl - so parmBytes is too small)
23
24 parmBytes for a function call seems to be setup in geniCodeCall in
25 SDCCicode.c.
26
27 geniCodeCall:
28 * Takes care of calls with side effects (?)
29 * Generates the icode to push the parameters (this also computes the 
30   resulting stack size)
31 * Generates a CALL or PCALL depending on if its a function or pointer to.
32 * Computes the result
33 * Adds the code for the call to the chain.
34
35 My bug is probably in geniCodeParms - it's probably computing the
36 size of pointers wrong.
37
38 geniCodeParms:
39 * A 'parm' node causes this to be run on the tree branches.
40 * It switches on the stack mode and sendto mode, and adds the
41   instructions required to push or put.
42 * A push adds the result of 'getSize' to the stack size.
43
44 So the bug is probably in getSize.  's' is not an aggregate, so the
45 bug is in getSize().
46
47 It seems that IS_SPEC() is being set, deferencing *s so that it's size
48 is sizeof(char) == 1.  It's either a SPECIFIER or a DECLARATOR - seems that
49 were the wrong way around.  This is set in SDCCsymt.c, SDCCval.c, and the 
50 yacc file. SDCCsymt.c and SDCCval.c havnt really changed in 5 days - must
51 be SDCC.y.  Nope, no changes.  diff against 5 days ago shows only intersting
52 changes are in SDCCicode.  Same with -14 days.
53
54 Michael
55 -------
56 Next bug is global function parameters not being pushed correctly. i.e
57
58 unsigned int counter;
59
60 void print(void)
61 {
62         printf("Counter is %u\n", counter);
63 }
64 generates:
65 _print::
66         ld hl,#_counter
67         push hl
68         ld hl,#str_1
69         push hl
70         call printf
71         fix, ret
72
73 which is more like:
74         printf("Counter is %u\n", &counter);
75         
76 First looking in SDCCicode.c for the stuff that generates function calls:
77 Probably a bug in geniCodeParams.
78 Nope, a bug in my stuff :)