How can I add reference to a variable defined in previous function in LLVM IR? -


i'm new llvm ir , i'm implementing pl0 language. http://en.wikipedia.org/wiki/pl/0

i'm generating testfile following:

const = 10; var b, c;  procedure check1; var dd;    procedure check2;        c := 2; begin    dd := 1 end;  begin     b := -1024+53*(-514-766)/93+100;     c := b end. 

and llvm ir generated this:

; moduleid = 'llvm module'  define void @__global_main_entry__() { blockunitentry:   %b = alloca i32   %c = alloca i32   store i32 -1653, i32* %b   %b1 = load i32* %b   store i32 %b1, i32* %c   ret void }  define void @check1() { procedureentry:   %dd = alloca i32   store i32 1, i32* %dd   ret void }  define void @check2() { procedureentry:   store i32 2, i32* %c   ret void } 

i got painful error here (at destruction):

while deleting: i32* %c use still stuck around after def destroyed:  store i32 2, i32* %c test004_llvm_generate: /files/install/llvm_framework/llvm/lib/ir/value.cpp:79: virtual llvm::value::~value(): assertion `use_empty() && "uses remain when value destroyed!"' failed. 

i guess using variable c(defined in __global_main_entry__) in procedure check2 adds ref in llvm::value, when destructing __global_main_entry__ ref @ check2 causing error.

i not know how solve problem, , if have time specific, please~

(moreover, except official documentation of llvm. there more resources on llvm? found tutorials outdated.)

my full list of code here: https://github.com/adamcavendish/pl0compiler

thanks in advance.

your ir malformed - cannot refer instruction body of function different 1 in instruction appears, referring %c in @check2 illegal. failure happened occur during module destruction, can occur in other circumstances well.

in general, recommend running opt -verify on ir if you're not sure it's legal, give nice error messages. my eclipse plugin might if want experiment ir see when , isn't legal.

as solution, looks should create global variable represent c, not instruction. can store , load in every function in module.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -