@Test public void testAssemble() throws Exception { try (Context context = new Context()) { try (TargetMachine tm = Target.getTarget("thumb").createTargetMachine("thumbv7-unknown-ios")) { Module module = Module.parseIR(context, "define private i32 @foo() {\n ret i32 5\n }\n", "foo.c"); ByteArrayOutputStream out = new ByteArrayOutputStream(); tm.emit(module, out, CodeGenFileType.AssemblyFile); String asm = new String(out.toByteArray(), "utf-8"); out = new ByteArrayOutputStream(); tm.assemble(asm.getBytes(), "foo.s", out); byte[] data = out.toByteArray(); assertTrue(data.length > 0); } } }
public void assemble(byte[] asm, String filename, OutputStream out) { MemoryBufferRef memoryBufferRef = LLVM.CreateMemoryBufferWithMemoryRangeCopy(asm, filename); if (memoryBufferRef == null) { throw new LlvmException("Failed to create memory buffer"); } filename = filename == null ? "" : filename; StringOut errorMessage = new StringOut(); if (LLVM.TargetMachineAssembleToOutputStream(ref, memoryBufferRef, out, false, false, errorMessage) != 0) { String error = errorMessage.getValue() != null ? errorMessage.getValue().trim() : "Unknown error"; throw new LlvmException(error); } }
TargetMachine implements AutoCloseable { public void assemble(byte[] asm, String filename, OutputStream out) { MemoryBufferRef memoryBufferRef = LLVM.CreateMemoryBufferWithMemoryRangeCopy(asm, filename); if (memoryBufferRef == null) { throw new LlvmException("Failed to create memory buffer"); } filename = filename == null ? "" : filename; StringOut errorMessage = new StringOut(); if (LLVM.TargetMachineAssembleToOutputStream(ref, memoryBufferRef, out, false, false, errorMessage) != 0) { String error = errorMessage.getValue() != null ? errorMessage.getValue().trim() : "Unknown error"; throw new LlvmException(error); } } }
TargetMachine implements AutoCloseable { public void assemble(byte[] asm, String filename, OutputStream out) { MemoryBufferRef memoryBufferRef = LLVM.CreateMemoryBufferWithMemoryRangeCopy(asm, filename); if (memoryBufferRef == null) { throw new LlvmException("Failed to create memory buffer"); } filename = filename == null ? "" : filename; StringOut errorMessage = new StringOut(); if (LLVM.TargetMachineAssembleToOutputStream(ref, memoryBufferRef, out, false, false, errorMessage) != 0) { String error = errorMessage.getValue() != null ? errorMessage.getValue().trim() : "Unknown error"; throw new LlvmException(error); } } TargetMachine(TargetMachineRef ref); }
TargetMachine implements AutoCloseable { public void assemble(byte[] asm, String filename, OutputStream out) { MemoryBufferRef memoryBufferRef = LLVM.CreateMemoryBufferWithMemoryRangeCopy(asm, filename); if (memoryBufferRef == null) { throw new LlvmException("Failed to create memory buffer"); } filename = filename == null ? "" : filename; StringOut errorMessage = new StringOut(); if (LLVM.TargetMachineAssembleToOutputStream(ref, memoryBufferRef, out, false, false, errorMessage) != 0) { String error = errorMessage.getValue() != null ? errorMessage.getValue().trim() : "Unknown error"; throw new LlvmException(error); } } TargetMachine(TargetMachineRef ref); synchronized void dispose(); @Override void close(); Target getTarget(); DataLayout getDataLayout(); TargetOptions getOptions(); String getTriple(); String getCPU(); String getFeatureString(); boolean getAsmVerbosityDefault(); void setAsmVerbosityDefault(boolean value); boolean getDataSections(); boolean getFunctionSections(); void setDataSections(boolean value); void setFunctionSections(boolean value); void emit(Module module, OutputStream out, CodeGenFileType fileType); void emit(Module module, File outFile, CodeGenFileType fileType); void assemble(byte[] asm, String filename, OutputStream out); @Override int hashCode(); @Override boolean equals(Object obj); }
TargetMachine implements AutoCloseable { public void assemble(byte[] asm, String filename, OutputStream out) { MemoryBufferRef memoryBufferRef = LLVM.CreateMemoryBufferWithMemoryRangeCopy(asm, filename); if (memoryBufferRef == null) { throw new LlvmException("Failed to create memory buffer"); } filename = filename == null ? "" : filename; StringOut errorMessage = new StringOut(); if (LLVM.TargetMachineAssembleToOutputStream(ref, memoryBufferRef, out, false, false, errorMessage) != 0) { String error = errorMessage.getValue() != null ? errorMessage.getValue().trim() : "Unknown error"; throw new LlvmException(error); } } TargetMachine(TargetMachineRef ref); synchronized void dispose(); @Override void close(); Target getTarget(); DataLayout getDataLayout(); TargetOptions getOptions(); String getTriple(); String getCPU(); String getFeatureString(); boolean getAsmVerbosityDefault(); void setAsmVerbosityDefault(boolean value); boolean getDataSections(); boolean getFunctionSections(); void setDataSections(boolean value); void setFunctionSections(boolean value); void emit(Module module, OutputStream out, CodeGenFileType fileType); void emit(Module module, File outFile, CodeGenFileType fileType); void assemble(byte[] asm, String filename, OutputStream out); @Override int hashCode(); @Override boolean equals(Object obj);  }