OSDN Git Service

More uses of backend interface for types.
[pf3gnuchains/gcc-fork.git] / libgo / runtime / go-main.c
1 /* go-main.c -- the main function for a Go program.
2
3    Copyright 2009 The Go Authors. All rights reserved.
4    Use of this source code is governed by a BSD-style
5    license that can be found in the LICENSE file.  */
6
7 #include "config.h"
8
9 #include <stdlib.h>
10 #include <time.h>
11
12 #ifdef HAVE_FPU_CONTROL_H
13 #include <fpu_control.h>
14 #endif
15
16 #include "go-alloc.h"
17 #include "array.h"
18 #include "go-signal.h"
19 #include "go-string.h"
20
21 #include "runtime.h"
22 #include "malloc.h"
23
24 #undef int
25 #undef char
26 #undef unsigned
27
28 /* The main function for a Go program.  This records the command line
29    parameters, calls the real main function, and returns a zero status
30    if the real main function returns.  */
31
32 extern char **environ;
33
34 extern struct __go_open_array Args asm ("libgo_os.os.Args");
35
36 extern struct __go_open_array Envs asm ("libgo_os.os.Envs");
37
38 /* These functions are created for the main package.  */
39 extern void __go_init_main (void);
40 extern void real_main (void) asm ("main.main");
41
42 /* The main function.  */
43
44 int
45 main (int argc, char **argv)
46 {
47   int i;
48   struct __go_string *values;
49
50   runtime_mallocinit ();
51   runtime_cpuprofinit ();
52   __go_gc_goroutine_init (&argc);
53
54   Args.__count = argc;
55   Args.__capacity = argc;
56   values = __go_alloc (argc * sizeof (struct __go_string));
57   for (i = 0; i < argc; ++i)
58     {
59       values[i].__data = (unsigned char *) argv[i];
60       values[i].__length = __builtin_strlen (argv[i]);
61     }
62   Args.__values = values;
63
64   for (i = 0; environ[i] != NULL; ++i)
65     ;
66   Envs.__count = i;
67   Envs.__capacity = i;
68   values = __go_alloc (i * sizeof (struct __go_string));
69   for (i = 0; environ[i] != NULL; ++i)
70     {
71       values[i].__data = (unsigned char *) environ[i];
72       values[i].__length = __builtin_strlen (environ[i]);
73     }
74   Envs.__values = values;
75
76   __initsig ();
77
78 #if defined(HAVE_SRANDOM)
79   srandom ((unsigned int) time (NULL));
80 #else
81   srand ((unsigned int) time (NULL));
82 #endif
83   __go_init_main ();
84
85   __go_enable_gc ();
86
87   real_main ();
88
89   return 0;
90 }