git @ Cat's Eye Technologies SixtyPical / 1098347
Routines can be declared `preserved`. Chris Pressey 2 years ago
5 changed file(s) with 55 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
77 approximates the set of routines which are not called
88 by any other routine, with an eye to omitting them from
99 the final executable.
10 * A routine can be declared `preserved`, which prevents a
11 compiler from omitting it from the final executable, even
12 if it determines it is not called by any other routine.
1013 * The `dcc6502-adapter` test adapter was updated to conform
1114 to the output of the latest version of `dcc6502`.
1215
3232 potential_calls = node['potentially-calls']
3333 if routine.name in potential_calls:
3434 potentially_called_by.append(name)
35 if getattr(routine, 'explicitly_marked_as_called', None) or routine.name == 'main':
36 potentially_called_by.append('*marked*')
35 if getattr(routine, 'preserved', None) or routine.name == 'main':
36 potentially_called_by.append('*preserved*')
3737 graph[routine.name]['potentially-called-by'] = potentially_called_by
3838
3939 return graph
110110 name = self.scanner.token
111111 self.scanner.scan()
112112 self.current_routine_name = name
113 preserved = False
114 if self.scanner.consume('preserved'):
115 preserved = True
113116 type_, routine = self.routine(name)
114117 self.declare(name, routine, type_)
118 routine.preserved = preserved
115119 routines.append(routine)
116120 self.current_routine_name = None
117121 self.scanner.check_type('EOF')
1111
1212 The `main` routine is always called. The thing that it will
1313 be called by is the system, but the callgraph analyzer will
14 simply consider it to be "marked as called".
14 simply consider it to be "marked as preserved".
1515
1616 | define main routine
1717 | {
1919 = {
2020 = "main": {
2121 = "potentially-called-by": [
22 = "*marked*"
22 = "*preserved*"
2323 = ],
2424 = "potentially-calls": []
2525 = }
3838 = {
3939 = "main": {
4040 = "potentially-called-by": [
41 = "*marked*"
41 = "*preserved*"
4242 = ],
4343 = "potentially-calls": [
4444 = "other"
6767 = {
6868 = "main": {
6969 = "potentially-called-by": [
70 = "*marked*"
70 = "*preserved*"
7171 = ],
7272 = "potentially-calls": []
7373 = },
7474 = "other": {
7575 = "potentially-called-by": [],
76 = "potentially-calls": []
77 = }
78 = }
79
80 If a routine is not called by another routine, but it is declared
81 explicitly as `preserved`, then it will not be considered unused,
82 and a compiler or linker will not be permitted to omit it from
83 the final executable. This is useful for interrupt routines and
84 such that really are used by some part of the system, even if not
85 directly by another SixtyPical routine.
86
87 | define main routine
88 | {
89 | }
90 |
91 | define other preserved routine
92 | {
93 | }
94 = {
95 = "main": {
96 = "potentially-called-by": [
97 = "*preserved*"
98 = ],
99 = "potentially-calls": []
100 = },
101 = "other": {
102 = "potentially-called-by": [
103 = "*preserved*"
104 = ],
76105 = "potentially-calls": []
77106 = }
78107 = }
97126 = {
98127 = "main": {
99128 = "potentially-called-by": [
100 = "*marked*"
129 = "*preserved*"
101130 = ],
102131 = "potentially-calls": []
103132 = },
7070 | outputs a
7171 | trashes x
7272 | @ 65487
73 = ok
74
75 Preserved routine.
76
77 | define main routine {
78 | ld a, $ff
79 | add a, $01
80 | }
81 | define foo preserved routine {
82 | ld a, 0
83 | add a, 1
84 | }
7385 = ok
7486
7587 Trash.