diff options
author | Christopher Li <sparse@chrisli.org> | 2012-06-21 02:46:53 -0700 |
---|---|---|
committer | Christopher Li <sparse@chrisli.org> | 2012-06-21 02:46:53 -0700 |
commit | 70c5b9619f9f3d4a33af043d019a073a4dc6e470 (patch) | |
tree | ae7b6b0dbcd45b260b91aef8fa6837b34ff0858c | |
parent | 64a6b4c61faa23c40a402656d044141a669965a3 (diff) | |
parent | ccf42dc22ef4354ef6db1673a5e2b2bc0a6be273 (diff) | |
download | sparse-70c5b9619f9f3d4a33af043d019a073a4dc6e470.tar.gz |
Merge branch 'for-chris' of git://github.com/penberg/sparse-llvm
Pull 'for-chris' tree from Pekka Enberg:
"Please pull the latest sparse-llvm tree from:
git@github.com:penberg/sparse-llvm.git for-chris
It has one new validation test case and fixes to handle strings properly
in the LLVM backend."
Pekka Enberg (4):
sparse, llvm: Add _Bool to cast validation test
sparse, llvm: Simplify output_data() type logic
sparse, llvm: Fix string initializer code generation
sparse, llvm: Fix global string access code generation
-rw-r--r-- | sparse-llvm.c | 16 | ||||
-rw-r--r-- | validation/backend/cast.c | 3 |
2 files changed, 17 insertions, 2 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c index 9226a212..6b94205d 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -308,7 +308,6 @@ static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *ins struct expression *expr; assert(sym->bb_target == NULL); - assert(sym->ident == NULL); expr = sym->initializer; if (expr) { @@ -326,6 +325,13 @@ static LLVMValueRef pseudo_to_value(struct function *fn, struct instruction *ins result = LLVMConstGEP(data, indices, ARRAY_SIZE(indices)); break; } + case EXPR_SYMBOL: { + struct symbol *sym = expr->symbol; + + result = LLVMGetNamedGlobal(fn->module, show_ident(sym->ident)); + assert(result != NULL); + break; + } default: assert(0); } @@ -1181,6 +1187,12 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym) initial_value = output_data(module, sym); break; } + case EXPR_STRING: { + const char *s = initializer->string->data; + + initial_value = LLVMConstString(strdup(s), strlen(s) + 1, true); + break; + } default: assert(0); } @@ -1192,7 +1204,7 @@ static LLVMValueRef output_data(LLVMModuleRef module, struct symbol *sym) name = show_ident(sym->ident); - data = LLVMAddGlobal(module, symbol_type(module, sym->ctype.base_type), name); + data = LLVMAddGlobal(module, LLVMTypeOf(initial_value), name); LLVMSetLinkage(data, data_linkage(sym)); diff --git a/validation/backend/cast.c b/validation/backend/cast.c index 3e677446..598b16aa 100644 --- a/validation/backend/cast.c +++ b/validation/backend/cast.c @@ -1,3 +1,4 @@ +typedef _Bool bool; typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; @@ -11,6 +12,7 @@ typedef unsigned long long ulonglong; } #define DEFINE_CASTS(from) \ + DEFINE_CAST(from, bool) \ DEFINE_CAST(from, char) \ DEFINE_CAST(from, uchar) \ DEFINE_CAST(from, short) \ @@ -26,6 +28,7 @@ typedef unsigned long long ulonglong; DEFINE_CAST(from, double) */ +DEFINE_CASTS(bool) DEFINE_CASTS(char) DEFINE_CASTS(uchar) DEFINE_CASTS(short) |