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
,
24 const char *prefix
, const char *relative_import_path
)
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 if (relative_import_path
!= NULL
)
36 ::gogo
->set_relative_import_path(relative_import_path
);
39 // Parse the input files.
43 go_parse_input_files(const char** filenames
, unsigned int filename_count
,
44 bool only_check_syntax
, bool)
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 // Check that functions have a terminating statement.
85 ::gogo
->check_return_statements();
87 // Now that we have seen all the names, lower the parse tree into a
88 // form which is easier to use.
89 ::gogo
->lower_parse_tree();
91 // Create function descriptors as needed.
92 ::gogo
->create_function_descriptors();
94 // Write out queued up functions for hash and comparison of types.
95 ::gogo
->write_specific_type_functions();
97 // Now that we have seen all the names, verify that types are
99 ::gogo
->verify_types();
101 // Work out types of unspecified constants and variables.
102 ::gogo
->determine_types();
104 // Check types and issue errors as appropriate.
105 ::gogo
->check_types();
107 if (only_check_syntax
)
110 // Export global identifiers as appropriate.
111 ::gogo
->do_exports();
113 // Turn short-cut operators (&&, ||) into explicit if statements.
114 ::gogo
->remove_shortcuts();
116 // Use temporary variables to force order of evaluation.
117 ::gogo
->order_evaluations();
119 // Convert named types to backend representation.
120 ::gogo
->convert_named_types();
122 // Flatten the parse tree.
125 // Build thunks for functions which call recover.
126 ::gogo
->build_recover_thunks();
128 // Convert complicated go and defer statements into simpler ones.
129 ::gogo
->simplify_thunk_statements();
131 // Dump ast, use filename[0] as the base name
132 ::gogo
->dump_ast(filenames
[0]);
135 // Write out globals.
141 return ::gogo
->write_globals();
144 // Return the global IR structure. This is used by some of the
145 // langhooks to pass to other code.