Commit 55875977 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: dedup Pragma switch

Change-Id: I2d01f692ae30a166079976b86bf0b7a439f05d5c
Reviewed-on: https://go-review.googlesource.com/28178
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent d1383b5b
...@@ -75,6 +75,54 @@ const ( ...@@ -75,6 +75,54 @@ const (
UintptrEscapes // pointers converted to uintptr escape UintptrEscapes // pointers converted to uintptr escape
) )
func PragmaValue(verb string) Pragma {
switch verb {
case "go:nointerface":
if obj.Fieldtrack_enabled != 0 {
return Nointerface
}
case "go:noescape":
return Noescape
case "go:norace":
return Norace
case "go:nosplit":
return Nosplit
case "go:noinline":
return Noinline
case "go:systemstack":
if !compiling_runtime {
Yyerror("//go:systemstack only allowed in runtime")
}
return Systemstack
case "go:nowritebarrier":
if !compiling_runtime {
Yyerror("//go:nowritebarrier only allowed in runtime")
}
return Nowritebarrier
case "go:nowritebarrierrec":
if !compiling_runtime {
Yyerror("//go:nowritebarrierrec only allowed in runtime")
}
return Nowritebarrierrec | Nowritebarrier // implies Nowritebarrier
case "go:cgo_unsafe_args":
return CgoUnsafeArgs
case "go:uintptrescapes":
// For the next function declared in the file
// any uintptr arguments may be pointer values
// converted to uintptr. This directive
// ensures that the referenced allocated
// object, if any, is retained and not moved
// until the call completes, even though from
// the types alone it would appear that the
// object is no longer needed during the
// call. The conversion to uintptr must appear
// in the argument list.
// Used in syscall/dll_windows.go.
return UintptrEscapes
}
return 0
}
type lexer struct { type lexer struct {
// source // source
bin *bufio.Reader bin *bufio.Reader
...@@ -888,48 +936,8 @@ func (l *lexer) getlinepragma() rune { ...@@ -888,48 +936,8 @@ func (l *lexer) getlinepragma() rune {
break break
} }
Lookup(f[1]).Linkname = f[2] Lookup(f[1]).Linkname = f[2]
case "go:nointerface": default:
if obj.Fieldtrack_enabled != 0 { l.pragma |= PragmaValue(verb)
l.pragma |= Nointerface
}
case "go:noescape":
l.pragma |= Noescape
case "go:norace":
l.pragma |= Norace
case "go:nosplit":
l.pragma |= Nosplit
case "go:noinline":
l.pragma |= Noinline
case "go:systemstack":
if !compiling_runtime {
Yyerror("//go:systemstack only allowed in runtime")
}
l.pragma |= Systemstack
case "go:nowritebarrier":
if !compiling_runtime {
Yyerror("//go:nowritebarrier only allowed in runtime")
}
l.pragma |= Nowritebarrier
case "go:nowritebarrierrec":
if !compiling_runtime {
Yyerror("//go:nowritebarrierrec only allowed in runtime")
}
l.pragma |= Nowritebarrierrec | Nowritebarrier // implies Nowritebarrier
case "go:cgo_unsafe_args":
l.pragma |= CgoUnsafeArgs
case "go:uintptrescapes":
// For the next function declared in the file
// any uintptr arguments may be pointer values
// converted to uintptr. This directive
// ensures that the referenced allocated
// object, if any, is retained and not moved
// until the call completes, even though from
// the types alone it would appear that the
// object is no longer needed during the
// call. The conversion to uintptr must appear
// in the argument list.
// Used in syscall/dll_windows.go.
l.pragma |= UintptrEscapes
} }
return c return c
} }
......
...@@ -12,7 +12,6 @@ import ( ...@@ -12,7 +12,6 @@ import (
"unicode/utf8" "unicode/utf8"
"cmd/compile/internal/syntax" "cmd/compile/internal/syntax"
"cmd/internal/obj"
) )
func parseFile(filename string) { func parseFile(filename string) {
...@@ -1014,50 +1013,7 @@ func (p *noder) pragma() Pragma { ...@@ -1014,50 +1013,7 @@ func (p *noder) pragma() Pragma {
verb = verb[:i] verb = verb[:i]
} }
switch verb { res |= PragmaValue(verb)
case "go:nointerface":
if obj.Fieldtrack_enabled != 0 {
res |= Nointerface
}
case "go:noescape":
res |= Noescape
case "go:norace":
res |= Norace
case "go:nosplit":
res |= Nosplit
case "go:noinline":
res |= Noinline
case "go:systemstack":
if !compiling_runtime {
Yyerror("//go:systemstack only allowed in runtime")
}
res |= Systemstack
case "go:nowritebarrier":
if !compiling_runtime {
Yyerror("//go:nowritebarrier only allowed in runtime")
}
res |= Nowritebarrier
case "go:nowritebarrierrec":
if !compiling_runtime {
Yyerror("//go:nowritebarrierrec only allowed in runtime")
}
res |= Nowritebarrierrec | Nowritebarrier // implies Nowritebarrier
case "go:cgo_unsafe_args":
res |= CgoUnsafeArgs
case "go:uintptrescapes":
// For the next function declared in the file
// any uintptr arguments may be pointer values
// converted to uintptr. This directive
// ensures that the referenced allocated
// object, if any, is retained and not moved
// until the call completes, even though from
// the types alone it would appear that the
// object is no longer needed during the
// call. The conversion to uintptr must appear
// in the argument list.
// Used in syscall/dll_windows.go.
res |= UintptrEscapes
}
} }
return res return res
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment