OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [go/] [gofrontend/] [go.cc] - Blame information for rev 714

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 714 jeremybenn
// go.cc -- Go frontend main file for gcc.
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 "go-system.h"
8
 
9
#include "go-c.h"
10
 
11
#include "lex.h"
12
#include "parse.h"
13
#include "backend.h"
14
#include "gogo.h"
15
 
16
// The unique prefix to use for exported symbols.  This is set during
17
// option processing.
18
 
19
static std::string unique_prefix;
20
 
21
// The data structures we build to represent the file.
22
static Gogo* gogo;
23
 
24
// Create the main IR data structure.
25
 
26
GO_EXTERN_C
27
void
28
go_create_gogo(int int_type_size, int pointer_size)
29
{
30
  go_assert(::gogo == NULL);
31
  Linemap* linemap = go_get_linemap();
32
  ::gogo = new Gogo(go_get_backend(), linemap, int_type_size, pointer_size);
33
  if (!unique_prefix.empty())
34
    ::gogo->set_unique_prefix(unique_prefix);
35
 
36
  // FIXME: This should be in the gcc dependent code.
37
  ::gogo->define_builtin_function_trees();
38
}
39
 
40
// Set the unique prefix we use for exported symbols.
41
 
42
GO_EXTERN_C
43
void
44
go_set_prefix(const char* arg)
45
{
46
  unique_prefix = arg;
47
  for (size_t i = 0; i < unique_prefix.length(); ++i)
48
    {
49
      char c = unique_prefix[i];
50
      if ((c >= 'a' && c <= 'z')
51
          || (c >= 'A' && c <= 'Z')
52
          || (c >= '0' && c <= '9')
53
          || c == '_')
54
        ;
55
      else
56
        unique_prefix[i] = '_';
57
    }
58
}
59
 
60
// Parse the input files.
61
 
62
GO_EXTERN_C
63
void
64
go_parse_input_files(const char** filenames, unsigned int filename_count,
65
                     bool only_check_syntax, bool require_return_statement)
66
{
67
  go_assert(filename_count > 0);
68
 
69
  for (unsigned int i = 0; i < filename_count; ++i)
70
    {
71
      if (i > 0)
72
        ::gogo->clear_file_scope();
73
 
74
      const char* filename = filenames[i];
75
      FILE* file;
76
      if (strcmp(filename, "-") == 0)
77
        file = stdin;
78
      else
79
        {
80
          file = fopen(filename, "r");
81
          if (file == NULL)
82
            fatal_error("cannot open %s: %m", filename);
83
        }
84
 
85
      Lex lexer(filename, file, ::gogo->linemap());
86
 
87
      Parse parse(&lexer, ::gogo);
88
      parse.program();
89
 
90
      if (strcmp(filename, "-") != 0)
91
        fclose(file);
92
    }
93
 
94
  ::gogo->linemap()->stop();
95
 
96
  ::gogo->clear_file_scope();
97
 
98
  // If the global predeclared names are referenced but not defined,
99
  // define them now.
100
  ::gogo->define_global_names();
101
 
102
  // Finalize method lists and build stub methods for named types.
103
  ::gogo->finalize_methods();
104
 
105
  // Now that we have seen all the names, lower the parse tree into a
106
  // form which is easier to use.
107
  ::gogo->lower_parse_tree();
108
 
109
  // Write out queued up functions for hash and comparison of types.
110
  ::gogo->write_specific_type_functions();
111
 
112
  // Now that we have seen all the names, verify that types are
113
  // correct.
114
  ::gogo->verify_types();
115
 
116
  // Work out types of unspecified constants and variables.
117
  ::gogo->determine_types();
118
 
119
  // Check types and issue errors as appropriate.
120
  ::gogo->check_types();
121
 
122
  if (only_check_syntax)
123
    return;
124
 
125
  // Check that functions have return statements.
126
  if (require_return_statement)
127
    ::gogo->check_return_statements();
128
 
129
  // Export global identifiers as appropriate.
130
  ::gogo->do_exports();
131
 
132
  // Turn short-cut operators (&&, ||) into explicit if statements.
133
  ::gogo->remove_shortcuts();
134
 
135
  // Use temporary variables to force order of evaluation.
136
  ::gogo->order_evaluations();
137
 
138
  // Build thunks for functions which call recover.
139
  ::gogo->build_recover_thunks();
140
 
141
  // Convert complicated go and defer statements into simpler ones.
142
  ::gogo->simplify_thunk_statements();
143
 
144
  // Dump ast, use filename[0] as the base name
145
  ::gogo->dump_ast(filenames[0]);
146
}
147
 
148
// Write out globals.
149
 
150
GO_EXTERN_C
151
void
152
go_write_globals()
153
{
154
  return ::gogo->write_globals();
155
}
156
 
157
// Return the global IR structure.  This is used by some of the
158
// langhooks to pass to other code.
159
 
160
Gogo*
161
go_get_gogo()
162
{
163
  return ::gogo;
164
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.