xref: /netbsd/external/bsd/pcc/dist/pcc/driver/prog_asm.c (revision 6935091c)
1 /*	Id	*/
2 /*	$NetBSD: prog_asm.c,v 1.1.1.1 2016/02/09 20:29:12 plunky Exp $	*/
3 
4 /*-
5  * Copyright (c) 2014 Iain Hibbert.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #include "driver.h"
27 
28 static int
asm_exec(const char * infile,const char * outfile)29 asm_exec(const char *infile, const char *outfile)
30 {
31 	list_t *l;
32 	const char *file;
33 	int rv;
34 
35 	if (opt.prog_asm == NULL)
36 		error("No assembler is defined");
37 
38 	l = list_alloc();
39 
40 	list_add_file(l, opt.prog_asm, &progdirs, X_OK);
41 
42 	Wflag_add(l, W_ASM);
43 
44 	list_add_list(l, opt.Wa);
45 
46 	{
47 		-p gnu
48 		-f <type>
49 #if defined(USE_YASM)
50 		av[na++] = "-p";
51 		av[na++] = "gnu";
52 
53 		av[na++] = "-f";
54 #if defined(os_win32)
55 		av[na++] = "win32";
56 #elif defined(os_darwin)
57 		av[na++] = "macho";
58 #else
59 		av[na++] = "elf";
60 #endif
61 #endif
62 
63 #if defined(os_sunos) && defined(mach_sparc64)
64 		av[na++] = "-m64";
65 #endif
66 
67 #if defined(os_darwin)
68 		if (Bstatic)
69 			av[na++] = "-static";
70 #endif
71 
72 #if !defined(USE_YASM)
73 		if (vflag)
74 			av[na++] = "-v";
75 #endif
76 		if (kflag)
77 			av[na++] = "-k";
78 
79 #ifdef os_darwin
80 		av[na++] = "-arch";
81 #if mach_amd64
82 		av[na++] = amd64_i386 ? "i386" : "x86_64";
83 #else
84 		av[na++] = "i386";
85 #endif
86 #else
87 #ifdef mach_amd64
88 		if (amd64_i386)
89 			av[na++] = "--32";
90 #endif
91 #endif
92 
93 		av[na++] = "-o";
94 		if (outfile && cflag)
95 			ermfile = av[na++] = outfile;
96 		else if (cflag)
97 			ermfile = av[na++] = olist[i] = setsuf(clist[i], 'o');
98 		else
99 			ermfile = av[na++] = olist[i] = gettmp();
100 		av[na++] = assource;
101 		av[na++] = 0;
102 
103 		if (callsys(as, av)) {
104 			cflag++;
105 			eflag++;
106 			cunlink(tmp4);
107 			continue;
108 		}
109 	}
110 
111 	if (infile != NULL)
112 		list_add(l, infile);
113 	else if (outfile != NULL)
114 		list_add(l, "-");
115 
116 	if (outfile != NULL) {
117 		list_add(l, "-o");
118 		list_add(l, outfile);
119 	}
120 
121 	rv = list_exec(l);
122 	list_free(l);
123 	return rv;
124 }
125