Mercurial > hg > CbC > CbC_gcc
comparison gcc/go/gofrontend/gogo.h @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
10 #include "go-linemap.h" | 10 #include "go-linemap.h" |
11 | 11 |
12 class Traverse; | 12 class Traverse; |
13 class Statement_inserter; | 13 class Statement_inserter; |
14 class Type; | 14 class Type; |
15 class Type_hash_identical; | |
16 class Type_equal; | 15 class Type_equal; |
17 class Type_identical; | |
18 class Typed_identifier; | 16 class Typed_identifier; |
19 class Typed_identifier_list; | 17 class Typed_identifier_list; |
20 class Function_type; | 18 class Function_type; |
21 class Expression; | 19 class Expression; |
22 class Expression_list; | 20 class Expression_list; |
115 }; | 113 }; |
116 | 114 |
117 // For sorting purposes. | 115 // For sorting purposes. |
118 | 116 |
119 struct Import_init_lt { | 117 struct Import_init_lt { |
120 bool operator()(const Import_init* i1, const Import_init* i2) | 118 bool operator()(const Import_init* i1, const Import_init* i2) const |
121 { | 119 { |
122 return i1->init_name() < i2->init_name(); | 120 return i1->init_name() < i2->init_name(); |
123 } | 121 } |
124 }; | 122 }; |
125 | 123 |
316 // Set the level of escape analysis debugging from a command line option. | 314 // Set the level of escape analysis debugging from a command line option. |
317 void | 315 void |
318 set_debug_escape_level(int level) | 316 set_debug_escape_level(int level) |
319 { this->debug_escape_level_ = level; } | 317 { this->debug_escape_level_ = level; } |
320 | 318 |
319 // Return the hash for debug escape analysis. | |
320 std::string | |
321 debug_escape_hash() const | |
322 { return this->debug_escape_hash_; } | |
323 | |
324 // Set the hash value for debug escape analysis. | |
325 void | |
326 set_debug_escape_hash(const std::string& s) | |
327 { this->debug_escape_hash_ = s; } | |
328 | |
329 // Return the size threshold used to determine whether to issue | |
330 // a nil-check for a given pointer dereference. A threshold of -1 | |
331 // implies that all potentially faulting dereference ops should | |
332 // be nil-checked. A positive threshold of N implies that a deref | |
333 // of *P where P has size less than N doesn't need a nil check. | |
334 int64_t | |
335 nil_check_size_threshold() const | |
336 { return this->nil_check_size_threshold_; } | |
337 | |
338 // Set the nil-check size threshold, as described above. | |
339 void | |
340 set_nil_check_size_threshold(int64_t bytes) | |
341 { this->nil_check_size_threshold_ = bytes; } | |
342 | |
321 // Import a package. FILENAME is the file name argument, LOCAL_NAME | 343 // Import a package. FILENAME is the file name argument, LOCAL_NAME |
322 // is the local name to give to the package. If LOCAL_NAME is empty | 344 // is the local name to give to the package. If LOCAL_NAME is empty |
323 // the declarations are added to the global scope. | 345 // the declarations are added to the global scope. |
324 void | 346 void |
325 import_package(const std::string& filename, const std::string& local_name, | 347 import_package(const std::string& filename, const std::string& local_name, |
656 // Add notes about the escape level of a function's input and output | 678 // Add notes about the escape level of a function's input and output |
657 // parameters for exporting and importing top level functions. | 679 // parameters for exporting and importing top level functions. |
658 void | 680 void |
659 tag_function(Escape_context*, Named_object*); | 681 tag_function(Escape_context*, Named_object*); |
660 | 682 |
683 // Reclaim memory of escape analysis Nodes. | |
684 void | |
685 reclaim_escape_nodes(); | |
686 | |
661 // Do all exports. | 687 // Do all exports. |
662 void | 688 void |
663 do_exports(); | 689 do_exports(); |
664 | 690 |
665 // Add an import control function for an imported package to the | 691 // Add an import control function for an imported package to the |
771 std::string | 797 std::string |
772 function_descriptor_name(Named_object*); | 798 function_descriptor_name(Named_object*); |
773 | 799 |
774 // Return the name to use for a generated stub method. | 800 // Return the name to use for a generated stub method. |
775 std::string | 801 std::string |
776 stub_method_name(const std::string& method_name); | 802 stub_method_name(const Package*, const std::string& method_name); |
777 | 803 |
778 // Return the names of the hash and equality functions for TYPE. | 804 // Return the names of the hash and equality functions for TYPE. |
779 void | 805 void |
780 specific_type_function_names(const Type*, const Named_type*, | 806 specific_type_function_names(const Type*, const Named_type*, |
781 std::string* hash_name, | 807 std::string* hash_name, |
796 is_erroneous_name(const std::string&); | 822 is_erroneous_name(const std::string&); |
797 | 823 |
798 // Return a name to use for a thunk function. A thunk function is | 824 // Return a name to use for a thunk function. A thunk function is |
799 // one we create during the compilation, for a go statement or a | 825 // one we create during the compilation, for a go statement or a |
800 // defer statement or a method expression. | 826 // defer statement or a method expression. |
801 static std::string | 827 std::string |
802 thunk_name(); | 828 thunk_name(); |
803 | 829 |
804 // Return whether an object is a thunk. | 830 // Return whether an object is a thunk. |
805 static bool | 831 static bool |
806 is_thunk(const Named_object*); | 832 is_thunk(const Named_object*); |
808 // Return the name to use for an init function. | 834 // Return the name to use for an init function. |
809 std::string | 835 std::string |
810 init_function_name(); | 836 init_function_name(); |
811 | 837 |
812 // Return the name to use for a nested function. | 838 // Return the name to use for a nested function. |
813 static std::string | 839 std::string |
814 nested_function_name(); | 840 nested_function_name(Named_object* enclosing); |
815 | |
816 // Return the index of a nested function name. | |
817 static int | |
818 nested_function_num(const std::string&); | |
819 | 841 |
820 // Return the name to use for a sink funciton. | 842 // Return the name to use for a sink funciton. |
821 std::string | 843 std::string |
822 sink_function_name(); | 844 sink_function_name(); |
823 | 845 |
860 ptrmask_symbol_name(const std::string& ptrmask_sym_name); | 882 ptrmask_symbol_name(const std::string& ptrmask_sym_name); |
861 | 883 |
862 // Return the name to use for an interface method table. | 884 // Return the name to use for an interface method table. |
863 std::string | 885 std::string |
864 interface_method_table_name(Interface_type*, Type*, bool is_pointer); | 886 interface_method_table_name(Interface_type*, Type*, bool is_pointer); |
887 | |
888 // Return whether NAME is a special name that can not be passed to | |
889 // unpack_hidden_name. This is needed because various special names | |
890 // use "..SUFFIX", but unpack_hidden_name just looks for '.'. | |
891 static bool | |
892 is_special_name(const std::string& name); | |
865 | 893 |
866 private: | 894 private: |
867 // During parsing, we keep a stack of functions. Each function on | 895 // During parsing, we keep a stack of functions. Each function on |
868 // the stack is one that we are currently parsing. For each | 896 // the stack is one that we are currently parsing. For each |
869 // function, we keep track of the current stack of blocks. | 897 // function, we keep track of the current stack of blocks. |
908 // Register variables with the garbage collector. | 936 // Register variables with the garbage collector. |
909 void | 937 void |
910 register_gc_vars(const std::vector<Named_object*>&, | 938 register_gc_vars(const std::vector<Named_object*>&, |
911 std::vector<Bstatement*>&, | 939 std::vector<Bstatement*>&, |
912 Bfunction* init_bfunction); | 940 Bfunction* init_bfunction); |
941 | |
942 void | |
943 propagate_writebarrierrec(); | |
913 | 944 |
914 Named_object* | 945 Named_object* |
915 write_barrier_variable(); | 946 write_barrier_variable(); |
916 | 947 |
917 Statement* | 948 Statement* |
1023 // -fgo-compiling-runtime option. | 1054 // -fgo-compiling-runtime option. |
1024 bool compiling_runtime_; | 1055 bool compiling_runtime_; |
1025 // The level of escape analysis debug information to emit, from the | 1056 // The level of escape analysis debug information to emit, from the |
1026 // -fgo-debug-escape option. | 1057 // -fgo-debug-escape option. |
1027 int debug_escape_level_; | 1058 int debug_escape_level_; |
1059 // A hash value for debug escape analysis, from the | |
1060 // -fgo-debug-escape-hash option. The analysis is run only on | |
1061 // functions with names that hash to the matching value. | |
1062 std::string debug_escape_hash_; | |
1063 // Nil-check size threshhold. | |
1064 int64_t nil_check_size_threshold_; | |
1028 // A list of types to verify. | 1065 // A list of types to verify. |
1029 std::vector<Type*> verify_types_; | 1066 std::vector<Type*> verify_types_; |
1030 // A list of interface types defined while parsing. | 1067 // A list of interface types defined while parsing. |
1031 std::vector<Interface_type*> interface_types_; | 1068 std::vector<Interface_type*> interface_types_; |
1032 // Type specific functions to write out. | 1069 // Type specific functions to write out. |
1201 // Whether the result variables have names. | 1238 // Whether the result variables have names. |
1202 bool | 1239 bool |
1203 results_are_named() const | 1240 results_are_named() const |
1204 { return this->results_are_named_; } | 1241 { return this->results_are_named_; } |
1205 | 1242 |
1243 // Return the assembler name. | |
1244 const std::string& | |
1245 asm_name() const | |
1246 { return this->asm_name_; } | |
1247 | |
1206 // Set the assembler name. | 1248 // Set the assembler name. |
1207 void | 1249 void |
1208 set_asm_name(const std::string& asm_name) | 1250 set_asm_name(const std::string& asm_name) |
1209 { this->asm_name_ = asm_name; } | 1251 { this->asm_name_ = asm_name; } |
1210 | 1252 |
1216 // Set the pragmas for this function. | 1258 // Set the pragmas for this function. |
1217 void | 1259 void |
1218 set_pragmas(unsigned int pragmas) | 1260 set_pragmas(unsigned int pragmas) |
1219 { | 1261 { |
1220 this->pragmas_ = pragmas; | 1262 this->pragmas_ = pragmas; |
1263 } | |
1264 | |
1265 // Return the index to use for a nested function. | |
1266 unsigned int | |
1267 next_nested_function_index() | |
1268 { | |
1269 ++this->nested_functions_; | |
1270 return this->nested_functions_; | |
1221 } | 1271 } |
1222 | 1272 |
1223 // Whether this method should not be included in the type | 1273 // Whether this method should not be included in the type |
1224 // descriptor. | 1274 // descriptor. |
1225 bool | 1275 bool |
1425 export_func(Export*, const std::string& name) const; | 1475 export_func(Export*, const std::string& name) const; |
1426 | 1476 |
1427 // Export a function with a type. | 1477 // Export a function with a type. |
1428 static void | 1478 static void |
1429 export_func_with_type(Export*, const std::string& name, | 1479 export_func_with_type(Export*, const std::string& name, |
1430 const Function_type*); | 1480 const Function_type*, bool nointerface); |
1431 | 1481 |
1432 // Import a function. | 1482 // Import a function. |
1433 static void | 1483 static void |
1434 import_func(Import*, std::string* pname, Typed_identifier** receiver, | 1484 import_func(Import*, std::string* pname, Typed_identifier** receiver, |
1435 Typed_identifier_list** pparameters, | 1485 Typed_identifier_list** pparameters, |
1436 Typed_identifier_list** presults, bool* is_varargs); | 1486 Typed_identifier_list** presults, bool* is_varargs, |
1487 bool* nointerface); | |
1437 | 1488 |
1438 private: | 1489 private: |
1439 // Type for mapping from label names to Label objects. | 1490 // Type for mapping from label names to Label objects. |
1440 typedef Unordered_map(std::string, Label*) Labels; | 1491 typedef Unordered_map(std::string, Label*) Labels; |
1441 | 1492 |
1478 // distinguish the defer stack for one function from another. This | 1529 // distinguish the defer stack for one function from another. This |
1479 // is NULL unless we actually need a defer stack. | 1530 // is NULL unless we actually need a defer stack. |
1480 Temporary_statement* defer_stack_; | 1531 Temporary_statement* defer_stack_; |
1481 // Pragmas for this function. This is a set of GOPRAGMA bits. | 1532 // Pragmas for this function. This is a set of GOPRAGMA bits. |
1482 unsigned int pragmas_; | 1533 unsigned int pragmas_; |
1534 // Number of nested functions defined within this function. | |
1535 unsigned int nested_functions_; | |
1483 // True if this function is sink-named. No code is generated. | 1536 // True if this function is sink-named. No code is generated. |
1484 bool is_sink_ : 1; | 1537 bool is_sink_ : 1; |
1485 // True if the result variables are named. | 1538 // True if the result variables are named. |
1486 bool results_are_named_ : 1; | 1539 bool results_are_named_ : 1; |
1487 // True if this function is a stub method created for an unnamed | 1540 // True if this function is a stub method created for an unnamed |
1554 | 1607 |
1555 Location | 1608 Location |
1556 location() const | 1609 location() const |
1557 { return this->location_; } | 1610 { return this->location_; } |
1558 | 1611 |
1612 // Return whether this function declaration is a method. | |
1613 bool | |
1614 is_method() const; | |
1615 | |
1559 const std::string& | 1616 const std::string& |
1560 asm_name() const | 1617 asm_name() const |
1561 { return this->asm_name_; } | 1618 { return this->asm_name_; } |
1562 | 1619 |
1563 // Set the assembler name. | 1620 // Set the assembler name. |
1564 void | 1621 void |
1565 set_asm_name(const std::string& asm_name) | 1622 set_asm_name(const std::string& asm_name) |
1566 { this->asm_name_ = asm_name; } | 1623 { this->asm_name_ = asm_name; } |
1567 | 1624 |
1625 // Return the pragmas for this function. | |
1626 unsigned int | |
1627 pragmas() const | |
1628 { return this->pragmas_; } | |
1629 | |
1568 // Set the pragmas for this function. | 1630 // Set the pragmas for this function. |
1569 void | 1631 void |
1570 set_pragmas(unsigned int pragmas) | 1632 set_pragmas(unsigned int pragmas) |
1571 { | 1633 { |
1572 this->pragmas_ = pragmas; | 1634 this->pragmas_ = pragmas; |
1573 } | 1635 } |
1636 | |
1637 // Whether this method should not be included in the type | |
1638 // descriptor. | |
1639 bool | |
1640 nointerface() const; | |
1641 | |
1642 // Record that this method should not be included in the type | |
1643 // descriptor. | |
1644 void | |
1645 set_nointerface(); | |
1574 | 1646 |
1575 // Return an expression for the function descriptor, given the named | 1647 // Return an expression for the function descriptor, given the named |
1576 // object for this function. This may only be called for functions | 1648 // object for this function. This may only be called for functions |
1577 // without a closure. This will be an immutable struct with one | 1649 // without a closure. This will be an immutable struct with one |
1578 // field that points to the function's code. | 1650 // field that points to the function's code. |
1594 build_backend_descriptor(Gogo*); | 1666 build_backend_descriptor(Gogo*); |
1595 | 1667 |
1596 // Export a function declaration. | 1668 // Export a function declaration. |
1597 void | 1669 void |
1598 export_func(Export* exp, const std::string& name) const | 1670 export_func(Export* exp, const std::string& name) const |
1599 { Function::export_func_with_type(exp, name, this->fntype_); } | 1671 { |
1672 Function::export_func_with_type(exp, name, this->fntype_, | |
1673 this->is_method() && this->nointerface()); | |
1674 } | |
1600 | 1675 |
1601 // Check that the types used in this declaration's signature are defined. | 1676 // Check that the types used in this declaration's signature are defined. |
1602 void | 1677 void |
1603 check_types() const; | 1678 check_types() const; |
1604 | 1679 |
1849 void | 1924 void |
1850 set_in_unique_section() | 1925 set_in_unique_section() |
1851 { | 1926 { |
1852 go_assert(this->is_global_); | 1927 go_assert(this->is_global_); |
1853 this->in_unique_section_ = true; | 1928 this->in_unique_section_ = true; |
1929 } | |
1930 | |
1931 // Return the top-level declaration for this variable. | |
1932 Statement* | |
1933 toplevel_decl() | |
1934 { return this->toplevel_decl_; } | |
1935 | |
1936 // Set the top-level declaration for this variable. Only used for local | |
1937 // variables | |
1938 void | |
1939 set_toplevel_decl(Statement* s) | |
1940 { | |
1941 go_assert(!this->is_global_ && !this->is_parameter_ && !this->is_receiver_); | |
1942 this->toplevel_decl_ = s; | |
1854 } | 1943 } |
1855 | 1944 |
1856 // Traverse the initializer expression. | 1945 // Traverse the initializer expression. |
1857 int | 1946 int |
1858 traverse_expression(Traverse*, unsigned int traverse_mask); | 1947 traverse_expression(Traverse*, unsigned int traverse_mask); |
1951 // used for field tracking. | 2040 // used for field tracking. |
1952 bool in_unique_section_ : 1; | 2041 bool in_unique_section_ : 1; |
1953 // Whether this variable escapes the function it is created in. This is | 2042 // Whether this variable escapes the function it is created in. This is |
1954 // true until shown otherwise. | 2043 // true until shown otherwise. |
1955 bool escapes_ : 1; | 2044 bool escapes_ : 1; |
2045 // The top-level declaration for this variable. Only used for local | |
2046 // variables. Must be a Temporary_statement if not NULL. | |
2047 Statement* toplevel_decl_; | |
1956 }; | 2048 }; |
1957 | 2049 |
1958 // A variable which is really the name for a function return value, or | 2050 // A variable which is really the name for a function return value, or |
1959 // part of one. | 2051 // part of one. |
1960 | 2052 |
2071 { } | 2163 { } |
2072 | 2164 |
2073 Type* | 2165 Type* |
2074 type() const | 2166 type() const |
2075 { return this->type_; } | 2167 { return this->type_; } |
2168 | |
2169 void | |
2170 set_type(Type* t); | |
2076 | 2171 |
2077 Expression* | 2172 Expression* |
2078 expr() const | 2173 expr() const |
2079 { return this->expr_; } | 2174 { return this->expr_; } |
2080 | 2175 |
3221 | 3316 |
3222 class Traverse | 3317 class Traverse |
3223 { | 3318 { |
3224 public: | 3319 public: |
3225 // These bitmasks say what to traverse. | 3320 // These bitmasks say what to traverse. |
3226 static const unsigned int traverse_variables = 0x1; | 3321 static const unsigned int traverse_variables = 0x1; |
3227 static const unsigned int traverse_constants = 0x2; | 3322 static const unsigned int traverse_constants = 0x2; |
3228 static const unsigned int traverse_functions = 0x4; | 3323 static const unsigned int traverse_functions = 0x4; |
3229 static const unsigned int traverse_blocks = 0x8; | 3324 static const unsigned int traverse_blocks = 0x8; |
3230 static const unsigned int traverse_statements = 0x10; | 3325 static const unsigned int traverse_statements = 0x10; |
3231 static const unsigned int traverse_expressions = 0x20; | 3326 static const unsigned int traverse_expressions = 0x20; |
3232 static const unsigned int traverse_types = 0x40; | 3327 static const unsigned int traverse_types = 0x40; |
3328 static const unsigned int traverse_func_declarations = 0x80; | |
3233 | 3329 |
3234 Traverse(unsigned int traverse_mask) | 3330 Traverse(unsigned int traverse_mask) |
3235 : traverse_mask_(traverse_mask), types_seen_(NULL), expressions_seen_(NULL) | 3331 : traverse_mask_(traverse_mask), types_seen_(NULL), expressions_seen_(NULL) |
3236 { } | 3332 { } |
3237 | 3333 |
3291 | 3387 |
3292 // If traverse_types is set in the mask, this is called for every | 3388 // If traverse_types is set in the mask, this is called for every |
3293 // type in the tree. | 3389 // type in the tree. |
3294 virtual int | 3390 virtual int |
3295 type(Type*); | 3391 type(Type*); |
3392 | |
3393 // If traverse_func_declarations is set in the mask, this is called | |
3394 // for every function declarations in the tree. | |
3395 virtual int | |
3396 function_declaration(Named_object*); | |
3296 | 3397 |
3297 private: | 3398 private: |
3298 // A hash table for types we have seen during this traversal. Note | 3399 // A hash table for types we have seen during this traversal. Note |
3299 // that this uses the default hash functions for pointers rather | 3400 // that this uses the default hash functions for pointers rather |
3300 // than Type_hash_identical and Type_identical. This is because for | 3401 // than Type_hash_identical and Type_identical. This is because for |
3317 // current statement during a traversal. | 3418 // current statement during a traversal. |
3318 | 3419 |
3319 class Statement_inserter | 3420 class Statement_inserter |
3320 { | 3421 { |
3321 public: | 3422 public: |
3423 typedef Unordered_set(Statement*) Statements; | |
3424 | |
3322 // Empty constructor. | 3425 // Empty constructor. |
3323 Statement_inserter() | 3426 Statement_inserter() |
3324 : block_(NULL), pindex_(NULL), gogo_(NULL), var_(NULL) | 3427 : block_(NULL), pindex_(NULL), gogo_(NULL), var_(NULL), |
3428 statements_added_(NULL) | |
3325 { } | 3429 { } |
3326 | 3430 |
3327 // Constructor for a statement in a block. | 3431 // Constructor for a statement in a block. |
3328 Statement_inserter(Block* block, size_t *pindex) | 3432 Statement_inserter(Block* block, size_t *pindex, Statements *added = NULL) |
3329 : block_(block), pindex_(pindex), gogo_(NULL), var_(NULL) | 3433 : block_(block), pindex_(pindex), gogo_(NULL), var_(NULL), |
3434 statements_added_(added) | |
3330 { } | 3435 { } |
3331 | 3436 |
3332 // Constructor for a global variable. | 3437 // Constructor for a global variable. |
3333 Statement_inserter(Gogo* gogo, Variable* var) | 3438 Statement_inserter(Gogo* gogo, Variable* var, Statements *added = NULL) |
3334 : block_(NULL), pindex_(NULL), gogo_(gogo), var_(var) | 3439 : block_(NULL), pindex_(NULL), gogo_(gogo), var_(var), |
3440 statements_added_(added) | |
3335 { go_assert(var->is_global()); } | 3441 { go_assert(var->is_global()); } |
3336 | 3442 |
3337 // We use the default copy constructor and assignment operator. | 3443 // We use the default copy constructor and assignment operator. |
3338 | 3444 |
3339 // Insert S before the statement we are traversing, or before the | 3445 // Insert S before the statement we are traversing, or before the |
3349 // The IR, needed when looking at an initializer expression for a | 3455 // The IR, needed when looking at an initializer expression for a |
3350 // global variable. | 3456 // global variable. |
3351 Gogo* gogo_; | 3457 Gogo* gogo_; |
3352 // The global variable, when looking at an initializer expression. | 3458 // The global variable, when looking at an initializer expression. |
3353 Variable* var_; | 3459 Variable* var_; |
3460 // If non-null, a set to record new statements inserted (non-owned). | |
3461 Statements* statements_added_; | |
3354 }; | 3462 }; |
3355 | 3463 |
3356 // When translating the gogo IR into the backend data structure, this | 3464 // When translating the gogo IR into the backend data structure, this |
3357 // is the context we pass down the blocks and statements. | 3465 // is the context we pass down the blocks and statements. |
3358 | 3466 |