<div> </div><div>Is there a way to save a reference to a Basic Block that gets all fixed up in the linker, so that you can branch to it during execution?  (Or maybe just a better way to do what I'm trying to do?)</div>
<div> </div><div>In my old-school BASIC compiler that I'm writing with LLVM, for each GOSUB, I keep a map of an integer ID and a pointer to the basic block following the GOSUB to return to.</div><div>Then, when a BASIC RETURN is executed, it pops the integer ID off a software stack and executes a switch statement based on that ID to branch to the Base Block to return to for that integer ID.</div>
<div> </div><div>(I attached a text file with the input file, output file, and generated LLVM code, if you want to see all the details).</div><div> </div><div>But to explain it in psudeo code:</div><div> </div><div>The BASIC code is:</div>
<div> </div><div>gosub sub1</div><div>gosub sub2</div><div> </div><div>sub1: </div><div>sub2: </div><div> return</div><div> </div><div>(Note the "subroutine" has multiple entry points, or put another way, the subroutines can share common code or return statements)</div>
<div> </div><div>Which translates to this llvm psuedo code:</div><div> </div><div>basicblock1: ext_runtime_function_push(101): br sub1     <-- 101 could be anything, the compiler stores a map of 101-to-basicblock1_ret</div>
<div>basicblock1_ret:</div><div>basicblock2: ext_runtime_function_push(102): br sub2     <-- 102 could be anything, the compiler stores a map of 102-to-basicblock2_ret</div><div>basicblock2_ret:</div><div>  br somewhere</div>
<div><div> </div><div>basicblock.sub1:  ...</div></div><div>basicblock.sub2:   ...</div><div>  br basicblock.ret</div><div> </div><div>basicblock.ret:</div><div>  switch( ext_runtime_func_pop() )</div><div>  case 101: br basicblock1_ret   <-- generated from the compiler's map of 101-to-basicblock1_ret</div>
<div><div>   case 102: br basicblock2_ret   <-- generated from the compiler's map of 102-to-basicblock2_ret</div><div>  default: error</div><div> </div><div>Which works just fine. But what would be nice would be:</div>
<div> </div><div><div>basicblock1:  ext_func_push(handleof(basicblock1_ret) ): br sub1</div><div>basicblock1_ret:</div><div>basicblock2: ext_func_push(handleof(basicblock2_ret)): br sub2</div><div>basicblock2_ret:</div><div>
  br somewhere</div><div><div> </div><div>basicblock.sub1: br basicblock.ret</div></div><div>basicblock.sub2: br basicblock.ret</div><div> </div><div>basicblock.ret:</div><div>  br ext_func_pop()</div><div> </div><div>Where, in the generated & linked Intel 386 assembly, its obvious that the ext_func_push could push the 32-bit address of the basicblock1_ret label, and the br would jump to that address.  But how to get there from here?</div>
<div> </div><div>Since I have a working solution, this is just a "shouldn't there be a more elegant way to do this?" question.</div><div> </div><div>Thanks!!!</div><div> </div><div> </div><div> </div></div></div>