Commit 60f30ac4 authored by John Zhang's avatar John Zhang


parent 33326cb4
// 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_30;
MuCtx* ctx_30;
MuIRBuilder* bldr_30;
MuID id_427;
MuID id_428;
MuID id_429;
MuID id_430;
MuID id_431;
MuID id_432;
MuID id_433;
MuID id_434;
MuID id_435;
MuID id_436;
MuID id_437;
MuID id_438;
MuID id_439;
MuID id_440;
MuID id_441;
mu_30 = mu_fastimpl_new();
ctx_30 = mu_30->new_context(mu_30);
bldr_30 = ctx_30->new_ir_builder(ctx_30);
id_427 = bldr_30->gen_sym(bldr_30, "@i8");
bldr_30->new_type_int(bldr_30, id_427, 8);
id_428 = bldr_30->gen_sym(bldr_30, "@i32");
bldr_30->new_type_int(bldr_30, id_428, 32);
id_429 = bldr_30->gen_sym(bldr_30, "@i64");
bldr_30->new_type_int(bldr_30, id_429, 64);
id_430 = bldr_30->gen_sym(bldr_30, "@hyb");
bldr_30->new_type_hybrid(bldr_30, id_430, (MuTypeNode [2]){id_427, id_429}, 2, id_428);
id_431 = bldr_30->gen_sym(bldr_30, "@phyb");
bldr_30->new_type_uptr(bldr_30, id_431, id_430);
id_432 = bldr_30->gen_sym(bldr_30, "@sig_phyb_i32");
bldr_30->new_funcsig(bldr_30, id_432, (MuTypeNode [1]){id_431}, 1, (MuTypeNode [1]){id_428}, 1);
id_433 = bldr_30->gen_sym(bldr_30, "@test_fnc");
bldr_30->new_func(bldr_30, id_433, id_432);
id_434 = bldr_30->gen_sym(bldr_30, "@test_fnc.v1");
id_435 = bldr_30->gen_sym(bldr_30, "@test_fnc.v1.blk0");
id_436 = bldr_30->gen_sym(bldr_30, "");
id_437 = bldr_30->gen_sym(bldr_30, "@test_fnc.v1.blk0.pfld");
id_438 = bldr_30->gen_sym(bldr_30, "@test_fnc.v1.blk0.res");
id_439 = bldr_30->gen_sym(bldr_30, NULL);
bldr_30->new_getvarpartiref(bldr_30, id_439, id_437, true, id_430, id_436);
id_440 = bldr_30->gen_sym(bldr_30, NULL);
bldr_30->new_load(bldr_30, id_440, id_438, true, MU_ORD_NOT_ATOMIC, id_428, id_437, MU_NO_ID);
id_441 = bldr_30->gen_sym(bldr_30, NULL);
bldr_30->new_ret(bldr_30, id_441, (MuVarNode [1]){id_438}, 1);
bldr_30->new_bb(bldr_30, id_435, (MuID [1]){id_436}, (MuTypeNode [1]){id_431}, 1, MU_NO_ID, (MuInstNode [3]){id_439, id_440, id_441}, 3);
bldr_30->new_func_ver(bldr_30, id_434, id_433, (MuBBNode [1]){id_435}, 1);
mu_30->compile_to_sharedlib(mu_30, "test_getvarpartiref.dylib", NULL, 0);
printf("%s\n", "test_getvarpartiref.dylib");
return 0;
// 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_31;
MuCtx* ctx_31;
MuIRBuilder* bldr_31;
MuID id_442;
MuID id_443;
MuID id_444;
MuID id_445;
MuID id_446;
MuID id_447;
MuID id_448;
MuID id_449;
MuID id_450;
MuID id_451;
MuID id_452;
MuID id_453;
MuID id_454;
MuID id_455;
MuID id_456;
mu_31 = mu_fastimpl_new();
ctx_31 = mu_31->new_context(mu_31);
bldr_31 = ctx_31->new_ir_builder(ctx_31);
id_442 = bldr_31->gen_sym(bldr_31, "@i8");
bldr_31->new_type_int(bldr_31, id_442, 8);
id_443 = bldr_31->gen_sym(bldr_31, "@i32");
bldr_31->new_type_int(bldr_31, id_443, 32);
id_444 = bldr_31->gen_sym(bldr_31, "@i64");
bldr_31->new_type_int(bldr_31, id_444, 64);
id_445 = bldr_31->gen_sym(bldr_31, "@hyb");
bldr_31->new_type_hybrid(bldr_31, id_445, NULL, 0, id_443);
id_446 = bldr_31->gen_sym(bldr_31, "@phyb");
bldr_31->new_type_uptr(bldr_31, id_446, id_445);
id_447 = bldr_31->gen_sym(bldr_31, "@sig_phyb_i32");
bldr_31->new_funcsig(bldr_31, id_447, (MuTypeNode [1]){id_446}, 1, (MuTypeNode [1]){id_443}, 1);
id_448 = bldr_31->gen_sym(bldr_31, "@test_fnc");
bldr_31->new_func(bldr_31, id_448, id_447);
id_449 = bldr_31->gen_sym(bldr_31, "@test_fnc.v1");
id_450 = bldr_31->gen_sym(bldr_31, "@test_fnc.v1.blk0");
id_451 = bldr_31->gen_sym(bldr_31, "");
id_452 = bldr_31->gen_sym(bldr_31, "@test_fnc.v1.blk0.pfld");
id_453 = bldr_31->gen_sym(bldr_31, "@test_fnc.v1.blk0.res");
id_454 = bldr_31->gen_sym(bldr_31, NULL);
bldr_31->new_getvarpartiref(bldr_31, id_454, id_452, true, id_445, id_451);
id_455 = bldr_31->gen_sym(bldr_31, NULL);
bldr_31->new_load(bldr_31, id_455, id_453, true, MU_ORD_NOT_ATOMIC, id_443, id_452, MU_NO_ID);
id_456 = bldr_31->gen_sym(bldr_31, NULL);
bldr_31->new_ret(bldr_31, id_456, (MuVarNode [1]){id_453}, 1);
bldr_31->new_bb(bldr_31, id_450, (MuID [1]){id_451}, (MuTypeNode [1]){id_446}, 1, MU_NO_ID, (MuInstNode [3]){id_454, id_455, id_456}, 3);
bldr_31->new_func_ver(bldr_31, id_449, id_448, (MuBBNode [1]){id_450}, 1);
mu_31->compile_to_sharedlib(mu_31, "test_getvarpartiref_nofix.dylib", NULL, 0);
printf("%s\n", "test_getvarpartiref_nofix.dylib");
return 0;
......@@ -29,3 +29,38 @@ def test_getfieldiref():
res = fn(ctypes.byref(stt))
assert res == 0xcafebabe, "result: %s" % hex(res)
def test_getvarpartiref():
class Stt(ctypes.Structure):
_fields_ = [('ui8', ctypes.c_uint8),
('ui64', ctypes.c_uint64),
('ui32s', ctypes.ARRAY(ctypes.c_uint32, 5))]
fn, _ = fncptr_from_c_script("test_getvarpartiref.c", "test_fnc",
stt = Stt()
stt.ui8 = 25
stt.ui64 = 0xabcdef0123456789
stt.ui32s[0] = 0xcafebabe
res = fn(ctypes.byref(stt))
assert res == 0xcafebabe, "result: %s" % hex(res)
def test_getvarpartiref_nofix():
Arr = ctypes.ARRAY(ctypes.c_uint32, 3)
fn, _ = fncptr_from_c_script("test_getvarpartiref_nofix.c", "test_fnc",
arr = Arr()
arr[0] = 0xcafebabe
arr[1] = 0xbecca
arr[2] = 0xfaebee
res = fn(ctypes.byref(arr))
assert res == 0xcafebabe, "result: %s" % hex(res)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment