Guest User

Untitled

a guest
Aug 9th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. test_code += ["#include <stdlib.h>"]
  2. test_code += ["#define STR_(x) #x"]
  3. test_code += ["#define STR(x) STR_(x)"]
  4. test_code += [
  5. "#define TEST(lhs, rhs) if(lhs(val8, lb8, sz8) != rhs(val8, lb8, sz8)) { fprintf(stderr, \"%s != %s (%d vs %d) -- %d/%d/%d\\n\", STR(lhs), STR(rhs), lhs(val8, lb8, sz8), rhs(val8, lb8, sz8), val, lb, ub); return 1; }"
  6. ]
  7. for pf in prefixes:
  8. for decl in pf[2]:
  9. test_code += [
  10. "extern _Bool {}(unsigned char, unsigned char, unsigned char);".
  11. format(decl)
  12. ]
  13.  
  14. test_code += ["int main() {"]
  15. test_code += ["unsigned val, lb, ub;"]
  16. test_code += ["for(val = 0; val < 256; ++val) {"]
  17. test_code += ["for(lb = 0; lb < 256; ++lb) {"]
  18. test_code += ["for(ub = lb; ub < 256; ++ub) {"]
  19. test_code += ["unsigned char val8, lb8, sz8;"]
  20. test_code += ["val8 = val; lb8 = lb; sz8 = ub - lb;"]
  21.  
  22. num_decls = len(prefixes[0][2])
  23. for i in range(0, num_decls):
  24. test_code += ["TEST({}, {});".format(prefixes[0][2][i], prefixes[1][2][i])]
  25. test_code += ["}}}"]
  26. test_code += ["fprintf(stderr, \"Success!\\n\");"]
  27. test_code += ["return 0; }"]
  28.  
  29. f = open("test-bounds.c", "w+")
  30. f.write("\n".join(test_code))
  31. f.close()
  32. assert os.system("ninja") == 0
  33. assert os.system(
  34. "{} -filetype=obj -O3 -mcpu=native test-new.ll -o test-new.o".format(
  35. new_llc)) == 0
  36. assert os.system(
  37. "llc -filetype=obj -O3 -mcpu=native test-old.ll -o test-old.o") == 0
  38. assert os.system("clang -O3 -c test-bounds.c -o test-bounds.o") == 0
  39. assert os.system(
  40. "clang test-bounds.o test-new.o test-old.o -o bounds-test") == 0
  41.  
  42. assert os.system("./bounds-test") == 0
  43.  
Advertisement
Add Comment
Please, Sign In to add comment