Advertisement
Guest User

Untitled

a guest
Jul 8th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LLVM 1.63 KB | None | 0 0
  1. I'm having a bit of trouble getting the output from
  2.     CreateAlloca()
  3.     CreateLoad()
  4.     CreateStore()
  5.  
  6. In the right place. If inside the production, I (incorrectly) have
  7.  
  8.     statement: T_ID '=' expression
  9.     {
  10.         // The code that is retrieving 'expression' as a Value* and being built as an AssignVarAST is here
  11.         Function *print_int = gen_print_int_def();
  12.         Function *TheFunction = gen_main_def(RetVal, print_int);
  13.         verifyFunction(*TheFunction);
  14.     }
  15.  
  16. Then I get the resulting output, where the highlighted lines are what I want after
  17.     define i32 @main(){
  18.     entry:
  19.         // All the highlighted lines I want here in the same order
  20.     }
  21.  
  22. http://i.imgur.com/2bxr1TD.png
  23.  
  24. However if I take away gen_print_int_def() and gen_main_def() from the production T_ID '=' expression, then I get the following result, where all the lines I want aren't going to the output any more.
  25.  
  26. http://i.imgur.com/FFdlzpi.png
  27.  
  28. I understand that in the first picture I'm getting multiple instances of  
  29.     declare i32 @print_int(i32)
  30.  
  31.     define i32 @main()
  32.  
  33. Because I'm calling T_ID '=' expression twice, followed by a single T_ID '(' expression ')'.
  34.  
  35. From what I can tell, calls to the functions Builder.CreateAlloca(), Builder.CreateLoad(), Builder.CreateStore() won't go to the output unless
  36.  
  37.     BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
  38.     Builder.SetInsertPoint(BB);
  39.  
  40. From gen_main_def() is done first. Since T_ID '(' expression ')' is the last line in the example, that is the reason I'm not getting the lines from the first picture in the second picture.
  41.  
  42. Any help in clarifying how I can remedy this issue would be greatly appreciated
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement