Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix relational operators with downto arrays

  • Loading branch information...
commit 1581b3e770c9259cc80627c54ebe7ba660c6cf1b 1 parent 7351254
Nick Gasson nickg authored

Showing 3 changed files with 36 additions and 14 deletions. Show diff stats Hide diff stats

  1. +1 1  Makefile.am
  2. +29 13 src/cgen.c
  3. +6 0 test/regress/ieee3.vhd
2  Makefile.am
@@ -5,6 +5,6 @@ EXTRA_DIST = autogen.sh
5 5 ACLOCAL_AMFLAGS = -I m4
6 6
7 7 bootstrap: all
8   - @cd lib && $(MAKE) $(AM_MAKEFLAGS) bootstrap
  8 + @cd lib && $(MAKE) $(AM_MAKEFLAGS) clean bootstrap
9 9
10 10 .PHONY: bootstrap
42 src/cgen.c
@@ -316,6 +316,14 @@ static LLVMValueRef cgen_uarray_low(LLVMValueRef array)
316 316 return LLVMBuildSelect(builder, is_downto, right, left, "low");
317 317 }
318 318
  319 +static LLVMValueRef cgen_array_dir(type_t type, LLVMValueRef var)
  320 +{
  321 + if (type_kind(type) == T_UARRAY || !cgen_const_bounds(type))
  322 + return LLVMBuildExtractValue(builder, var, 3, "dir");
  323 + else
  324 + return llvm_int8(type_dim(type, 0).kind);
  325 +}
  326 +
319 327 static LLVMValueRef cgen_array_len(type_t type, LLVMValueRef data)
320 328 {
321 329 if (type_kind(type) == T_CARRAY && cgen_const_bounds(type)) {
@@ -482,17 +490,8 @@ static void cgen_array_copy(type_t src_type, type_t dest_type,
482 490 LLVMValueRef src, LLVMValueRef dst,
483 491 LLVMValueRef offset)
484 492 {
485   - LLVMValueRef src_dir;
486   - if (type_kind(src_type) == T_UARRAY || !cgen_const_bounds(src_type))
487   - src_dir = LLVMBuildExtractValue(builder, src, 3, "dir");
488   - else
489   - src_dir = llvm_int8(type_dim(src_type, 0).kind);
490   -
491   - LLVMValueRef dst_dir;
492   - if (type_kind(dest_type) == T_UARRAY || !cgen_const_bounds(dest_type))
493   - dst_dir = LLVMBuildExtractValue(builder, dst, 3, "dir");
494   - else
495   - dst_dir = llvm_int8(type_dim(dest_type, 0).kind);
  493 + LLVMValueRef src_dir = cgen_array_dir(src_type, src);
  494 + LLVMValueRef dst_dir = cgen_array_dir(dest_type, dst);
496 495
497 496 LLVMValueRef opposite_dir =
498 497 LLVMBuildICmp(builder, LLVMIntNE, src_dir, dst_dir, "opp_dir");
@@ -836,6 +835,14 @@ static LLVMValueRef cgen_array_rel(LLVMValueRef lhs, LLVMValueRef rhs,
836 835 LLVMValueRef left_base = cgen_array_data_ptr(left_type, lhs);
837 836 LLVMValueRef right_base = cgen_array_data_ptr(right_type, rhs);
838 837
  838 + LLVMValueRef ldir = cgen_array_dir(left_type, lhs);
  839 + LLVMValueRef rdir = cgen_array_dir(right_type, rhs);
  840 +
  841 + LLVMValueRef l_downto = LLVMBuildICmp(builder, LLVMIntEQ, ldir,
  842 + llvm_int8(RANGE_DOWNTO), "l_downto");
  843 + LLVMValueRef r_downto = LLVMBuildICmp(builder, LLVMIntEQ, rdir,
  844 + llvm_int8(RANGE_DOWNTO), "r_downto");
  845 +
839 846 LLVMValueRef i = LLVMBuildAlloca(builder, LLVMInt32Type(), "i");
840 847 LLVMBuildStore(builder, llvm_int32(0), i);
841 848
@@ -861,10 +868,19 @@ static LLVMValueRef cgen_array_rel(LLVMValueRef lhs, LLVMValueRef rhs,
861 868
862 869 LLVMPositionBuilderAtEnd(builder, body_bb);
863 870
  871 + LLVMValueRef i_plus_1 = LLVMBuildAdd(builder, i_loaded, llvm_int32(1), "");
  872 + LLVMValueRef l_off_down = LLVMBuildSub(builder, left_len, i_plus_1, "");
  873 + LLVMValueRef r_off_down = LLVMBuildSub(builder, right_len, i_plus_1, "");
  874 +
  875 + LLVMValueRef l_off = LLVMBuildSelect(builder, l_downto,
  876 + l_off_down, i_loaded, "l_off");
  877 + LLVMValueRef r_off = LLVMBuildSelect(builder, r_downto,
  878 + r_off_down, i_loaded, "r_off");
  879 +
864 880 LLVMValueRef l_ptr = LLVMBuildGEP(builder, left_base,
865   - &i_loaded, 1, "l_ptr");
  881 + &l_off, 1, "l_ptr");
866 882 LLVMValueRef r_ptr = LLVMBuildGEP(builder, right_base,
867   - &i_loaded, 1, "r_ptr");
  883 + &r_off, 1, "r_ptr");
868 884
869 885 LLVMValueRef l_val = LLVMBuildLoad(builder, l_ptr, "l_val");
870 886 LLVMValueRef r_val = LLVMBuildLoad(builder, r_ptr, "r_val");
6 test/regress/ieee3.vhd
@@ -13,10 +13,16 @@ begin
13 13 begin
14 14 x := to_unsigned(3, 8);
15 15 y := to_unsigned(5, 8);
  16 +
  17 + assert y > x;
  18 + assert y >= x;
  19 + assert x <= y;
  20 + assert x < y;
16 21 assert to_integer(x) = 3;
17 22 assert (x + y) = 8;
18 23 assert (y - x) = 2;
19 24 assert (x * y) = 15;
  25 + assert (y / x) = 1;
20 26 wait;
21 27 end process;
22 28

0 comments on commit 1581b3e

Please sign in to comment.
Something went wrong with that request. Please try again.