Clean up run script to use for testing Subzero.

Adds the python script run-llvm2ice.py (was llvm2iceinsts.py) that
automatically handles conversion of LLVM source to a PEXE file,
and then runs llvm2ice on the corresponding PEXE file.

Also, defines three paths in tests, based on the executable chosen:

  %lc2i - Directly reads from LLVM source, and converts to Subzero.
  %l2i  - Parses a PEXE file into LLVM IR, and converts to Subzero.
  %p2i  - Parses a PEXE directly into Subzero.

Note that for all three executables, the same arguments can be used,
making it easy to change how the input is handled.

Also moves tests to use %p2i whenever possible.

BUG= https://code.google.com/p/nativeclient/issues/detail?id=3892
R=jvoung@chromium.org

Review URL: https://codereview.chromium.org/600043002
diff --git a/tests_lit/reader_tests/alloca.ll b/tests_lit/reader_tests/alloca.ll
index 04b203a..fd1dea3 100644
--- a/tests_lit/reader_tests/alloca.ll
+++ b/tests_lit/reader_tests/alloca.ll
@@ -1,10 +1,6 @@
 ; Test if we can read alloca instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 ; Show examples where size is defined by a constant.
 
diff --git a/tests_lit/reader_tests/binops.ll b/tests_lit/reader_tests/binops.ll
index 25dd0fa..5fde67c 100644
--- a/tests_lit/reader_tests/binops.ll
+++ b/tests_lit/reader_tests/binops.ll
@@ -1,10 +1,6 @@
 ; Tests if we can read binary operators.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 ; TODO(kschimpf): add i8/i16. Needs bitcasts.
 
diff --git a/tests_lit/reader_tests/branch.ll b/tests_lit/reader_tests/branch.ll
index 66e9d5e..46b7ffa 100644
--- a/tests_lit/reader_tests/branch.ll
+++ b/tests_lit/reader_tests/branch.ll
@@ -1,10 +1,6 @@
 ; Tests if we handle a branch instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 define void @SimpleBranch() {
 entry:
diff --git a/tests_lit/reader_tests/call-indirect.ll b/tests_lit/reader_tests/call-indirect.ll
index 13221d0..35f73e3 100644
--- a/tests_lit/reader_tests/call-indirect.ll
+++ b/tests_lit/reader_tests/call-indirect.ll
@@ -1,10 +1,6 @@
 ; Test parsing indirect calls in Subzero.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 define internal void @CallIndirectVoid(i32 %f_addr) {
 entry:
diff --git a/tests_lit/reader_tests/call.ll b/tests_lit/reader_tests/call.ll
index f70c44a..ffe5e04 100644
--- a/tests_lit/reader_tests/call.ll
+++ b/tests_lit/reader_tests/call.ll
@@ -1,10 +1,6 @@
 ; Test handling of call instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 define i32 @fib(i32 %n) {
 entry:
diff --git a/tests_lit/reader_tests/casts.ll b/tests_lit/reader_tests/casts.ll
index 2346bec..26dc8b7 100644
--- a/tests_lit/reader_tests/casts.ll
+++ b/tests_lit/reader_tests/casts.ll
@@ -1,9 +1,6 @@
 ; Tests if we can read cast operations.
 
-; RUN: llvm-as < %s | pnacl-freeze \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts --no-local-syms | FileCheck %s
 
 ; TODO(kschimpf) Find way to test pointer conversions (since they in general
 ; get removed by pnacl-freeze).
diff --git a/tests_lit/reader_tests/compare.ll b/tests_lit/reader_tests/compare.ll
index 40f65db..51eb581 100644
--- a/tests_lit/reader_tests/compare.ll
+++ b/tests_lit/reader_tests/compare.ll
@@ -1,10 +1,6 @@
 ; Test if we can read compare instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 define i1 @IcmpI1(i32 %p1, i32 %p2) {
 entry:
diff --git a/tests_lit/reader_tests/constants.ll b/tests_lit/reader_tests/constants.ll
index 85d962a..feb7dcd 100644
--- a/tests_lit/reader_tests/constants.ll
+++ b/tests_lit/reader_tests/constants.ll
@@ -1,10 +1,6 @@
 ; Test handling of constants in function blocks.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 define void @TestIntegers() {
 entry:
diff --git a/tests_lit/reader_tests/forwardref.ll b/tests_lit/reader_tests/forwardref.ll
index 21d33d5..b938b6c 100644
--- a/tests_lit/reader_tests/forwardref.ll
+++ b/tests_lit/reader_tests/forwardref.ll
@@ -1,10 +1,6 @@
 ; Test use forward type references in function blocks.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 ; RUN: llvm-as < %s | pnacl-freeze | pnacl-bcdis -no-records \
 ; RUN:              | FileCheck --check-prefix=DUMP %s
diff --git a/tests_lit/reader_tests/globalinit.pnacl.ll b/tests_lit/reader_tests/globalinit.pnacl.ll
index 2620d90..4bdb4f8 100644
--- a/tests_lit/reader_tests/globalinit.pnacl.ll
+++ b/tests_lit/reader_tests/globalinit.pnacl.ll
@@ -1,22 +1,14 @@
 ; Test of global initializers.
 
 ; Check that we generate proper global initializers.
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -verbose inst -build-on-read \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --args -verbose inst | FileCheck %s
 
 ; Check that what we generate is valid assembly
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -verbose none -build-on-read \
-; RUN:                -allow-local-symbol-tables \
+; RUN: %p2i -i %s --args -verbose none \
 ; RUN:     | llvm-mc -triple=i686-none-nacl -x86-asm-syntax=intel -filetype=obj
 
 ; Check that we don't generate errors
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -verbose none -build-on-read \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck --check-prefix=ERRORS %s
+; RUN: %p2i -i %s --args -verbose none | FileCheck --check-prefix=ERRORS %s
 
 @PrimitiveInit = internal global [4 x i8] c"\1B\00\00\00", align 4
 ; CHECK: .data
diff --git a/tests_lit/reader_tests/insertextract.ll b/tests_lit/reader_tests/insertextract.ll
index c77acf2..9dbe6aa 100644
--- a/tests_lit/reader_tests/insertextract.ll
+++ b/tests_lit/reader_tests/insertextract.ll
@@ -1,11 +1,6 @@
 ; Tests insertelement and extractelement vector instructions.
 
-
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 ; TODO(kschimpf): Change index arguments to valid constant indices once
 ; we can handle constants.
diff --git a/tests_lit/reader_tests/load.ll b/tests_lit/reader_tests/load.ll
index 117dbbf..7b579d3 100644
--- a/tests_lit/reader_tests/load.ll
+++ b/tests_lit/reader_tests/load.ll
@@ -1,9 +1,6 @@
 ; Test if we can read load instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:              | FileCheck %s
+; RUN: %p2i --no-local-syms -i %s --insts | FileCheck %s
 
 define i32 @load_i8(i32 %addr) {
 entry:
diff --git a/tests_lit/reader_tests/nacl-atomic-intrinsics.ll b/tests_lit/reader_tests/nacl-atomic-intrinsics.ll
index 37bb05c..bc9011e 100644
--- a/tests_lit/reader_tests/nacl-atomic-intrinsics.ll
+++ b/tests_lit/reader_tests/nacl-atomic-intrinsics.ll
@@ -1,10 +1,6 @@
 ; Test parsing NaCl atomic instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 declare i8 @llvm.nacl.atomic.load.i8(i8*, i32)
 declare i16 @llvm.nacl.atomic.load.i16(i16*, i32)
diff --git a/tests_lit/reader_tests/nacl-fake-intrinsic.ll b/tests_lit/reader_tests/nacl-fake-intrinsic.ll
index 65d9459..f4a6604 100644
--- a/tests_lit/reader_tests/nacl-fake-intrinsic.ll
+++ b/tests_lit/reader_tests/nacl-fake-intrinsic.ll
@@ -1,6 +1,8 @@
 ; Tests that we don't get fooled by a fake NaCl intrinsic.
 
-
+; TODO(kschimpf) Find way to run this through p2i. Note: Can't do this
+;                currently because run-llvm2ice.py raises exception on error,
+;                and output is lost.
 ; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
 ; RUN:              | not %llvm2ice -notranslate -verbose=inst -build-on-read \
 ; RUN:                -allow-pnacl-reader-error-recovery \
diff --git a/tests_lit/reader_tests/nacl-other-intrinsics.ll b/tests_lit/reader_tests/nacl-other-intrinsics.ll
index a1ab031..eda03a3 100644
--- a/tests_lit/reader_tests/nacl-other-intrinsics.ll
+++ b/tests_lit/reader_tests/nacl-other-intrinsics.ll
@@ -1,10 +1,6 @@
 ; This tests parsing NaCl intrinsics not related to atomic operations.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 declare i8* @llvm.nacl.read.tp()
 declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
diff --git a/tests_lit/reader_tests/phi.ll b/tests_lit/reader_tests/phi.ll
index 0186d4c..3799d4b 100644
--- a/tests_lit/reader_tests/phi.ll
+++ b/tests_lit/reader_tests/phi.ll
@@ -1,10 +1,6 @@
 ; Test reading phi instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 ; TODO(kschimpf) Add forward reference examples.
 
diff --git a/tests_lit/reader_tests/select.ll b/tests_lit/reader_tests/select.ll
index 954c80e..8177fa3 100644
--- a/tests_lit/reader_tests/select.ll
+++ b/tests_lit/reader_tests/select.ll
@@ -1,10 +1,6 @@
 ; Tests if we can read select instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 define void @Seli1(i32 %p) {
 entry:
diff --git a/tests_lit/reader_tests/store.ll b/tests_lit/reader_tests/store.ll
index ac1f711..c507175 100644
--- a/tests_lit/reader_tests/store.ll
+++ b/tests_lit/reader_tests/store.ll
@@ -1,9 +1,6 @@
 ; Test if we can read store instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts --no-local-syms | FileCheck %s
 
 define void @store_i8(i32 %addr) {
 entry:
diff --git a/tests_lit/reader_tests/switch.ll b/tests_lit/reader_tests/switch.ll
index 7edaeda..bb60e55 100644
--- a/tests_lit/reader_tests/switch.ll
+++ b/tests_lit/reader_tests/switch.ll
@@ -1,10 +1,6 @@
 ; Test switch instructions.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 define void @testDefaultSwitch(i32 %a) {
 entry:
diff --git a/tests_lit/reader_tests/unnamed.ll b/tests_lit/reader_tests/unnamed.ll
index 72c274c..8495ee5 100644
--- a/tests_lit/reader_tests/unnamed.ll
+++ b/tests_lit/reader_tests/unnamed.ll
@@ -1,15 +1,10 @@
 ; Tests that we name unnamed global addresses.
 
-; RUN: llvm-as < %s | pnacl-freeze \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:              | FileCheck %s
+; RUN: %p2i --no-local-syms -i %s --insts | FileCheck %s
 
-; RUN: llvm-as < %s | pnacl-freeze \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -default-function-prefix=h -default-global-prefix=g \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:              | FileCheck --check-prefix=BAD %s
+; RUN: %p2i --no-local-syms -i %s --insts --args \
+; RUN:      -default-function-prefix=h -default-global-prefix=g \
+; RUN:      | FileCheck --check-prefix=BAD %s
 
 ; TODO(kschimpf) Check global variable declarations, once generated.
 
diff --git a/tests_lit/reader_tests/unreachable.ll b/tests_lit/reader_tests/unreachable.ll
index 954c8f8..4cd2f9d 100644
--- a/tests_lit/reader_tests/unreachable.ll
+++ b/tests_lit/reader_tests/unreachable.ll
@@ -1,10 +1,6 @@
 ; Test parsing unreachable instruction.
 
-; RUN: llvm-as < %s | pnacl-freeze -allow-local-symbol-tables \
-; RUN:              | %llvm2ice -notranslate -verbose=inst -build-on-read \
-; RUN:                -allow-pnacl-reader-error-recovery \
-; RUN:                -allow-local-symbol-tables \
-; RUN:              | FileCheck %s
+; RUN: %p2i -i %s --insts | FileCheck %s
 
 define internal i32 @divide(i32 %num, i32 %den) {
 entry: