1 // go.cc -- Go frontend main file for gcc.
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.
16 // The data structures we build to represent the file.
19 // Create the main IR data structure.
23 go_create_gogo(int int_type_size, int pointer_size, const char *pkgpath,
26 go_assert(::gogo == NULL);
27 Linemap* linemap = go_get_linemap();
28 ::gogo = new Gogo(go_get_backend(), linemap, int_type_size, pointer_size);
31 ::gogo->set_pkgpath(pkgpath);
32 else if (prefix != NULL)
33 ::gogo->set_prefix(prefix);
35 // FIXME: This should be in the gcc dependent code.
36 ::gogo->define_builtin_function_trees();
39 // Parse the input files.
43 go_parse_input_files(const char** filenames, unsigned int filename_count,
44 bool only_check_syntax, bool require_return_statement)
46 go_assert(filename_count > 0);
48 for (unsigned int i = 0; i < filename_count; ++i)
51 ::gogo->clear_file_scope();
53 const char* filename = filenames[i];
55 if (strcmp(filename, "-") == 0)
59 file = fopen(filename, "r");
61 fatal_error("cannot open %s: %m", filename);
64 Lex lexer(filename, file, ::gogo->linemap());
66 Parse parse(&lexer, ::gogo);
69 if (strcmp(filename, "-") != 0)
73 ::gogo->linemap()->stop();
75 ::gogo->clear_file_scope();
77 // If the global predeclared names are referenced but not defined,
79 ::gogo->define_global_names();
81 // Finalize method lists and build stub methods for named types.
82 ::gogo->finalize_methods();
84 // Now that we have seen all the names, lower the parse tree into a
85 // form which is easier to use.
86 ::gogo->lower_parse_tree();
88 // Write out queued up functions for hash and comparison of types.
89 ::gogo->write_specific_type_functions();
91 // Now that we have seen all the names, verify that types are
93 ::gogo->verify_types();
95 // Work out types of unspecified constants and variables.
96 ::gogo->determine_types();
98 // Check types and issue errors as appropriate.
99 ::gogo->check_types();
101 if (only_check_syntax)
104 // Check that functions have return statements.
105 if (require_return_statement)
106 ::gogo->check_return_statements();
108 // Export global identifiers as appropriate.
109 ::gogo->do_exports();
111 // Turn short-cut operators (&&, ||) into explicit if statements.
112 ::gogo->remove_shortcuts();
114 // Use temporary variables to force order of evaluation.
115 ::gogo->order_evaluations();
117 // Build thunks for functions which call recover.
118 ::gogo->build_recover_thunks();
120 // Convert complicated go and defer statements into simpler ones.
121 ::gogo->simplify_thunk_statements();
123 // Dump ast, use filename[0] as the base name
124 ::gogo->dump_ast(filenames[0]);
127 // Write out globals.
133 return ::gogo->write_globals();
136 // Return the global IR structure. This is used by some of the
137 // langhooks to pass to other code.