Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Midas_samy / Source.pm
CommitLineData
86530b38
AT
1# -*- perl -*-
2
3package Midas::Source;
4
5use Midas::Command;
6use Midas::Globals;
7use Midas::Paths;
8use Midas::Error;
9
10use File::Spec;
11use File::Copy;
12use File::Basename;
13
14
15use strict;
16
17use fields qw(ofile args fullsource);
18
19###############################################################################
20
21sub new {
22 my $class = shift;
23 my %args = @_;
24
25 my $this = fields::new($class);
26 foreach my $key (keys %args) {
27 $this->{$key} = $args{$key};
28 }
29
30 return $this;
31}
32
33###############################################################################
34
35sub set_defaults {
36 my $this = shift;
37
38}
39
40###############################################################################
41
42sub get_full_source_file {
43 my $this = shift;
44 return $this->{fullsource};
45}
46
47###############################################################################
48
49sub get_source_file {
50 my $this = shift;
51 return basename $this->get_full_source_file();
52}
53
54###############################################################################
55
56sub get_object_file {
57 my $this = shift;
58 return $this->{ofile};
59}
60
61###############################################################################
62
63sub is_library {
64 my $this = shift;
65 return 0;
66}
67
68###############################################################################
69
70sub from_diag_source {
71 my $this = shift;
72 return 0;
73}
74
75###############################################################################
76
77sub copy_to_build_dir {
78 my $this = shift;
79
80 fatal "Cannot copy_to_build_dir of file generated from diag source\n", M_FILE
81 if $this->from_diag_source();
82
83 my @search = $this->get_search_paths();
84 my $full_source = $this->get_full_source_file();
85 my $local_source = path_to_build_file($this->get_source_file(), $STATE);
86
87 foreach my $testdir (@search) {
88 my $testfile = File::Spec->catfile($testdir, $full_source);
89 if(-e $testfile) {
90 chat "Copying $testfile to $local_source\n";
91 copy($testfile, $local_source);
92 last;
93 }
94 }
95 if(not -e $local_source) {
96 fatal "Could not find \"$full_source\" in search path: @search\n", M_FILE;
97 }
98
99}
100
101###############################################################################
102
103sub get_search_paths {
104 my $this = shift;
105 fatal "Cannot get_search_paths of abstract superclass\n", M_CODE;
106}
107
108###############################################################################
109
110sub process_source {
111 my $this = shift;
112}
113
114###############################################################################
115
116sub build {
117 my $this = shift;
118 fatal "Cannot build source file in abstract superclass\n", M_CODE;
119}
120
121###############################################################################
122
123sub debug_string {
124 my $this = shift;
125
126 my $str = "O=$this->{ofile} ";
127 $str .= "ARGS=\"$this->{args}\" " if defined $this->{args};
128
129 return $str;
130}
131###############################################################################
132###############################################################################
133
134package Midas::Source::Assembly;
135
136use strict;
137
138use Midas::Paths;
139use Midas::Globals;
140use Midas::Command;
141use Midas::Error;
142
143use base 'Midas::Source';
144use fields qw(sfile);
145
146###############################################################################
147
148sub new {
149 my $class = shift;
150 my %args = @_;
151
152 my $this = fields::new($class);
153 foreach my $key (keys %args) {
154 $this->{$key} = $args{$key};
155 }
156
157 return $this;
158}
159
160###############################################################################
161
162sub set_defaults {
163 my $this = shift;
164 $this->SUPER::set_defaults();
165}
166
167###############################################################################
168
169sub get_search_paths {
170 my $this = shift;
171 return;
172}
173
174###############################################################################
175
176sub from_diag_source {
177 my $this = shift;
178 return 1;
179}
180
181###############################################################################
182
183sub debug_string {
184 my $this = shift;
185
186 my $str = "ASM: S=$this->{sfile} ";
187 $str .= $this->SUPER::debug_string();
188 return $str;
189}
190
191###############################################################################
192
193# This function may be called from a child thread, sot it is important
194# that it doesn't write any state (i.e., have any side-effects)
195sub build {
196 my $this = shift;
197 my $pushd = Midas::Paths->pushd($STATE->get_build_dir);
198
199 my $source = $this->get_source_file();
200 my $cmd = "$CONFIG{as_cmd} ";
201 $cmd .= "$this->{args} " if defined $this->{args};
202 $cmd .= join ' ', @{$CONFIG{as_opt}};
203 $cmd .= " $source -o $this->{ofile}";
204
205 run_command($cmd, -errcode => M_ASMFAIL);
206}
207
208###############################################################################
209###############################################################################
210
211package Midas::Source::C;
212
213use strict;
214
215use Midas::Globals;
216use Midas::Preprocess ':all';
217use Midas::Command;
218use Midas::Paths;
219use Midas::Error;
220
221
222use base 'Midas::Source';
223use fields qw(cfile sfile);
224
225###############################################################################
226
227sub new {
228 my $class = shift;
229 my %args = @_;
230
231 my $this = fields::new($class);
232 foreach my $key (keys %args) {
233 $this->{$key} = $args{$key};
234 }
235
236 return $this;
237}
238
239###############################################################################
240
241sub set_defaults {
242 my $this = shift;
243
244 $this->SUPER::set_defaults();
245}
246
247###############################################################################
248
249sub get_search_paths {
250 my $this = shift;
251 return get_includes($CONFIG{csrc_includes});
252}
253
254###############################################################################
255
256sub process_source {
257 my $this = shift;
258 # Run gcc -S if assembly
259
260 if(defined $this->{sfile}) {
261 my $cmd = $CONFIG{gcc_cmd};
262 my $gccopt = join ' ', @{$CONFIG{gcc_opt}};
263
264 my @incs = map { "-I$_" } get_includes($CONFIG{c_includes});
265
266 # Don't use cfile directly, since it may contain path seperator.
267 my $c_file = $this->get_source_file();
268
269 $cmd .= " $gccopt @incs " if defined $gccopt;
270 $cmd .= " $this->{args} " if defined $this->{args};
271 $cmd .= " $c_file -o $this->{sfile}";
272
273 $cmd =~ s/\s+/ /g;
274
275 chat "Compiling C code $c_file to generate $this->{sfile}\n";
276 run_command($cmd, -errcode => M_CCFAIL);
277 }
278}
279
280###############################################################################
281
282# This function may be called from a child thread, sot it is important
283# that it doesn't write any state (i.e., have any side-effects)
284sub build {
285 my $this = shift;
286 my $pushd = Midas::Paths->pushd($STATE->get_build_dir);
287
288 if(defined $this->{sfile}) {
289 # Already compiled to assembly - now just assemble
290
291 my $args = join ' ', @{$CONFIG{as_opt}};
292 run_command("$CONFIG{as_cmd} $args $this->{sfile} -o $this->{ofile}",
293 -errcode => M_ASMFAIL);
294
295 } else {
296 # Need to compile from .c
297
298 my $cfile = $this->get_source_file();
299
300 my $cmd = $CONFIG{gcc_cmd};
301 my $gccopt = join ' ', @{$CONFIG{gcc_opt}};
302 my @incs = map { "-I$_" } get_includes($CONFIG{c_includes});
303 $cmd .= " $gccopt @incs " if defined $gccopt;
304 $cmd .= " -c $cfile -o $this->{ofile}";
305 $cmd =~ s/\s+/ /g;
306 run_command($cmd, -errcode => M_CCFAIL);
307 }
308
309}
310
311###############################################################################
312
313sub debug_string {
314 my $this = shift;
315
316 my $str = "C: C=$this->{cfile} ";
317 $str .= "S=$this->{sfile} " if defined $this->{sfile};
318 $str .= $this->SUPER::debug_string();
319 return $str;
320}
321
322###############################################################################
323###############################################################################
324
325package Midas::Source::Object;
326
327use strict;
328
329use Midas::Globals;
330use Midas::Preprocess ':all';
331
332
333use base 'Midas::Source';
334use fields qw();
335
336###############################################################################
337
338sub new {
339 my $class = shift;
340 my %args = @_;
341
342 my $this = fields::new($class);
343 foreach my $key (keys %args) {
344 $this->{$key} = $args{$key};
345 }
346
347 return $this;
348}
349
350###############################################################################
351
352sub set_defaults {
353 my $this = shift;
354
355 $this->SUPER::set_defaults();
356}
357
358###############################################################################
359
360sub build {
361 my $this = shift;
362}
363
364###############################################################################
365
366sub get_search_paths {
367 my $this = shift;
368 return get_includes($CONFIG{link_paths});
369}
370
371###############################################################################
372
373sub debug_string {
374 my $this = shift;
375 my $str = "O: ";
376 $str .= $this->SUPER::debug_string();
377 return $str;
378}
379
380###############################################################################
381###############################################################################
382
383package Midas::Source::Library;
384
385use strict;
386
387use Midas::Globals;
388use Midas::Preprocess ':all';
389
390
391use base 'Midas::Source';
392use fields qw();
393
394###############################################################################
395
396sub new {
397 my $class = shift;
398 my %args = @_;
399
400 my $this = fields::new($class);
401 foreach my $key (keys %args) {
402 $this->{$key} = $args{$key};
403 }
404
405 return $this;
406}
407
408###############################################################################
409
410sub set_defaults {
411 my $this = shift;
412
413 $this->SUPER::set_defaults();
414}
415
416###############################################################################
417
418sub build {
419 my $this = shift;
420}
421
422###############################################################################
423
424sub get_search_paths {
425 my $this = shift;
426
427 return get_includes($CONFIG{link_paths});
428}
429
430###############################################################################
431
432sub debug_string {
433 my $this = shift;
434 my $str = "L: ";
435 $str .= $this->SUPER::debug_string();
436 return $str;
437}
438
439###############################################################################
440
441sub is_library {
442 my $this = shift;
443 return 1; # libraries need to link after everything else
444}
445
446###############################################################################
447###############################################################################
4481;