Skip to content

Commit

Permalink
Sulong: Add LLIRTestGen and respective mx projects
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorcos committed Nov 5, 2019
1 parent 40cc6f5 commit e98e854
Show file tree
Hide file tree
Showing 5 changed files with 984 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sulong/mx.sulong/mx_sulong.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,9 @@ def create_asm_parser(args=None, out=None):
"""create the inline assembly parser using antlr"""
mx.suite("truffle").extensions.create_parser("com.oracle.truffle.llvm.asm.amd64", "com.oracle.truffle.llvm.asm.amd64", "InlineAssembly", COPYRIGHT_HEADER_BSD, args, out)

def llirtestgen(args=None, out=None):
return mx.run_java(mx.get_runtime_jvm_args(["LLIR_TEST_GEN"]) + ["com.oracle.truffle.llvm.tests.llirtestgen.LLIRTestGen"] + args, out=out)

mx.update_commands(_suite, {
'lli' : [runLLVM, ''],
'test-llvm-image' : [_test_llvm_image, 'test a pre-built LLVM image'],
Expand Down
39 changes: 39 additions & 0 deletions sulong/mx.sulong/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,34 @@
"jacoco" : "exclude",
},

"com.oracle.truffle.llvm.tests.llirtestgen" : {
"subDir" : "tests",
"sourceDirs" : ["src"],
"checkstyle" : "com.oracle.truffle.llvm.runtime",
"javaCompliance" : "1.8+",
"license" : "BSD-new",
"testProject" : True,
"defaultBuild" : False,
"jacoco" : "exclude",
},
"com.oracle.truffle.llvm.tests.llirtestgen.generated" : {
"class": "GeneratedTestSuite",
"subDir" : "tests",
"native" : True,
"vpath" : True,
"variants" : ["O0"],
"buildDependencies" : [
"LLIR_TEST_GEN",
],
"buildEnv" : {
"LDFLAGS": "-lm",
"LLIR_TEST_GEN_JAR" : "<path:LLIR_TEST_GEN>",
},
"license" : "BSD-new",
"testProject" : True,
"defaultBuild" : False,
},

"com.oracle.truffle.llvm.tests.pipe.native" : {
"subDir" : "tests",
"native" : True,
Expand Down Expand Up @@ -1068,6 +1096,16 @@
"defaultBuild" : False,
},

"LLIR_TEST_GEN" : {
"relpath" : True,
"dependencies" : [
"com.oracle.truffle.llvm.tests.llirtestgen",
],
"license" : "BSD-new",
"testDistribution" : True,
"defaultBuild" : False,
},

"SULONG_TEST_SUITES" : {
"native" : True,
"relpath" : True,
Expand All @@ -1078,6 +1116,7 @@
"dependency:com.oracle.truffle.llvm.tests.bitcode.uncommon.native/*",
"dependency:com.oracle.truffle.llvm.tests.bitcodeformat.native/*",
"dependency:com.oracle.truffle.llvm.tests.debug.native/*",
"dependency:com.oracle.truffle.llvm.tests.llirtestgen.generated/*",
"dependency:com.oracle.truffle.llvm.tests.irdebug.native/*",
"dependency:com.oracle.truffle.llvm.tests.interop.native/*",
"dependency:com.oracle.truffle.llvm.tests.other.native/*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# Copyright (c) 2019, 2019, Oracle and/or its affiliates.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
# conditions and the following disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
# endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#

JAVA=$(JAVA_HOME)/bin/java
LLIRTESTGEN_CMD=$(JAVA) -Dllirtestgen.prelude=prelude.ll -cp $(LLIR_TEST_GEN_JAR) com.oracle.truffle.llvm.tests.llirtestgen.LLIRTestGen
OUTPUT_DIR=gen
GENERATED=$(TESTS:=.ll)
TIMESTAMP=timestamp

GENERATED_REFS=$(GENERATED:.ll=/ref.out)
GENERATED_BCS=$(GENERATED:.ll=/O0.bc)

all: $(GENERATED_REFS) $(GENERATED_BCS)

include $(VPATH)/../Makefile

prelude.ll: prelude.bc
$(LLVM_DIS) $<

prelude.bc: prelude.c
$(CLANG) -Wall -Wextra $(CFLAGS) -c -emit-llvm $<

$(TIMESTAMP): prelude.ll $(LLIR_TEST_GEN_JAR)
mkdir -p $(OUTPUT_DIR)
touch $@
$(LLIRTESTGEN_CMD) $(OUTPUT_DIR)

$(GENERATED): $(TIMESTAMP)
@echo -n ""

.PHONY:
clean:
$(RM) prelude.bc prelude.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2019, 2019, Oracle and/or its affiliates.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <string.h>
#include <stdio.h>

#define FMT "%016lx %016lx %016lx %016lx: %s\n"

void run(const char *, const char *, char *);

void print_output(void *_output, const char *test) {
long *output = _output;

printf(FMT, output[0], output[1], output[2], output[3], test);
memset(output, 0, 32);
}

void print_input(void *_input) {
long *input = _input;

printf("\n===========================\n");
printf(FMT, input[0], input[1], input[2], input[3], "input/lhs");
printf(FMT, input[4], input[5], input[6], input[7], "rhs");
printf("\n");
}

void fill(void *_input, void *_output, long start, long increment) {
long *input = _input;
long *output = _output;

int i;

for (i = 0; i < (256 * 2 / 64); i++) {
input[i] = start + (increment * i);
}

for (; i < ((256 + 128) * 2 / 64); i++) {
output[i - (256 * 2 / 64)] = start + (increment * i);
}
}

int main(void) {
char _input[256 / 8 * 2] = {0};
char _output[256 / 8] = {0};

void *input = _input;
void *output = _output;

print_input(input);
run(input, input + 32, output);

fill(input, output, 0xffffffffffffffffl, 0);
print_input(input);
run(input, input + 32, output);

fill(input, output, 0xf0f0f0f0f0f0f0f0l, 0);
print_input(input);
run(input, input + 32, output);

fill(input, output, 0x0101010101010101l, 0x9456010101010101l);
print_input(input);
run(input, input + 32, output);

fill(input, output, 0xffffffffffffffffl, -0x0101010101010101l);
print_input(input);
run(input, input + 32, output);

fill(input, output, 0, 0x0101010101010101l);
print_input(input);
run(input, input + 32, output);

return 0;
}
Loading

0 comments on commit e98e854

Please sign in to comment.