Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
daa5bbe8
Commit
daa5bbe8
authored
Jan 27, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e833702e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
38 deletions
+37
-38
t/neo/protogen.go
t/neo/protogen.go
+37
-38
No files found.
t/neo/protogen.go
View file @
daa5bbe8
...
@@ -381,10 +381,10 @@ func (s *SymSize) Reset() {
...
@@ -381,10 +381,10 @@ func (s *SymSize) Reset() {
// decoder overflow check state
// decoder overflow check state
type
OverflowCheck
struct
{
type
OverflowCheck
struct
{
// accumulator for size to check at overflow check point
// accumulator for size to check at overflow check point
size
SymSize
checkSize
SymSize
// whether overflow was already checked for current decodings
// whether overflow was already checked for current decodings
// (if yes,
s
ize updates will be ignored)
// (if yes,
checkS
ize updates will be ignored)
checked
bool
checked
bool
// stack operated by {Push,Pop}Checked
// stack operated by {Push,Pop}Checked
...
@@ -407,17 +407,17 @@ func (o *OverflowCheck) PopChecked() bool {
...
@@ -407,17 +407,17 @@ func (o *OverflowCheck) PopChecked() bool {
// Add and AddExpr update .
s
ize accordingly, but only if overflow was not
// Add and AddExpr update .
checkS
ize accordingly, but only if overflow was not
// already marked as checked
// already marked as checked
func
(
o
*
OverflowCheck
)
Add
(
n
int
)
{
func
(
o
*
OverflowCheck
)
Add
(
n
int
)
{
if
!
o
.
checked
{
if
!
o
.
checked
{
o
.
s
ize
.
Add
(
n
)
o
.
checkS
ize
.
Add
(
n
)
}
}
}
}
func
(
o
*
OverflowCheck
)
AddExpr
(
format
string
,
a
...
interface
{})
{
func
(
o
*
OverflowCheck
)
AddExpr
(
format
string
,
a
...
interface
{})
{
if
!
o
.
checked
{
if
!
o
.
checked
{
o
.
s
ize
.
AddExpr
(
format
,
a
...
)
o
.
checkS
ize
.
AddExpr
(
format
,
a
...
)
}
}
}
}
...
@@ -473,11 +473,11 @@ type decoder struct {
...
@@ -473,11 +473,11 @@ type decoder struct {
bufDone
Buffer
bufDone
Buffer
n
int
// current read position in data.
n
int
// current read position in data.
nread
int
// numeric part of
nread return XXX
nread
int
// numeric part of
total nread return
// overflow check state and size that will be checked for overflow at
// overflow check state and size that will be checked for overflow at
// current overflow check point
// current overflow check point
overflow
Check
OverflowCheck
overflow
OverflowCheck
}
}
var
_
CodeGenerator
=
(
*
sizer
)(
nil
)
var
_
CodeGenerator
=
(
*
sizer
)(
nil
)
...
@@ -530,7 +530,6 @@ func (d *decoder) resetPos() {
...
@@ -530,7 +530,6 @@ func (d *decoder) resetPos() {
}
}
// XXX place?
// XXX place?
// XXX naming -> overflowCheck() ?
// mark current place for delayed insertion of overflow check code
// mark current place for delayed insertion of overflow check code
//
//
// delayed: because we go forward in decode path scanning ahead as far as we
// delayed: because we go forward in decode path scanning ahead as far as we
...
@@ -538,7 +537,7 @@ func (d *decoder) resetPos() {
...
@@ -538,7 +537,7 @@ func (d *decoder) resetPos() {
// fixed size would be to read - insert checking condition for accumulated size
// fixed size would be to read - insert checking condition for accumulated size
// to here-marked overflow checkpoint.
// to here-marked overflow checkpoint.
//
//
// so overflowCheck
Point
does:
// so overflowCheck does:
// 1. emit overflow checking code for previous overflow checkpoint
// 1. emit overflow checking code for previous overflow checkpoint
// 2. mark current place as next overflow checkpoint to eventually emit
// 2. mark current place as next overflow checkpoint to eventually emit
//
//
...
@@ -546,15 +545,15 @@ func (d *decoder) resetPos() {
...
@@ -546,15 +545,15 @@ func (d *decoder) resetPos() {
// - before reading a variable sized item
// - before reading a variable sized item
// - in the beginning of a loop inside
// - in the beginning of a loop inside
// - right after loop exit
// - right after loop exit
func
(
d
*
decoder
)
overflowCheck
Point
()
{
func
(
d
*
decoder
)
overflowCheck
()
{
// nop if we know overflow was already checked
// nop if we know overflow was already checked
if
d
.
overflow
Check
.
checked
{
if
d
.
overflow
.
checked
{
return
return
}
}
//d.bufDone.emit("// overflow check point")
//d.bufDone.emit("// overflow check point")
if
!
d
.
overflow
Check
.
s
ize
.
IsZero
()
{
if
!
d
.
overflow
.
checkS
ize
.
IsZero
()
{
d
.
bufDone
.
emit
(
"if uint32(len(data)) < %v { goto overflow }"
,
&
d
.
overflow
Check
.
s
ize
)
d
.
bufDone
.
emit
(
"if uint32(len(data)) < %v { goto overflow }"
,
&
d
.
overflow
.
checkS
ize
)
// if size for overflow check was only numeric - just
// if size for overflow check was only numeric - just
// accumulate it at compile time
// accumulate it at compile time
...
@@ -564,14 +563,14 @@ func (d *decoder) overflowCheckPoint() {
...
@@ -564,14 +563,14 @@ func (d *decoder) overflowCheckPoint() {
// parts, because just above whole expression num + symbolic
// parts, because just above whole expression num + symbolic
// was just given to compiler so compiler shoud have it just computed.
// was just given to compiler so compiler shoud have it just computed.
// XXX recheck ^^^ actually good with the compiler
// XXX recheck ^^^ actually good with the compiler
if
d
.
overflow
Check
.
s
ize
.
IsNumeric
()
{
if
d
.
overflow
.
checkS
ize
.
IsNumeric
()
{
d
.
nread
+=
d
.
overflow
Check
.
s
ize
.
num
d
.
nread
+=
d
.
overflow
.
checkS
ize
.
num
}
else
{
}
else
{
d
.
bufDone
.
emit
(
"%v += %v"
,
d
.
var_
(
"nread"
),
&
d
.
overflow
Check
.
s
ize
)
d
.
bufDone
.
emit
(
"%v += %v"
,
d
.
var_
(
"nread"
),
&
d
.
overflow
.
checkS
ize
)
}
}
}
}
d
.
overflow
Check
.
s
ize
.
Reset
()
d
.
overflow
.
checkS
ize
.
Reset
()
d
.
bufDone
.
Write
(
d
.
buf
.
Bytes
())
d
.
bufDone
.
Write
(
d
.
buf
.
Bytes
())
d
.
buf
.
Reset
()
d
.
buf
.
Reset
()
...
@@ -579,7 +578,7 @@ func (d *decoder) overflowCheckPoint() {
...
@@ -579,7 +578,7 @@ func (d *decoder) overflowCheckPoint() {
func
(
d
*
decoder
)
generatedCode
()
string
{
func
(
d
*
decoder
)
generatedCode
()
string
{
// flush for last overflow check point
// flush for last overflow check point
d
.
overflowCheck
Point
()
d
.
overflowCheck
()
code
:=
Buffer
{}
code
:=
Buffer
{}
// prologue
// prologue
...
@@ -640,7 +639,7 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
...
@@ -640,7 +639,7 @@ func (d *decoder) genBasic(assignto string, typ *types.Basic, userType types.Typ
d
.
emit
(
"%s= %s"
,
assignto
,
decoded
)
d
.
emit
(
"%s= %s"
,
assignto
,
decoded
)
d
.
n
+=
basic
.
wireSize
d
.
n
+=
basic
.
wireSize
d
.
overflow
Check
.
Add
(
basic
.
wireSize
)
d
.
overflow
.
Add
(
basic
.
wireSize
)
}
}
// emit code to size/encode/decode array with sizeof(elem)==1
// emit code to size/encode/decode array with sizeof(elem)==1
...
@@ -658,7 +657,7 @@ func (d *decoder) genArray1(assignto string, typ *types.Array) {
...
@@ -658,7 +657,7 @@ func (d *decoder) genArray1(assignto string, typ *types.Array) {
typLen
:=
int
(
typ
.
Len
())
typLen
:=
int
(
typ
.
Len
())
d
.
emit
(
"copy(%v[:], data[%v:%v])"
,
assignto
,
d
.
n
,
d
.
n
+
typLen
)
d
.
emit
(
"copy(%v[:], data[%v:%v])"
,
assignto
,
d
.
n
,
d
.
n
+
typLen
)
d
.
n
+=
typLen
d
.
n
+=
typLen
d
.
overflow
Check
.
Add
(
typLen
)
d
.
overflow
.
Add
(
typLen
)
}
}
// emit code to size/encode/decode string or []byte
// emit code to size/encode/decode string or []byte
...
@@ -686,8 +685,8 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) {
...
@@ -686,8 +685,8 @@ func (d *decoder) genSlice1(assignto string, typ types.Type) {
d
.
resetPos
()
d
.
resetPos
()
d
.
overflowCheck
Point
()
d
.
overflowCheck
()
d
.
overflow
Check
.
AddExpr
(
"l"
)
d
.
overflow
.
AddExpr
(
"l"
)
switch
t
:=
typ
.
(
type
)
{
switch
t
:=
typ
.
(
type
)
{
case
*
types
.
Basic
:
case
*
types
.
Basic
:
...
@@ -764,19 +763,19 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
...
@@ -764,19 +763,19 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
// if size(item)==const - check overflow in one go
// if size(item)==const - check overflow in one go
elemSize
,
elemFixed
:=
typeSizeFixed
(
typ
.
Elem
())
elemSize
,
elemFixed
:=
typeSizeFixed
(
typ
.
Elem
())
if
elemFixed
{
if
elemFixed
{
d
.
overflowCheck
Point
()
d
.
overflowCheck
()
d
.
overflow
Check
.
AddExpr
(
"l * %v"
,
elemSize
)
d
.
overflow
.
AddExpr
(
"l * %v"
,
elemSize
)
d
.
overflow
Check
.
PushChecked
(
true
)
d
.
overflow
.
PushChecked
(
true
)
defer
d
.
overflow
Check
.
PopChecked
()
defer
d
.
overflow
.
PopChecked
()
}
}
d
.
emit
(
"%v= make(%v, l)"
,
assignto
,
typeName
(
typ
))
d
.
emit
(
"%v= make(%v, l)"
,
assignto
,
typeName
(
typ
))
d
.
emit
(
"for i := 0; uint32(i) < l; i++ {"
)
d
.
emit
(
"for i := 0; uint32(i) < l; i++ {"
)
d
.
emit
(
"a := &%s[i]"
,
assignto
)
d
.
emit
(
"a := &%s[i]"
,
assignto
)
d
.
overflowCheck
Point
()
// -> overflowCheckPoint
LoopEntry ?
d
.
overflowCheck
()
// -> overflowCheck
LoopEntry ?
var
nreadCur
int
var
nreadCur
int
if
!
d
.
overflow
Check
.
checked
{
// TODO merge-in into overflow checker
if
!
d
.
overflow
.
checked
{
// TODO merge-in into overflow checker
nreadCur
=
d
.
nread
nreadCur
=
d
.
nread
d
.
nread
=
0
d
.
nread
=
0
}
}
...
@@ -786,10 +785,10 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
...
@@ -786,10 +785,10 @@ func (d *decoder) genSlice(assignto string, typ *types.Slice, obj types.Object)
d
.
resetPos
()
d
.
resetPos
()
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
d
.
overflowCheck
Point
()
// -> overflowCheckPointLoopExit("l") ?
d
.
overflowCheck
()
// -> overflowCheckPointLoopExit("l") ?
// merge-in numeric nread updates from loop
// merge-in numeric nread updates from loop
if
!
d
.
overflow
Check
.
checked
{
if
!
d
.
overflow
.
checked
{
if
d
.
nread
!=
0
{
if
d
.
nread
!=
0
{
d
.
emit
(
"%v += l * %v"
,
d
.
var_
(
"nread"
),
d
.
nread
)
d
.
emit
(
"%v += l * %v"
,
d
.
var_
(
"nread"
),
d
.
nread
)
}
}
...
@@ -863,19 +862,19 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
...
@@ -863,19 +862,19 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
elemSize
,
elemFixed
:=
typeSizeFixed
(
typ
.
Elem
())
elemSize
,
elemFixed
:=
typeSizeFixed
(
typ
.
Elem
())
itemFixed
:=
keyFixed
&&
elemFixed
itemFixed
:=
keyFixed
&&
elemFixed
if
itemFixed
{
if
itemFixed
{
d
.
overflowCheck
Point
()
d
.
overflowCheck
()
d
.
overflow
Check
.
AddExpr
(
"l * %v"
,
keySize
+
elemSize
)
d
.
overflow
.
AddExpr
(
"l * %v"
,
keySize
+
elemSize
)
d
.
overflow
Check
.
PushChecked
(
true
)
d
.
overflow
.
PushChecked
(
true
)
defer
d
.
overflow
Check
.
PopChecked
()
defer
d
.
overflow
.
PopChecked
()
}
}
d
.
emit
(
"%v= make(%v, l)"
,
assignto
,
typeName
(
typ
))
d
.
emit
(
"%v= make(%v, l)"
,
assignto
,
typeName
(
typ
))
d
.
emit
(
"m := %v"
,
assignto
)
d
.
emit
(
"m := %v"
,
assignto
)
d
.
emit
(
"for i := 0; uint32(i) < l; i++ {"
)
d
.
emit
(
"for i := 0; uint32(i) < l; i++ {"
)
d
.
overflowCheck
Point
()
// -> overflowCheckPointLoopEntry ?
d
.
overflowCheck
()
// -> overflowCheckPointLoopEntry ?
var
nreadCur
int
var
nreadCur
int
if
!
d
.
overflow
Check
.
checked
{
// TODO merge-in into overflow checker
if
!
d
.
overflow
.
checked
{
// TODO merge-in into overflow checker
nreadCur
=
d
.
nread
nreadCur
=
d
.
nread
d
.
nread
=
0
d
.
nread
=
0
}
}
...
@@ -897,10 +896,10 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
...
@@ -897,10 +896,10 @@ func (d *decoder) genMap(assignto string, typ *types.Map, obj types.Object) {
d
.
resetPos
()
d
.
resetPos
()
d
.
emit
(
"}"
)
d
.
emit
(
"}"
)
d
.
overflowCheck
Point
()
// -> overflowCheckPointLoopExit("l") ?
d
.
overflowCheck
()
// -> overflowCheckPointLoopExit("l") ?
// merge-in numeric nread updates from loop
// merge-in numeric nread updates from loop
if
!
d
.
overflow
Check
.
checked
{
if
!
d
.
overflow
.
checked
{
if
d
.
nread
!=
0
{
if
d
.
nread
!=
0
{
d
.
emit
(
"%v += l * %v"
,
d
.
var_
(
"nread"
),
d
.
nread
)
d
.
emit
(
"%v += l * %v"
,
d
.
var_
(
"nread"
),
d
.
nread
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment