comparison graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java @ 7756:98143feb3879

provide calling convention for assembler tests
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 11 Feb 2013 12:12:59 +0100
parents 52fd6491fca8
children b792a2f3c4da
comparison
equal deleted inserted replaced
7749:52fd6491fca8 7756:98143feb3879
36 36
37 protected final CodeCacheProvider codeCache; 37 protected final CodeCacheProvider codeCache;
38 38
39 public interface CodeGenTest { 39 public interface CodeGenTest {
40 40
41 Buffer generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig); 41 Buffer generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc);
42 } 42 }
43 43
44 public AssemblerTest() { 44 public AssemblerTest() {
45 this.codeCache = Graal.getRequiredCapability(CodeCacheProvider.class); 45 this.codeCache = Graal.getRequiredCapability(CodeCacheProvider.class);
46 } 46 }
49 ResolvedJavaMethod method = codeCache.lookupJavaMethod(m); 49 ResolvedJavaMethod method = codeCache.lookupJavaMethod(m);
50 RegisterConfig registerConfig = codeCache.lookupRegisterConfig(method); 50 RegisterConfig registerConfig = codeCache.lookupRegisterConfig(method);
51 51
52 CompilationResult compResult = new CompilationResult(); 52 CompilationResult compResult = new CompilationResult();
53 53
54 Buffer codeBuffer = test.generateCode(compResult, codeCache.getTarget(), registerConfig); 54 Signature sig = method.getSignature();
55 JavaType retType = sig.getReturnType(null);
56 JavaType[] argTypes = new JavaType[sig.getParameterCount(false)];
57 for (int i = 0; i < argTypes.length; i++) {
58 argTypes[i] = sig.getParameterType(i, null);
59 }
60 CallingConvention cc = registerConfig.getCallingConvention(CallingConvention.Type.JavaCallee, retType, argTypes, codeCache.getTarget(), false);
61
62 Buffer codeBuffer = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc);
55 compResult.setTargetCode(codeBuffer.close(true), codeBuffer.position()); 63 compResult.setTargetCode(codeBuffer.close(true), codeBuffer.position());
56 64
57 return codeCache.addMethod(method, compResult, null); 65 return codeCache.addMethod(method, compResult, null);
58 } 66 }
59 67
60 protected void assertReturn(String methodName, CodeGenTest test, Object expected, Object... args) { 68 protected Object runTest(String methodName, CodeGenTest test, Object... args) {
61 Method method = getMethod(methodName); 69 Method method = getMethod(methodName);
62 InstalledCode code = assembleMethod(method, test); 70 InstalledCode code = assembleMethod(method, test);
71 return code.executeVarargs(args);
72 }
63 73
64 Object actual = code.executeVarargs(args); 74 protected void assertReturn(String methodName, CodeGenTest test, Object expected, Object... args) {
75 Object actual = runTest(methodName, test, args);
65 Assert.assertEquals("unexpected return value: " + actual, actual, expected); 76 Assert.assertEquals("unexpected return value: " + actual, actual, expected);
66 } 77 }
67 } 78 }