GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 9938b350 authored by John Zhang's avatar John Zhang

write 'hello world' string works (ccall write)

parent d421c192
// Compile with flag -std=c99
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include "muapi.h"
#include "mu-fastimpl.h"
int main(int argc, char** argv) {
MuVM* mu_22;
MuCtx* ctx_22;
MuIRBuilder* bldr_22;
MuID id_285;
MuID id_286;
MuID id_287;
MuID id_288;
MuID id_289;
MuID id_290;
MuID id_291;
MuID id_292;
MuID id_293;
MuID id_294;
MuID id_295;
MuID id_296;
MuID id_297;
MuID id_298;
MuID id_299;
MuID id_300;
MuID id_301;
mu_22 = mu_fastimpl_new();
ctx_22 = mu_22->new_context(mu_22);
bldr_22 = ctx_22->new_ir_builder(ctx_22);
id_285 = bldr_22->gen_sym(bldr_22, "@i32");
bldr_22->new_type_int(bldr_22, id_285, 32);
id_286 = bldr_22->gen_sym(bldr_22, "@i64");
bldr_22->new_type_int(bldr_22, id_286, 64);
id_287 = bldr_22->gen_sym(bldr_22, "@void");
bldr_22->new_type_void(bldr_22, id_287);
id_288 = bldr_22->gen_sym(bldr_22, "@voidp");
bldr_22->new_type_uptr(bldr_22, id_288, id_287);
id_289 = bldr_22->gen_sym(bldr_22, "@fd_stdout");
bldr_22->new_const_int(bldr_22, id_289, id_285, 1);
id_290 = bldr_22->gen_sym(bldr_22, "@sig_voidpi64_i64");
bldr_22->new_funcsig(bldr_22, id_290, (MuTypeNode [2]){id_288, id_286}, 2, (MuTypeNode [1]){id_286}, 1);
id_291 = bldr_22->gen_sym(bldr_22, "@sig_i32voidpi64_i64");
bldr_22->new_funcsig(bldr_22, id_291, (MuTypeNode [3]){id_285, id_288, id_286}, 3, (MuTypeNode [1]){id_286}, 1);
id_292 = bldr_22->gen_sym(bldr_22, "@fnpsig_i32voidpi64_i64");
bldr_22->new_type_ufuncptr(bldr_22, id_292, id_291);
id_293 = bldr_22->gen_sym(bldr_22, "@c_write");
bldr_22->new_const_extern(bldr_22, id_293, id_292, "write");
id_294 = bldr_22->gen_sym(bldr_22, "@test_write");
bldr_22->new_func(bldr_22, id_294, id_290);
id_295 = bldr_22->gen_sym(bldr_22, "@test_write_v1");
id_296 = bldr_22->gen_sym(bldr_22, "@test_write_v1.blk0");
id_297 = bldr_22->gen_sym(bldr_22, "@test_write_v1.blk0.buf");
id_298 = bldr_22->gen_sym(bldr_22, "");
id_299 = bldr_22->gen_sym(bldr_22, "@test_write_v1.blk0.res");
id_300 = bldr_22->gen_sym(bldr_22, NULL);
bldr_22->new_ccall(bldr_22, id_300, (MuID [1]){id_299}, 1, MU_CC_DEFAULT, id_292, id_291, id_293, (MuVarNode [3]){id_289, id_297, id_298}, 3, MU_NO_ID, MU_NO_ID);
id_301 = bldr_22->gen_sym(bldr_22, NULL);
bldr_22->new_ret(bldr_22, id_301, (MuVarNode [1]){id_299}, 1);
bldr_22->new_bb(bldr_22, id_296, (MuID [2]){id_297, id_298}, (MuTypeNode [2]){id_288, id_286}, 2, MU_NO_ID, (MuInstNode [2]){id_300, id_301}, 2);
bldr_22->new_func_ver(bldr_22, id_295, id_294, (MuBBNode [1]){id_296}, 1);
mu_22->compile_to_sharedlib(mu_22, "test_extern_func.dylib", NULL, 0);
printf("%s\n", "test_extern_func.dylib");
return 0;
from test_milestones import get_fncptr
import ctypes
from test_milestones import get_fncptr, compile_lib
import ctypes, ctypes.util
def test_branch():
......@@ -14,3 +14,9 @@ def test_branch2():
def test_ccall():
fn = get_fncptr("test_ccall", "test_ccall", [ctypes.c_ulonglong])
assert fn(0x7e707560c92d5400) == 0x7e707560c92d5400
def test_extern_func():
# libc = ctypes.CDLL(ctypes.util.find_library('c'), ctypes.RTLD_GLOBAL)
fn = get_fncptr("test_extern_func", "test_write", [ctypes.c_void_p, ctypes.c_size_t], ctypes.c_int64)
buf = ctypes.create_string_buffer('hello world!\n')
assert fn(ctypes.byref(buf), len(buf)) == len(buf)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment