From 9e256c085149afef4bf0991d1fc75a8f50238403 Mon Sep 17 00:00:00 2001 From: inglorion Date: Fri, 19 Aug 2011 10:13:22 +0200 Subject: [PATCH] arm_gas_generator: Emit constants at every goto and every return to top level --- lib/voodoo/generators/arm_gas_generator.rb | 33 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/voodoo/generators/arm_gas_generator.rb b/lib/voodoo/generators/arm_gas_generator.rb index 9f54f8d..bef7e2a 100644 --- a/lib/voodoo/generators/arm_gas_generator.rb +++ b/lib/voodoo/generators/arm_gas_generator.rb @@ -271,6 +271,16 @@ module Voodoo count end + # Writes any constants that need to be written to the instruction + # stream, and clears the list of constants that need to be written. + def emit_constants + @constants.each do |x| + label x[0] + word x[1] + end + @constants = [] + end + # Emit function prologue. def emit_function_prologue formals = [], nlocals = 0 # Calculate the number of arguments we were passed in @@ -295,7 +305,7 @@ module Voodoo # If we are returning to top level, restore stack pointer # and saved registers. if @environment.parent == @top_level - offset = @frame_size - @saved_registers * @WORDSIZE + offset = @frame_size - @saved_registers.length * @WORDSIZE if offset > 0 emit "add sp, sp, \##{offset}\n" end @@ -303,6 +313,13 @@ module Voodoo @frame_size = 0 @frame_offset = 0 @saved_registers = [] + + # If we need to emit constants, do so now + unless @constants.empty? + lbl = gensym + goto lbl + label lbl + end end # Restore old value of @environment @@ -334,12 +351,7 @@ module Voodoo @frame_offset = 0 @saved_registers = [] - # Emit constants - @constants.each do |x| - label x[0] - word x[1] - end - @constants = [] + emit_constants emit "# end function\n\n" @@ -464,6 +476,9 @@ module Voodoo # Jump to a label. def goto label emit "b #{label}\n" + + # If we have constants that need to be emitted, do so now + emit_constants end # Grows the current frame by n words, plus padding to @@ -601,8 +616,8 @@ module Voodoo end else # Assume global - label = add_constant x - emit "ldr #{register}, #{label}\n" + lbl = add_constant x + emit "ldr #{register}, #{lbl}\n" return register end elsif at_expr? x -- 2.11.4.GIT