Skip to content

Commit

Permalink
* front end optimizations to reduce parsing time
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwalkerlewis committed Nov 2, 2012
1 parent a38fc9d commit 54c2637
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 34 deletions.
1 change: 1 addition & 0 deletions docs/release/4.1.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@
* Smaller translated DLLs are produced by improved identification of routines that need to be exported
* Eutest now has an eubin option for specifying all binaries in a single option.
* Eutest has a retest option for retesting all tests that had previously failed.
* Front end optimizations to reduce parsing time
22 changes: 17 additions & 5 deletions source/fwdref.e
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,43 @@ sequence patch_code_temp = {}
sequence patch_linetab_temp = {}
symtab_index patch_code_sub
symtab_index patch_current_sub

procedure set_code( integer ref )
patch_code_sub = forward_references[ref][FR_SUBPROG]

if patch_code_sub != CurrentSub then
-- we're patching a routine other than the current one
patch_code_temp = Code
patch_linetab_temp = LineTable

Code = SymTab[patch_code_sub][S_CODE]
SymTab[patch_code_sub][S_CODE] = 0
LineTable = SymTab[patch_code_sub][S_LINETAB]
SymTab[patch_code_sub][S_LINETAB] = 0

patch_current_sub = CurrentSub
CurrentSub = patch_code_sub
else
patch_current_sub = patch_code_sub
if sequence( SymTab[patch_current_sub][S_CODE] ) then
SymTab[patch_code_sub][S_CODE] = 0
SymTab[patch_code_sub][S_LINETAB] = 0
end if
end if
end procedure

procedure reset_code( )
SymTab[patch_code_sub][S_CODE] = Code
SymTab[patch_code_sub][S_LINETAB] = LineTable
if patch_code_sub != patch_current_sub then
-- put the patched code back into the symtab
SymTab[patch_code_sub][S_CODE] = Code
SymTab[patch_code_sub][S_LINETAB] = LineTable

-- reset to where we were before set_code() was called
CurrentSub = patch_current_sub
Code = patch_code_temp
LineTable = patch_linetab_temp
end if

-- clear the references on these
patch_code_temp = {}
patch_linetab_temp = {}
end procedure
Expand Down Expand Up @@ -305,6 +316,7 @@ procedure patch_forward_call( token tok, integer ref )
sequence params = repeat( 0, args )
sequence orig_code = code
sequence orig_linetable = LineTable
LineTable = {}
Code = {}


Expand Down Expand Up @@ -353,7 +365,9 @@ procedure patch_forward_call( token tok, integer ref )

sequence new_code = Code
Code = orig_code
orig_code = {}
LineTable = orig_linetable
orig_linetable = {}
set_dont_read( 0 )
current_file_no = real_file

Expand Down Expand Up @@ -847,7 +861,6 @@ procedure remove_active_reference( integer ref, integer file_no = current_file_n
end procedure

function resolve_file( sequence refs, integer report_errors, integer unincluded_ok )

sequence errors = {}
for ar = length( refs ) to 1 by -1 do
integer ref = refs[ar]
Expand Down Expand Up @@ -966,7 +979,6 @@ export procedure Resolve_forward_references( integer report_errors = 0 )
if (length( active_subprogs[i] ) or length(toplevel_references[i]))
and (i = current_file_no or finished_files[i] or unincluded_ok)
then

for j = length( active_references[i] ) to 1 by -1 do
errors &= resolve_file( active_references[i][j], report_errors, unincluded_ok )
end for
Expand Down
2 changes: 2 additions & 0 deletions source/inline.e
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@ export procedure inline_deferred_calls()
CurrentSub = calling_sub
Code = SymTab[calling_sub][S_CODE]
LineTable = SymTab[calling_sub][S_LINETAB]
SymTab[calling_sub][S_CODE] = 0
SymTab[calling_sub][S_LINETAB] = 0
sequence code = {}

sequence calls = find_ops( 1, PROC )
Expand Down
6 changes: 6 additions & 0 deletions source/parser.e
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ procedure EnterTopLevel( integer end_line_table = 1 )
end if
LineTable = SymTab[TopLevelSub][S_LINETAB]
Code = SymTab[TopLevelSub][S_CODE]
SymTab[TopLevelSub][S_LINETAB] = 0
SymTab[TopLevelSub][S_CODE] = 0
previous_op = -1
CurrentSub = TopLevelSub
clear_last()
Expand Down Expand Up @@ -5034,6 +5036,10 @@ export procedure parser()
mark_final_targets()
resolve_unincluded_globals( 1 )
Resolve_forward_references( 1 )
SymTab[TopLevelSub][S_CODE] = Code
SymTab[TopLevelSub][S_LINETAB] = LineTable
Code = {}
LineTable = {}
inline_deferred_calls()
if not repl then
End_block( PROC )
Expand Down
95 changes: 66 additions & 29 deletions source/shift.e
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,22 @@ export enum
OP_TARGET,
OP_SUB

sequence
op_info_size_type,
op_info_size,
op_info_addr,
op_info_target,
op_info_sub,
$

procedure init_op_info()
op_info = repeat( 0, MAX_OPCODE )
op_info_size_type = repeat( 0, MAX_OPCODE )
op_info_size = repeat( 0, MAX_OPCODE )
op_info_addr = repeat( 0, MAX_OPCODE )
op_info_target = repeat( 0, MAX_OPCODE )
op_info_sub = repeat( 0, MAX_OPCODE )

op_info[ABORT ] = { FIXED_SIZE, 2, {}, {}, {} } -- ary: pun
op_info[AND ] = { FIXED_SIZE, 4, {}, {}, {} } -- ary: bin
op_info[AND_BITS ] = { FIXED_SIZE, 4, {}, {3}, {} } -- ary: bin
Expand Down Expand Up @@ -262,42 +276,58 @@ procedure init_op_info()
op_info[CONCAT_N ] = { VARIABLE_SIZE, 0, {}, {}, {} } -- target: [pc+1] + 2
op_info[PROC ] = { VARIABLE_SIZE, 0, {}, {}, {} }
op_info[PROC_TAIL ] = op_info[PROC]


for i = 1 to MAX_OPCODE do
object info = op_info[i]
if sequence( info ) then
op_info_size_type[i] = info[OP_SIZE_TYPE]
op_info_size[i] = info[OP_SIZE]
op_info_addr[i] = info[OP_ADDR]
op_info_target[i] = info[OP_TARGET]
op_info_sub[i] = info[OP_SUB]
end if
end for
end procedure

init_op_info()

function variable_op_size( integer pc, integer op, sequence code = Code )
integer int
switch op do
case PROC, PROC_TAIL then
sequence info = SymTab[code[pc+1]]
return info[S_NUM_ARGS] + 2 + (info[S_TOKEN] != PROC)

case PROC_FORWARD then
int = code[pc+2]
int += 3
case FUNC_FORWARD then
int = code[pc+2]
int += 4
case RIGHT_BRACE_N, CONCAT_N then
int = code[pc+1]
int += 3
case else
InternalErr( 269, {op} )
end switch
return int
end function

function op_size( integer pc, sequence code = Code )
integer op = code[pc]
sequence info = op_info[op]
integer int = info[OP_SIZE_TYPE]
integer int = op_info_size_type[op]

if int = FIXED_SIZE then
int = info[OP_SIZE]
return int
return op_info_size[op]
else
switch op do
case PROC, PROC_TAIL then
info = SymTab[code[pc+1]]
return info[S_NUM_ARGS] + 2 + (info[S_TOKEN] != PROC)
case PROC_FORWARD then
int = code[pc+2]
int += 3
case FUNC_FORWARD then
int = code[pc+2]
int += 4
case RIGHT_BRACE_N, CONCAT_N then
int = code[pc+1]
int += 3
case else
InternalErr( 269, {op} )
end switch
return int
return variable_op_size( pc, op, code )
end if
end function

export function advance( integer pc, sequence code = Code )
pc += op_size( pc, code )
return pc
integer size = op_size( pc, code )
return pc + size
end function

procedure shift_switch( integer pc, integer start, integer amount )
Expand Down Expand Up @@ -376,10 +406,10 @@ export procedure shift( integer start, integer amount, integer bound = start )
integer finish = start + amount - 1
integer len = length( Code )
while pc <= len do
op = Code[pc]
if pc < start or pc > finish then
op = Code[pc]
sequence addrs = op_info[op][OP_ADDR]
for i = 1 to length( addrs ) do

if length( op_info_addr[op] ) then

switch op with fallthru do
case SWITCH then
Expand All @@ -391,13 +421,19 @@ export procedure shift( integer start, integer amount, integer bound = start )
break

case else
int = addrs[i]
int = op_info_addr[op][1]
shift_addr( pc + int, amount, start, bound )

end switch
end for
end if
end if
integer size_type = op_info_size_type[op]
if size_type = FIXED_SIZE then
-- most common case...inline this for speed
pc += op_info_size[op]
else
pc += variable_op_size( pc, op )
end if
pc = advance( pc )
end while
shift_fwd_refs( start, amount )
move_last_pc( amount )
Expand Down Expand Up @@ -508,6 +544,7 @@ export function get_target_sym( sequence opseq )

case RIGHT_BRACE_N, CONCAT_N then
return opseq[opseq[2]+2]


end switch
end if
Expand Down

0 comments on commit 54c2637

Please sign in to comment.