ObjFW  Check-in [a9e0972112]

Overview
Comment:generators/library: Restructure the code a little
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a9e0972112f1ec81c1c2bf6deadc76bdf23a36530fce692f2b18bb17e0815875
User & Date: js on 2020-12-29 13:53:00
Other Links: manifest | tags
Context
2020-12-29
19:41
-[longLongValueWithBase:]: Fall back to base 10 check-in: 86055ffb5b user: js tags: trunk
13:53
generators/library: Restructure the code a little check-in: a9e0972112 user: js tags: trunk
13:11
Let OFXMLElement take a stream instead of a file check-in: 6b21acb1a9 user: js tags: trunk
Changes

Modified generators/library/LibraryGenerator.m from [4d246f30a8] to [5c3dcfdff0].

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219














220

221
222
223
224
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFFile.h"
#import "OFXMLAttribute.h"
#import "OFXMLElement.h"

#import "OFInvalidFormatException.h"
#import "OFUnsupportedVersionException.h"

#import "copyright.h"

@interface LibraryGenerator: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE(LibraryGenerator)

@implementation LibraryGenerator
- (void)generateLinkLibInDirectory: (OFString *)directory
{
	OFXMLElement *library = [OFXMLElement elementWithFile:
	    [directory stringByAppendingPathComponent: @"library.xml"]];
	OFString *linklibPath = [[directory
	    stringByAppendingPathComponent: @"linklib"]
	    stringByAppendingPathComponent: @"linklib.m"];
	OFFile *linklib = [OFFile fileWithPath: linklibPath
					  mode: @"w"];
	OFArray OF_GENERIC(OFXMLElement *) *functions;
	size_t funcIndex = 0;
	OFString *libBase;

	if (![library.name isEqual: @"amiga-library"] ||
	    library.namespace != nil)
		@throw [OFInvalidFormatException exception];

	OFXMLAttribute *version = [library attributeForName: @"version"];
	if (version == nil)
		@throw [OFInvalidFormatException exception];

	if (![version.stringValue isEqual: @"1.0"])
		@throw [OFUnsupportedVersionException
		    exceptionWithVersion: version.stringValue];

	libBase = [library attributeForName: @"base"].stringValue;

	[linklib writeString: COPYRIGHT];
	[linklib writeString:
	    @"/* This file is automatically generated from library.xml */\n"
	    @"\n"
	    @"#include \"config.h\"\n"
	    @"\n"];

	for (OFXMLElement *include in [library elementsForName: @"include"])
		[linklib writeFormat: @"#import \"%@\"\n", include.stringValue];

	[linklib writeFormat: @"\n"
			      @"extern struct Library *%@;\n"
			      @"\n",
			      libBase];

	functions = [library elementsForName: @"function"];
	for (OFXMLElement *function in functions) {
		OFString *name =
		    [function attributeForName: @"name"].stringValue;
		OFString *returnType =
		    [function attributeForName: @"return-type"].stringValue;
		OFArray OF_GENERIC(OFXMLElement *) *arguments =
		    [function elementsForName: @"argument"];
		size_t argumentIndex;

		if (returnType == nil)
			returnType = @"void";

		[linklib writeFormat: @"%@\n%@(", returnType, name];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argType];
			if (![argType hasSuffix: @"*"])
				[linklib writeString: @" "];
			[linklib writeString: argName];
		}

		[linklib writeFormat:
		    @")\n"
		    @"{\n"
		    @"#if defined(OF_AMIGAOS_M68K)\n"
		    @"\tregister struct Library *a6 __asm__(\"a6\") = %@;\n"
		    @"\t(void)a6;\n"
		    @"\t", libBase];

		if (![returnType isEqual: @"void"])
			[linklib writeString: @"return "];

		[linklib writeString: @"(("];
		[linklib writeString: returnType];
		if (![returnType hasSuffix: @"*"])
			[linklib writeString: @" "];
		[linklib writeString: @"(*)("];

		argumentIndex = 0;
		for (OFXMLElement *argument in arguments) {
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;
			OFString *m68kReg = [argument
			    attributeForName: @"m68k-reg"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argType];
			if (![argType hasSuffix: @"*"])
				[linklib writeString: @" "];
			[linklib writeFormat: @"__asm__(\"%@\")", m68kReg];
		}

		[linklib writeFormat: @"))(((uintptr_t)%@) - %zu))(",
				      libBase, 30 + funcIndex * 6];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argName];
		}

		[linklib writeFormat:
		    @");\n"
		    @"#elif defined(OF_MORPHOS)\n"
		    @"\t__asm__ __volatile__ (\n"
		    @"\t    \"mr\t\t%%%%r12, %%0\"\n"
		    @"\t    :: \"r\"(%@) : \"r12\"\n"
		    @"\t);\n"
		    @"\n"
		    @"\t",
		    libBase, libBase];

		if (![returnType isEqual: @"void"])
			[linklib writeString: @"return "];

		[linklib writeString: @"__extension__ (("];
		[linklib writeString: returnType];
		if (![returnType hasSuffix: @"*"])
			[linklib writeString: @" "];
		[linklib writeString: @"(*)("];

		argumentIndex = 0;
		for (OFXMLElement *argument in arguments) {
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argType];
		}

		[linklib writeFormat: @"))*(void **)(((uintptr_t)%@) - %zu))(",
				      libBase, 28 + funcIndex * 6];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argName];
		}

		[linklib writeString: @");\n"
				      @"#endif\n"];

		if ([function attributeForName: @"noreturn"] != nil)
			[linklib writeString: @"\n\tOF_UNREACHABLE\n"];

		[linklib writeString: @"}\n"];

		if (++funcIndex < functions.count)
			[linklib writeString: @"\n"];
	}
}

- (void)applicationDidFinishLaunching
{














	[self generateLinkLibInDirectory: @"../../src/runtime"];


	[OFApplication terminate];
}
@end







|
|
|


<
<
<
|







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>




14
15
16
17
18
19
20
21
22
23
24
25



26
27
28
29
30
31
32
33





















































































































































































34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFApplication.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFURL.h"
#import "OFXMLElement.h"




#import "LinkLibGenerator.h"

@interface LibraryGenerator: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE(LibraryGenerator)

@implementation LibraryGenerator





















































































































































































- (void)applicationDidFinishLaunching
{
	OFURL *sourcesURL = [[OFFileManager defaultManager].currentDirectoryURL
	    URLByAppendingPathComponent: @"../../src"];
	OFURL *runtimeLibraryPath = [sourcesURL
	    URLByAppendingPathComponent: @"runtime/library.xml"];
	OFURL *runtimeLinkLibPath = [sourcesURL
	    URLByAppendingPathComponent: @"runtime/linklib/linklib.m"];
	OFXMLElement *runtimeLibrary = [OFXMLElement elementWithStream:
	    [OFFile fileWithURL: runtimeLibraryPath
			   mode: @"r"]];
	OFFile *runtimeLinkLib = [OFFile fileWithURL: runtimeLinkLibPath
						mode: @"w"];
	LinkLibGenerator *runtimeLinkLibGenerator = [[[LinkLibGenerator alloc]
	    initWithLibrary: runtimeLibrary
	       outputStream: runtimeLinkLib] autorelease];

	[runtimeLinkLibGenerator generate];

	[OFApplication terminate];
}
@end

Added generators/library/LinkLibGenerator.h version [1ad010b630].































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"
#import "OFStream.h"
#import "OFXMLElement.h"

@interface LinkLibGenerator: OFObject
{
	OFXMLElement *_library;
	OFStream *_outputStream;
}

- (instancetype)initWithLibrary: (OFXMLElement *)library
		   outputStream: (OFStream *)outputStream;
- (void)generate;
@end

Renamed and modified generators/library/LibraryGenerator.m [4d246f30a8] to generators/library/LinkLibGenerator.m [e43125cde8].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

33

34


35

36

37


38



39
40





41


42




43


44


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFApplication.h"
#import "OFArray.h"
#import "OFFile.h"
#import "OFXMLAttribute.h"
#import "OFXMLElement.h"

#import "OFInvalidFormatException.h"
#import "OFUnsupportedVersionException.h"

#import "copyright.h"

@interface LibraryGenerator: OFObject <OFApplicationDelegate>
@end



OF_APPLICATION_DELEGATE(LibraryGenerator)




@implementation LibraryGenerator

- (void)generateLinkLibInDirectory: (OFString *)directory


{



	OFXMLElement *library = [OFXMLElement elementWithFile:
	    [directory stringByAppendingPathComponent: @"library.xml"]];





	OFString *linklibPath = [[directory


	    stringByAppendingPathComponent: @"linklib"]




	    stringByAppendingPathComponent: @"linklib.m"];


	OFFile *linklib = [OFFile fileWithPath: linklibPath


					  mode: @"w"];
	OFArray OF_GENERIC(OFXMLElement *) *functions;
	size_t funcIndex = 0;
	OFString *libBase;

	if (![library.name isEqual: @"amiga-library"] ||
	    library.namespace != nil)
		@throw [OFInvalidFormatException exception];

	OFXMLAttribute *version = [library attributeForName: @"version"];
	if (version == nil)
		@throw [OFInvalidFormatException exception];

	if (![version.stringValue isEqual: @"1.0"])
		@throw [OFUnsupportedVersionException
		    exceptionWithVersion: version.stringValue];

	libBase = [library attributeForName: @"base"].stringValue;

	[linklib writeString: COPYRIGHT];
	[linklib writeString:
	    @"/* This file is automatically generated from library.xml */\n"
	    @"\n"
	    @"#include \"config.h\"\n"
	    @"\n"];

	for (OFXMLElement *include in [library elementsForName: @"include"])
		[linklib writeFormat: @"#import \"%@\"\n", include.stringValue];


	[linklib writeFormat: @"\n"
			      @"extern struct Library *%@;\n"
			      @"\n",
			      libBase];

	functions = [library elementsForName: @"function"];
	for (OFXMLElement *function in functions) {
		OFString *name =
		    [function attributeForName: @"name"].stringValue;
		OFString *returnType =
		    [function attributeForName: @"return-type"].stringValue;
		OFArray OF_GENERIC(OFXMLElement *) *arguments =
		    [function elementsForName: @"argument"];
		size_t argumentIndex;

		if (returnType == nil)
			returnType = @"void";

		[linklib writeFormat: @"%@\n%@(", returnType, name];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argType];
			if (![argType hasSuffix: @"*"])
				[linklib writeString: @" "];
			[linklib writeString: argName];
		}

		[linklib writeFormat:
		    @")\n"
		    @"{\n"
		    @"#if defined(OF_AMIGAOS_M68K)\n"
		    @"\tregister struct Library *a6 __asm__(\"a6\") = %@;\n"
		    @"\t(void)a6;\n"
		    @"\t", libBase];

		if (![returnType isEqual: @"void"])
			[linklib writeString: @"return "];

		[linklib writeString: @"(("];
		[linklib writeString: returnType];
		if (![returnType hasSuffix: @"*"])
			[linklib writeString: @" "];
		[linklib writeString: @"(*)("];

		argumentIndex = 0;
		for (OFXMLElement *argument in arguments) {
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;
			OFString *m68kReg = [argument
			    attributeForName: @"m68k-reg"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argType];
			if (![argType hasSuffix: @"*"])
				[linklib writeString: @" "];
			[linklib writeFormat: @"__asm__(\"%@\")", m68kReg];

		}

		[linklib writeFormat: @"))(((uintptr_t)%@) - %zu))(",
				      libBase, 30 + funcIndex * 6];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argName];
		}

		[linklib writeFormat:
		    @");\n"
		    @"#elif defined(OF_MORPHOS)\n"
		    @"\t__asm__ __volatile__ (\n"
		    @"\t    \"mr\t\t%%%%r12, %%0\"\n"
		    @"\t    :: \"r\"(%@) : \"r12\"\n"
		    @"\t);\n"
		    @"\n"
		    @"\t",
		    libBase, libBase];

		if (![returnType isEqual: @"void"])
			[linklib writeString: @"return "];

		[linklib writeString: @"__extension__ (("];
		[linklib writeString: returnType];
		if (![returnType hasSuffix: @"*"])
			[linklib writeString: @" "];
		[linklib writeString: @"(*)("];

		argumentIndex = 0;
		for (OFXMLElement *argument in arguments) {
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argType];
		}


		[linklib writeFormat: @"))*(void **)(((uintptr_t)%@) - %zu))(",
				      libBase, 28 + funcIndex * 6];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;

			if (argumentIndex++ > 0)
				[linklib writeString: @", "];

			[linklib writeString: argName];
		}

		[linklib writeString: @");\n"
				      @"#endif\n"];

		if ([function attributeForName: @"noreturn"] != nil)
			[linklib writeString: @"\n\tOF_UNREACHABLE\n"];

		[linklib writeString: @"}\n"];

		if (++funcIndex < functions.count)
			[linklib writeString: @"\n"];
	}
}

- (void)applicationDidFinishLaunching
{
	[self generateLinkLibInDirectory: @"../../src/runtime"];

	[OFApplication terminate];
}
@end







<

|
|
|






|
|
>
|
>
|
>
>

>
|
>
|
>
>
|
>
>
>
|
|
>
>
>
>
>
|
>
>
|
>
>
>
>
|
>
>
|
>
>
|


<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|





|
|
>

|
|
|
|

|












|










|

|

|
|


|








|

|
|

|
|









|

|

|
|
>


|
|








|

|


|











|

|
|

|
|







|

|


>
|
|








|

|


|
|


|

|


|

<
<
<
<
<
<
<


13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73














74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228







229
230
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"


#import "OFArray.h"
#import "OFXMLAttribute.h"

#import "LinkLibGenerator.h"

#import "OFInvalidFormatException.h"
#import "OFUnsupportedVersionException.h"

#import "copyright.h"

@implementation LinkLibGenerator
- (instancetype)initWithLibrary: (OFXMLElement *)library
		   outputStream: (OFStream *)outputStream
{
	self = [super init];

	@try {
		OFXMLAttribute *version;

		if (![library.name isEqual: @"amiga-library"] ||
		    library.namespace != nil)
			@throw [OFInvalidFormatException exception];

		if ((version = [library attributeForName: @"version"]) == nil)
			@throw [OFInvalidFormatException exception];

		if (![version.stringValue isEqual: @"1.0"])
			@throw [OFUnsupportedVersionException
			    exceptionWithVersion: version.stringValue];

		_library = [library retain];
		_outputStream = [outputStream retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_library release];
	[_outputStream release];

	[super dealloc];
}

- (void)generate
{
	OFString *libBase = [_library attributeForName: @"base"].stringValue;
	OFArray OF_GENERIC(OFXMLElement *) *functions;
	size_t funcIndex = 0;
















	[_outputStream writeString: COPYRIGHT];
	[_outputStream writeString:
	    @"/* This file is automatically generated from library.xml */\n"
	    @"\n"
	    @"#include \"config.h\"\n"
	    @"\n"];

	for (OFXMLElement *include in [_library elementsForName: @"include"])
		[_outputStream writeFormat: @"#import \"%@\"\n",
					    include.stringValue];

	[_outputStream writeFormat: @"\n"
				    @"extern struct Library *%@;\n"
				    @"\n",
				    libBase];

	functions = [_library elementsForName: @"function"];
	for (OFXMLElement *function in functions) {
		OFString *name =
		    [function attributeForName: @"name"].stringValue;
		OFString *returnType =
		    [function attributeForName: @"return-type"].stringValue;
		OFArray OF_GENERIC(OFXMLElement *) *arguments =
		    [function elementsForName: @"argument"];
		size_t argumentIndex;

		if (returnType == nil)
			returnType = @"void";

		[_outputStream writeFormat: @"%@\n%@(", returnType, name];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;

			if (argumentIndex++ > 0)
				[_outputStream writeString: @", "];

			[_outputStream writeString: argType];
			if (![argType hasSuffix: @"*"])
				[_outputStream writeString: @" "];
			[_outputStream writeString: argName];
		}

		[_outputStream writeFormat:
		    @")\n"
		    @"{\n"
		    @"#if defined(OF_AMIGAOS_M68K)\n"
		    @"\tregister struct Library *a6 __asm__(\"a6\") = %@;\n"
		    @"\t(void)a6;\n"
		    @"\t", libBase];

		if (![returnType isEqual: @"void"])
			[_outputStream writeString: @"return "];

		[_outputStream writeString: @"(("];
		[_outputStream writeString: returnType];
		if (![returnType hasSuffix: @"*"])
			[_outputStream writeString: @" "];
		[_outputStream writeString: @"(*)("];

		argumentIndex = 0;
		for (OFXMLElement *argument in arguments) {
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;
			OFString *m68kReg = [argument
			    attributeForName: @"m68k-reg"].stringValue;

			if (argumentIndex++ > 0)
				[_outputStream writeString: @", "];

			[_outputStream writeString: argType];
			if (![argType hasSuffix: @"*"])
				[_outputStream writeString: @" "];
			[_outputStream writeFormat: @"__asm__(\"%@\")",
						    m68kReg];
		}

		[_outputStream writeFormat: @"))(((uintptr_t)%@) - %zu))(",
					    libBase, 30 + funcIndex * 6];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;

			if (argumentIndex++ > 0)
				[_outputStream writeString: @", "];

			[_outputStream writeString: argName];
		}

		[_outputStream writeFormat:
		    @");\n"
		    @"#elif defined(OF_MORPHOS)\n"
		    @"\t__asm__ __volatile__ (\n"
		    @"\t    \"mr\t\t%%%%r12, %%0\"\n"
		    @"\t    :: \"r\"(%@) : \"r12\"\n"
		    @"\t);\n"
		    @"\n"
		    @"\t",
		    libBase, libBase];

		if (![returnType isEqual: @"void"])
			[_outputStream writeString: @"return "];

		[_outputStream writeString: @"__extension__ (("];
		[_outputStream writeString: returnType];
		if (![returnType hasSuffix: @"*"])
			[_outputStream writeString: @" "];
		[_outputStream writeString: @"(*)("];

		argumentIndex = 0;
		for (OFXMLElement *argument in arguments) {
			OFString *argType =
			    [argument attributeForName: @"type"].stringValue;

			if (argumentIndex++ > 0)
				[_outputStream writeString: @", "];

			[_outputStream writeString: argType];
		}

		[_outputStream writeFormat:
		    @"))*(void **)(((uintptr_t)%@) - %zu))(",
		    libBase, 28 + funcIndex * 6];

		argumentIndex = 0;
		for (OFXMLElement *argument in
		    [function elementsForName: @"argument"]) {
			OFString *argName =
			    [argument attributeForName: @"name"].stringValue;

			if (argumentIndex++ > 0)
				[_outputStream writeString: @", "];

			[_outputStream writeString: argName];
		}

		[_outputStream writeString: @");\n"
					    @"#endif\n"];

		if ([function attributeForName: @"noreturn"] != nil)
			[_outputStream writeString: @"\n\tOF_UNREACHABLE\n"];

		[_outputStream writeString: @"}\n"];

		if (++funcIndex < functions.count)
			[_outputStream writeString: @"\n"];
	}







}
@end

Modified generators/library/Makefile from [f4bd961875] to [1ffdf44043].

1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
include ../../extra.mk

PROG_NOINST = gen_libraries${PROG_SUFFIX}
SRCS = LibraryGenerator.m


.PHONY: run
run: all
	rm -f libobjfw.so.${OBJFW_LIB_MAJOR}
	rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}
	rm -f objfw.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib
	rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}
	rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}
	rm -f objfwrt.dll libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib
	rm -f ${OBJFWRT_AMIGA_LIB}
	if test -f ../../src/libobjfw.so; then \
		${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \
		${LN_S} ../../src/libobjfw.so \
		    libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \
	elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \
		${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \
		    libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \
	fi
	if test -f ../../src/objfw.dll; then \
		${LN_S} ../src/objfw.dll objfw.dll; \
	fi
	if test -f ../../src/libobjfw.dylib; then \
		${LN_S} ../src/libobjfw.dylib \
		    libobjfw.${OBJFW_LIB_MAJOR}.dylib; \
	fi
	if test -f ../../src/runtime/libobjfwrt.so; then \
		${LN_S} ../../src/runtime/libobjfwrt.so \
		    libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \
		${LN_S} ../../src/runtime/libobjfwrt.so \
		    libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \



|
>



















|


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
include ../../extra.mk

PROG_NOINST = gen_libraries${PROG_SUFFIX}
SRCS = LibraryGenerator.m	\
       LinkLibGenerator.m

.PHONY: run
run: all
	rm -f libobjfw.so.${OBJFW_LIB_MAJOR}
	rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}
	rm -f objfw.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib
	rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}
	rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}
	rm -f objfwrt.dll libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib
	rm -f ${OBJFWRT_AMIGA_LIB}
	if test -f ../../src/libobjfw.so; then \
		${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \
		${LN_S} ../../src/libobjfw.so \
		    libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \
	elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \
		${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \
		    libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \
	fi
	if test -f ../../src/objfw.dll; then \
		${LN_S} ../../src/objfw.dll objfw.dll; \
	fi
	if test -f ../../src/libobjfw.dylib; then \
		${LN_S} ../../src/libobjfw.dylib \
		    libobjfw.${OBJFW_LIB_MAJOR}.dylib; \
	fi
	if test -f ../../src/runtime/libobjfwrt.so; then \
		${LN_S} ../../src/runtime/libobjfwrt.so \
		    libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \
		${LN_S} ../../src/runtime/libobjfwrt.so \
		    libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \

Modified generators/unicode/Makefile from [1d508bcb51] to [c6ebd60fbb].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
		${LN_S} ../../src/libobjfw.so \
		    libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \
	elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \
		${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \
		    libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \
	fi
	if test -f ../../src/objfw.dll; then \
		${LN_S} ../src/objfw.dll objfw.dll; \
	fi
	if test -f ../../src/libobjfw.dylib; then \
		${LN_S} ../src/libobjfw.dylib \
		    libobjfw.${OBJFW_LIB_MAJOR}.dylib; \
	fi
	if test -f ../../src/runtime/libobjfwrt.so; then \
		${LN_S} ../../src/runtime/libobjfwrt.so \
		    libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \
		${LN_S} ../../src/runtime/libobjfwrt.so \
		    libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \







|


|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
		${LN_S} ../../src/libobjfw.so \
		    libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \
	elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \
		${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \
		    libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \
	fi
	if test -f ../../src/objfw.dll; then \
		${LN_S} ../../src/objfw.dll objfw.dll; \
	fi
	if test -f ../../src/libobjfw.dylib; then \
		${LN_S} ../../src/libobjfw.dylib \
		    libobjfw.${OBJFW_LIB_MAJOR}.dylib; \
	fi
	if test -f ../../src/runtime/libobjfwrt.so; then \
		${LN_S} ../../src/runtime/libobjfwrt.so \
		    libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \
		${LN_S} ../../src/runtime/libobjfwrt.so \
		    libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \