std::string package = (no->package() != NULL
? no->package()->pkgpath()
: gogo->pkgpath());
+ bool is_method = ((no->is_function() && no->func_value()->is_method())
+ || (no->is_function_declaration()
+ && no->func_declaration_value()->is_method()));
Location loc = this->location();
Type* int_type = Type::lookup_integer_type("int");
Type* int32_type = Type::lookup_integer_type("int32");
Type* int64_type = Type::lookup_integer_type("int64");
Type* uint_type = Type::lookup_integer_type("uint");
+ Type* uint8_type = Type::lookup_integer_type("uint8");
Type* uint32_type = Type::lookup_integer_type("uint32");
Type* uint64_type = Type::lookup_integer_type("uint64");
Type* uintptr_type = Type::lookup_integer_type("uintptr");
if (package == "sync/atomic")
{
+ if (is_method)
+ return NULL;
+
// sync/atomic functions and runtime/internal/atomic functions
// are very similar. In order not to duplicate code, we just
// redirect to the latter and let the code below to handle them.
if (package == "runtime/internal/sys")
{
+ if (is_method)
+ return NULL;
+
// runtime/internal/sys functions and math/bits functions
// are very similar. In order not to duplicate code, we just
// redirect to the latter and let the code below to handle them.
if (package == "runtime")
{
+ if (is_method)
+ return NULL;
+
// Handle a couple of special runtime functions. In the runtime
// package, getcallerpc returns the PC of the caller, and
// getcallersp returns the frame pointer of the caller. Implement
}
else if (package == "math/bits")
{
+ if (is_method)
+ return NULL;
+
if ((name == "ReverseBytes16" || name == "ReverseBytes32"
|| name == "ReverseBytes64" || name == "ReverseBytes")
&& this->args_ != NULL && this->args_->size() == 1)
{
int memorder = __ATOMIC_SEQ_CST;
+ if (is_method)
+ {
+ Function_type* ftype = (no->is_function()
+ ? no->func_value()->type()
+ : no->func_declaration_value()->type());
+ Type* rtype = ftype->receiver()->type()->deref();
+ go_assert(rtype->named_type() != NULL);
+ const std::string& rname(rtype->named_type()->name());
+ if (rname == "Int32")
+ {
+ if (name == "Load")
+ name = "LoadInt32";
+ else if (name == "Store")
+ name = "Storeint32";
+ else if (name == "CompareAndSwap")
+ name = "Casint32";
+ else if (name == "Swap")
+ name = "Xchgint32";
+ else if (name == "Add")
+ name = "Xaddint32";
+ else
+ go_unreachable();
+ }
+ else if (rname == "Int64")
+ {
+ if (name == "Load")
+ name = "LoadInt64";
+ else if (name == "Store")
+ name = "Storeint64";
+ else if (name == "CompareAndSwap")
+ name = "Casint64";
+ else if (name == "Swap")
+ name = "Xchgint64";
+ else if (name == "Add")
+ name = "Xaddint64";
+ else
+ go_unreachable();
+ }
+ else if (rname == "Uint8")
+ {
+ if (name == "Load")
+ name = "Load8";
+ else if (name == "Store")
+ name = "Store8";
+ else if (name == "And")
+ name = "And8";
+ else if (name == "Or")
+ name = "Or8";
+ else
+ go_unreachable();
+ }
+ else if (rname == "Uint32")
+ {
+ if (name == "Load")
+ name = "Load";
+ else if (name == "LoadAcquire")
+ name = "LoadAcq";
+ else if (name == "Store")
+ name = "Store";
+ else if (name == "CompareAndSwap")
+ name = "Cas";
+ else if (name == "CompareAndSwapRelease")
+ name = "CasRel";
+ else if (name == "Swap")
+ name = "Xchg";
+ else if (name == "And")
+ name = "And";
+ else if (name == "Or")
+ name = "Or";
+ else if (name == "Add")
+ name = "Xadd";
+ else
+ go_unreachable();
+ }
+ else if (rname == "Uint64")
+ {
+ if (name == "Load")
+ name = "Load64";
+ else if (name == "Store")
+ name = "Store64";
+ else if (name == "CompareAndSwap")
+ name = "Cas64";
+ else if (name == "Swap")
+ name = "Xchgt64";
+ else if (name == "Add")
+ name = "Xadd64";
+ else
+ go_unreachable();
+ }
+ else if (rname == "Uintptr")
+ {
+ if (name == "Load")
+ name = "Loaduintptr";
+ else if (name == "LoadAcquire")
+ name = "Loadacquintptr";
+ else if (name == "Store")
+ name = "Storeuintptr";
+ else if (name == "StoreRelease")
+ name = "StoreReluintptr";
+ else if (name == "CompareAndSwap")
+ name = "Casuintptr";
+ else if (name == "Swap")
+ name = "Xchguintptr";
+ else if (name == "Add")
+ name = "Xadduintptr";
+ else
+ go_unreachable();
+ }
+ else if (rname == "Float64")
+ {
+ // Needs unsafe type conversion. Don't intrinsify for now.
+ return NULL;
+ }
+ else if (rname == "UnsafePointer")
+ {
+ if (name == "Load")
+ name = "Loadp";
+ else if (name == "StoreNoWB")
+ name = "StorepoWB";
+ else if (name == "CompareAndSwapNoWB")
+ name = "Casp1";
+ else
+ go_unreachable();
+ }
+ else
+ go_unreachable();
+ }
+
if ((name == "Load" || name == "Load64" || name == "Loadint64" || name == "Loadp"
|| name == "Loaduint" || name == "Loaduintptr" || name == "LoadAcq"
- || name == "Loadint32")
+ || name == "Loadint32" || name == "Load8")
&& this->args_ != NULL && this->args_->size() == 1)
{
if (int_size < 8 && (name == "Load64" || name == "Loadint64"))
res_type = uint32_type;
memorder = __ATOMIC_ACQUIRE;
}
+ else if (name == "Load8")
+ {
+ code = Runtime::ATOMIC_LOAD_1;
+ res_type = uint8_type;
+ }
else
go_unreachable();
Expression* a1 = this->args_->front();
code = Runtime::ATOMIC_STORE_4;
memorder = __ATOMIC_RELEASE;
}
+ else if (name == "Store8")
+ code = Runtime::ATOMIC_STORE_1;
else
go_unreachable();
Expression* a3 = Expression::make_integer_ul(memorder, int32_type, loc);
}
else if (package == "internal/abi")
{
+ if (is_method)
+ return NULL;
+
if ((name == "FuncPCABI0" || name == "FuncPCABIInternal")
&& this->args_ != NULL
&& this->args_->size() == 1)