WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit dc957fb5 authored by Isaac Oscar Gariano's avatar Isaac Oscar Gariano
Browse files

Added tagref64 tests and update ci script

parent 62635f6d
......@@ -30,12 +30,6 @@ stages:
- build
- test
build_vm:
stage: build
script:
- rustc --version
- time CARGO_HOME=.cargo RUST_BACKTRACE=1 CC=clang cargo build --release
build_test:
stage: build
script:
......@@ -56,22 +50,22 @@ before_script:
test:cargo:api:
stage: test
script:
- RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --release test_api 2> /dev/null
- RUST_BACKTRACE=1 RUST_TEST_THREADS=1 ./test-release --release test_api 2> /dev/null
test:cargo:ir:
stage: test
script:
- RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --release test_ir 2> /dev/null
- RUST_BACKTRACE=1 RUST_TEST_THREADS=1 ./test-release --release test_ir 2> /dev/null
test:cargo:compiler:
stage: test
script:
- RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --release test_compiler 2> /dev/null
- RUST_BACKTRACE=1 RUST_TEST_THREADS=1 ./test-release --release test_compiler 2> /dev/null
test:cargo:runtime:
stage: test
script:
- RUST_BACKTRACE=1 RUST_TEST_THREADS=1 cargo test --release test_runtime 2> /dev/null
- RUST_BACKTRACE=1 RUST_TEST_THREADS=1 ./test-release test_runtime 2> /dev/null
testjit:milestones:
stage: test
......@@ -136,10 +130,5 @@ testjit:som:
- if [ -d "tests/test_jit/RPySOM" ]; then rm -Rf tests/test_jit/RPySOM; fi
- git clone https://github.com/microvm/RPySOM.git tests/test_jit/RPySOM
- cd tests/test_jit/RPySOM; git submodule init; git submodule update; cd $CI_PROJECT_DIR
- if [ -d "tests/test_jit/mu-client-pypy" ]; then rm -Rf tests/test_jit/mu-client-pypy; fi
- git clone https://gitlab.anu.edu.au/mu/mu-client-pypy.git tests/test_jit/mu-client-pypy
- cd tests/test_jit/mu-client-pypy
- git checkout mu-rewrite
- git apply pypy.patch
- cd $CI_PROJECT_DIR/tests/test_jit
- MU_LOG_LEVEL=info LD_LIBRARY_PATH=. RUST_BACKTRACE=1 PYTHONPATH=mu-client-pypy:RPySOM/src RPYSOM=RPySOM pytest test_som.py -v
\ No newline at end of file
......@@ -1239,23 +1239,23 @@ impl <'a> InstructionSelection {
let tmp_res = self.get_result_value(node, 0);
let tmp_op = self.emit_ireg(op, f_content, f_context, vm);
let tmp1 = cast_value(&tmp_res, &UINT64_TYPE);
let tmp_res_r64 = cast_value(&tmp_res, &UINT64_TYPE);
let tmp1 = make_temporary(f_context, UINT64_TYPE.clone(), vm);
let tmp2 = make_temporary(f_context, UINT64_TYPE.clone(), vm);
let tmp3 = make_temporary(f_context, UINT64_TYPE.clone(), vm);
//res = (op & 0x7ff0000000000003 != 0x7ff0000000000002) & ((!op & 0x7ff0000000000001) != 0)
emit_mov_u64(self.backend.as_mut(), &tmp1, 0x7ff0000000000001);
self.backend.emit_add_imm(&tmp2, &tmp1, 2, false);
self.backend.emit_add_imm(&tmp3, &tmp1, 1, false);
self.backend.emit_and(&tmp2, &tmp_op, &tmp2);
self.backend.emit_cmp(&tmp2, &tmp3);
self.backend.emit_cset(&tmp2, "NE");
emit_mov_u64(self.backend.as_mut(), &tmp_res_r64, 0x7ff0000000000001);
self.backend.emit_add_imm(&tmp1, &tmp_res_r64, 2, false);
self.backend.emit_add_imm(&tmp2, &tmp_res_r64, 1, false);
self.backend.emit_and(&tmp1, &tmp_op, &tmp1);
self.backend.emit_bics(&XZR, &tmp1, &tmp_op);
self.backend.emit_cmp(&tmp1, &tmp2);
self.backend.emit_cset(&tmp1, "NE");
self.backend.emit_and(&tmp_res, &tmp2, &tmp1);
self.backend.emit_bics(&XZR, &tmp_res_r64, &tmp_op);
self.backend.emit_cset(&tmp_res_r64, "NE");
self.backend.emit_and(&tmp_res_r64, &tmp1, &tmp_res_r64);
},
Instruction_::CommonInst_Tr64FromFp(index) => {
......@@ -1276,16 +1276,17 @@ impl <'a> InstructionSelection {
});
} else {
let tmp_op = self.emit_fpreg(op, f_content, f_context, vm);
let tmp1 = make_temporary(f_context, UINT64_TYPE.clone(), vm);
// isNaN(op) ? (op & 0xfff8000000000000) | 0x0000000000000008 : op
self.backend.emit_fmov(&tmp_res, &tmp_op);
self.backend.emit_and_imm(&tmp_res, &tmp_res, 0xfff8000000000000);
self.backend.emit_orr_imm(&tmp_res, &tmp_res, 0x0000000000000008);
self.backend.emit_and_imm(&tmp1, &tmp_res, 0xfff8000000000000);
self.backend.emit_orr_imm(&tmp1, &tmp1, 0x0000000000000008);
// Sets V flag if tmp_op is unordered with tmp_op (i.e. it is a NaN)
self.backend.emit_fcmp(&tmp_op, &tmp_op);
// sets tmp_res to tmp2 if V is set
self.backend.emit_csel(&tmp_res, &tmp_res, &tmp_res, "VS");
// sets tmp_res to tmp1 if V is set
self.backend.emit_csel(&tmp_res, &tmp1, &tmp_res, "VS");
}
},
//(0x7ff0000000000001u64 | ((opnd & 0x7ffffffffffffu64) << 1) | ((opnd & 0x8000000000000u64) << 12))
......@@ -1296,13 +1297,15 @@ impl <'a> InstructionSelection {
if match_node_int_imm(op) {
let int_val: u64 = node_imm_to_u64(op);
emit_mov_u64(self.backend.as_mut(), &tmp_res,
0x7FF0000000000001 | (((int_val & 0x8000000000000000) << 12) | (int_val & 0x7ffffffffffffu64) << 1));
0x7FF0000000000001 | (((int_val & 0x8000000000000) << 12) |
(int_val & 0x7ffffffffffffu64) << 1));
} else {
let tmp_op = self.emit_fpreg(op, f_content, f_context, vm);
let tmp = make_temporary(f_context, UINT64_TYPE.clone(), vm);
// res = 0x7FF0000000000001 | (((op & 0x8000000000000000) << 12) | (opnd & 0x7ffffffffffffu64) << 1)
// res = 0x7FF0000000000001 | (((op & 0x8000000000000000) << 12)
// | (opnd & 0x7ffffffffffffu64) << 1)
self.backend.emit_and_imm(&tmp_res, &tmp_res, 0x8000000000000);
self.backend.emit_lsl_imm(&tmp_res, &tmp_op, 12);
......@@ -1317,8 +1320,6 @@ impl <'a> InstructionSelection {
let ref op1 = ops[index1];
let ref op2 = ops[index2];
let tmp_res = self.get_result_value(node, 0);
if match_node_ref_imm(op1) && match_node_int_imm(op2) {
let tag: u64 = node_imm_to_u64(op2);
emit_mov_u64(self.backend.as_mut(), &tmp_res,
......@@ -1360,7 +1361,7 @@ impl <'a> InstructionSelection {
}
self.backend.emit_orr(&tmp_res, &tmp, &tmp_res);
emit_mov_u64(self.backend.as_mut(), &tmp, 0xFF0000000000002);
emit_mov_u64(self.backend.as_mut(), &tmp, 0x7ff0000000000002);
self.backend.emit_orr(&tmp_res, &tmp_res, &tmp);
}
},
......
......@@ -1388,8 +1388,8 @@ impl <'a> VM {
let opnd = value.v.as_tr64();
self.new_handle(APIHandle {
id: handle_id,
v : APIHandleValue::Int(
(((opnd & 0xffffffffffffeu64) >> 1) | ((opnd & 0x8000000000000000u64) >> 12)),
v : APIHandleValue::Int(((opnd & 0xffffffffffffeu64) >> 1) |
((opnd & 0x8000000000000000u64) >> 12),
52
)
})
......@@ -1402,10 +1402,9 @@ impl <'a> VM {
self.new_handle(APIHandle {
id: handle_id,
v : APIHandleValue::Ref(types::REF_VOID_TYPE.clone(),
unsafe { Address::from_usize(
((opnd & 0x7ffffffffff8u64) |
u64_asr((opnd & 0x8000000000000000u64), 16)) as usize
) })
unsafe { Address::from_usize(((opnd & 0x7ffffffffff8u64) |
u64_asr((opnd & 0x8000000000000000u64), 16)) as usize)
})
})
}
......@@ -1415,8 +1414,8 @@ impl <'a> VM {
let opnd = value.v.as_tr64();
self.new_handle(APIHandle {
id: handle_id,
v : APIHandleValue::Int(
(u64_asr((opnd & 0x000f800000000000u64), 46) | (u64_asr((opnd & 0x4), 2))),
v : APIHandleValue::Int(u64_asr((opnd & 0x000f800000000000u64), 46) |
(u64_asr((opnd & 0x4), 2)),
6
)
})
......@@ -1445,10 +1444,8 @@ impl <'a> VM {
let opnd = value.v.as_int();
self.new_handle(APIHandle {
id: handle_id,
v : APIHandleValue::TagRef64(
(0x7ff0000000000001u64 | ((opnd & 0x7ffffffffffffu64) << 1) |
((opnd & 0x8000000000000u64) << 12))
)
v : APIHandleValue::TagRef64(0x7ff0000000000001u64 | ((opnd & 0x7ffffffffffffu64) << 1)
| ((opnd & 0x8000000000000u64) << 12))
})
}
......@@ -1460,9 +1457,8 @@ impl <'a> VM {
let tag_ = tag.v.as_int();
self.new_handle (APIHandle {
id: handle_id,
v : APIHandleValue::TagRef64(
(0x7ff0000000000002u64 | (addr_ & 0x7ffffffffff8u64) | ((addr_ & 0x800000000000u64) << 16)
| ((tag_ & 0x3eu64) << 46) | ((tag_ & 0x1) << 2))
v : APIHandleValue::TagRef64(0x7ff0000000000002u64 | (addr_ & 0x7ffffffffff8u64) |
((addr_ & 0x800000000000u64) << 16) | ((tag_ & 0x3eu64) << 46) | ((tag_ & 0x1) << 2)
)
})
}
......
......@@ -12,24 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from util import execute_bundle, load_bundle, get_function;
from util import execute, compile_bundle, load_bundle, get_function;
import pytest;
import ctypes;
def test_argc():
assert(execute_bundle(
compile_bundle(
"""
.funcdef test_argc <main_sig>
{
entry(<int<32>>argc <uptr<uptr<char>>>argv):
RET argc
}
""",
"test_argc", ["2", "3", "4"]) == 4);
""", "test_argc");
assert(execute("test_argc", ["2", "3", "4"]) == 4);
@pytest.mark.xfail(reason = "1 bit division is not implemented on x86-64")
def test_int1():
assert(execute_bundle(
compile_bundle(
"""
.funcdef test_int <main_sig>
{
......@@ -41,7 +41,8 @@ def test_int1():
RET res
}
""",
"test_int") == 1);
"test_int")
assert(execute("test_int") == 1);
def test_add():
......@@ -54,13 +55,13 @@ def test_add():
RET res
}
""",
"test_add.so");
"test_add");
test_add = get_function(lib.test_add, [ctypes.c_int64, ctypes.c_int64], ctypes.c_int64);
assert(test_add(1, 2) == 3);
assert(test_add(-40, 60) == 20);
def test_except_stack_args():
assert(execute_bundle(
compile_bundle(
"""
.funcsig stack_sig = (int<64> int<64> int<64> int<64> int<64> int<64> int<64>)->()
.funcdef stack_args <stack_sig>
......@@ -78,4 +79,5 @@ def test_except_stack_args():
RET status
}
""",
"test_except_stack_args") == 1);
"test_except_stack_args");
assert(execute("test_except_stack_args") == 1);
from util import execute, compile_bundle, load_bundle, get_function;
import pytest;
import ctypes, struct, math;
def transmute_float_to_int(f): # type: (float)->int
return int(struct.unpack('P', struct.pack('d', float(f)))[0]);
def transmute_int_to_float(i): # type: (int)->float
return float(struct.unpack('d', struct.pack('P', int(i)))[0]);
def test_is_int():
lib = load_bundle("""
.funcdef tr64_is_int <(tagref64)->(int<1>)>
{
entry(<tagref64> tr):
res = COMMINST uvm.tr64.is_int (tr)
RET res
}
""", "tr64_is_int"); # type: ctypes.CDLL
tr64_is_int = get_function(lib.tr64_is_int, [ctypes.c_uint64], ctypes.c_bool);
assert(tr64_is_int(0x7ff0000000000001));
assert(tr64_is_int(0xfff0000000000001));
assert(tr64_is_int(0xffffffffffffffff));
def test_is_ref():
lib = load_bundle("""
.funcdef tr64_is_ref <(tagref64)->(int<1>)>
{
entry(<tagref64> tr):
res = COMMINST uvm.tr64.is_ref (tr)
RET res
}
""", "tr64_is_ref"); # type: ctypes.CDLL
tr64_is_ref = get_function(lib.tr64_is_ref, [ctypes.c_uint64], ctypes.c_bool);
assert(tr64_is_ref(0x7ff0000000000002));
assert(tr64_is_ref(0xfff0000000000002));
assert(tr64_is_ref(0xfffffffffffffffe));
def test_is_fp():
lib = load_bundle("""
.funcdef tr64_is_fp <(tagref64)->(int<1>)>
{
entry(<tagref64> tr):
res = COMMINST uvm.tr64.is_fp(tr)
RET res
}
""", "tr64_is_fp"); # type: ctypes.CDLL
tr64_is_fp = get_function(lib.tr64_is_fp, [ctypes.c_uint64], ctypes.c_bool);
assert(tr64_is_fp(0x0));
assert(tr64_is_fp(0x123456789abcdef0));
assert(tr64_is_fp(0x7ff123456789abcc));
assert(tr64_is_fp(0xfffffffffffffffc));
assert(tr64_is_fp(transmute_float_to_int(3.1415927)));
def test_from_int():
lib = load_bundle("""
.funcdef tr64_from_int <(int<52>)->(tagref64)>
{
entry(<int<52>> val):
res = COMMINST uvm.tr64.from_int(val)
RET res
}
""", "tr64_from_int"); # type: ctypes.CDLL
tr64_from_int = get_function(lib.tr64_from_int, [ctypes.c_uint64], ctypes.c_uint64);
assert(tr64_from_int(0x0000000000000) == 0x7ff0000000000001);
assert(tr64_from_int(0xfffffffffffff) == 0xffffffffffffffff);
assert(tr64_from_int(0x5555555555555) == 0x7ffaaaaaaaaaaaab);
assert(tr64_from_int(0xaaaaaaaaaaaaa) == 0xfff5555555555555);
def test_from_fp():
lib = load_bundle("""
.funcdef tr64_from_fp <(double)->(tagref64)>
{
entry(<double> val):
res = COMMINST uvm.tr64.from_fp(val)
RET res
}
""", "tr64_from_fp"); # type: ctypes.CDLL
tr64_from_fp = get_function(lib.tr64_from_fp, [ctypes.c_double], ctypes.c_uint64);
assert(tr64_from_fp(3.14) == transmute_float_to_int(3.14));
assert(tr64_from_fp(-3.14) == transmute_float_to_int(-3.14));
assert(tr64_from_fp(float("inf")) == 0x7ff0000000000000);
assert(tr64_from_fp(transmute_int_to_float(0x7ff123456789abcd)) == 0x7ff0000000000008);
assert(math.isnan(transmute_int_to_float(tr64_from_fp(transmute_int_to_float(0x7ff123456789abcd)))));
def test_from_ref():
lib = load_bundle("""
.funcdef tr64_from_ref <(ref<void> int<6>)->(tagref64)>
{
entry(<ref<void>>%ref <int<6>> tag):
res = COMMINST uvm.tr64.from_ref(%ref tag)
RET res
}
""", "tr64_from_ref"); # type: ctypes.CDLL
tr64_from_ref = get_function(lib.tr64_from_ref, [ctypes.c_void_p, ctypes.c_uint8], ctypes.c_uint64);
assert(tr64_from_ref(0x000000000000, 0x00) == 0x7ff0000000000002);
assert(tr64_from_ref(0x7ffffffffff8, 0x00) == 0x7ff07ffffffffffa);
assert(tr64_from_ref(0xfffffffffffffff8, 0x00) == 0xfff07ffffffffffa);
assert(tr64_from_ref(0x000000000000, 0x3f) == 0x7fff800000000006);
def test_to_int():
lib = load_bundle("""
.funcdef tr64_to_int <(tagref64)->(int<52>)>
{
entry(<tagref64> tr):
res = COMMINST uvm.tr64.to_int(tr)
RET res
}
""", "tr64_to_int"); # type: ctypes.CDLL
tr64_to_int = get_function(lib.tr64_to_int, [ctypes.c_uint64], ctypes.c_uint64);
assert(tr64_to_int(0x7ff0000000000001) == 0);
assert(tr64_to_int(0xfff0000000000001) == 0x8000000000000);
assert(tr64_to_int(0xfff5555555555555) == 0xaaaaaaaaaaaaa);
assert(tr64_to_int(0x7ffaaaaaaaaaaaab) == 0x5555555555555);
def test_to_fp():
lib = load_bundle("""
.funcdef tr64_to_fp <(tagref64)->(double)>
{
entry(<tagref64> tr):
res = COMMINST uvm.tr64.to_fp(tr)
RET res
}
""", "tr64_to_fp"); # type: ctypes.CDLL
tr64_to_fp = get_function(lib.tr64_to_fp, [ctypes.c_uint64], ctypes.c_double);
assert(tr64_to_fp(0x0000000000000000) == 0.0);
assert(tr64_to_fp(0x8000000000000000) == -0.0);
assert(tr64_to_fp(0x3ff0000000000000) == 1.0);
assert(math.isnan(tr64_to_fp(0x7ff0000000000008)));
def test_to_ref():
lib = load_bundle("""
.funcdef tr64_to_ref <(tagref64)->(ref<void>)>
{
entry(<tagref64> tr):
res = COMMINST uvm.tr64.to_ref(tr)
RET res
}
""", "tr64_to_ref"); # type: ctypes.CDLL
tr64_to_ref = get_function(lib.tr64_to_ref, [ctypes.c_uint64], ctypes.c_void_p);
assert(tr64_to_ref(0x7ff0555555555552) == 0x555555555550);
assert(tr64_to_ref(0xfff02aaaaaaaaaaa) == 0xffffaaaaaaaaaaa8);
def test_to_tag():
lib = load_bundle("""
.funcdef tr64_to_tag <(tagref64)->(int<6>)>
{
entry(<tagref64> tr):
res = COMMINST uvm.tr64.to_tag(tr)
RET res
}
""", "tr64_to_tag"); # type: ctypes.CDLL
tr64_to_tag = get_function(lib.tr64_to_tag, [ctypes.c_uint64], ctypes.c_uint8);
assert(tr64_to_tag(0x7ff0555555555552) == 0);
assert(tr64_to_tag(0x7fff800000000006) == 0x3f);
assert(tr64_to_tag(0x7ffa800000000002) == 0x2a);
assert(tr64_to_tag(0x7ff5000000000006) == 0x15);
def test_from_int_imm():
bundle_template = """
.funcdef tr64_from_int <()->(tagref64)>
{{
entry():
res = COMMINST uvm.tr64.from_int(<int<52>>{})
RET res
}}
"""; # type: str
def tr64_from_int(val): # type: (str) -> int
lib = load_bundle(bundle_template.format(val), "tr64_from_int_{}".format(val));
return get_function(lib.tr64_from_int, [], ctypes.c_uint64)();
assert(tr64_from_int("0x0000000000000") == 0x7ff0000000000001);
assert(tr64_from_int("0xfffffffffffff") == 0xffffffffffffffff);
assert(tr64_from_int("0x5555555555555") == 0x7ffaaaaaaaaaaaab);
assert(tr64_from_int("0xaaaaaaaaaaaaa") == 0xfff5555555555555);
def test_from_fp_imm():
bundle_template = """
.funcdef tr64_from_fp <()->(tagref64)>
{{
entry():
res = COMMINST uvm.tr64.from_fp(<double>{})
RET res
}}
"""; # type: str
def tr64_from_fp(val): # type: (str) -> int
lib = load_bundle(bundle_template.format(val), "tr64_from_fp_{}".format(val));
return get_function(lib.tr64_from_fp, [], ctypes.c_uint64)();
assert(tr64_from_fp("3.14 d") == transmute_float_to_int(3.14));
assert(tr64_from_fp("-3.14 d") == transmute_float_to_int(-3.14));
assert(tr64_from_fp("+inf d") == 0x7ff0000000000000);
assert(tr64_from_fp("bitsd(0x7ff123456789abcd)") == 0x7ff0000000000008);
assert(math.isnan(transmute_int_to_float(tr64_from_fp("bitsd(0x7ff123456789abcd)"))));
def test_from_ref_imm():
lib = load_bundle("""
.funcdef tr64_from_tag <(int<6>)->(tagref64)>
{
entry(<int<6>> tag):
res = COMMINST uvm.tr64.from_ref(<ref<void>>NULL tag)
RET res
}""", "tr64_from_tag"); # type: ctypes.CDLL
tr64_from_tag = get_function(lib.tr64_from_tag, [ctypes.c_uint8], ctypes.c_uint64);
assert(tr64_from_tag(0x00) == 0x7ff0000000000002);
assert(tr64_from_tag(0x3f) == 0x7fff800000000006);
def test_from_tag_imm():
bundle_template = """
.funcdef tr64_from_ref <(ref<void>)->(tagref64)>
{{
entry(<ref<void>>%ref):
res = COMMINST uvm.tr64.from_ref(%ref <int<6>>{})
RET res
}}
"""; # type: str
def tr64_from_ref(ref, val): # type: (int, str) -> int
lib = load_bundle(bundle_template.format(val), "tr64_from_ref_{}".format(val));
return get_function(lib.tr64_from_ref, [ctypes.c_void_p], ctypes.c_uint64)(ref);
assert(tr64_from_ref(0x000000000000, "0x00") == 0x7ff0000000000002);
assert(tr64_from_ref(0x7ffffffffff8, "0x00") == 0x7ff07ffffffffffa);
assert(tr64_from_ref(0xfffffffffffffff8, "0x00") == 0xfff07ffffffffffa);
assert(tr64_from_ref(0x000000000000, "0x3f") == 0x7fff800000000006);
def test_from_tag_ref_imm():
bundle_template = """
.funcdef tr64_from_tag_ref <()->(tagref64)>
{{
entry():
res = COMMINST uvm.tr64.from_ref(<ref<void>>NULL <int<6>>{})
RET res
}}
"""; # type: str
def tr64_from_tag_ref(val): # type: (str) -> int
lib = load_bundle(bundle_template.format(val), "tr64_from_tag_ref_{}".format(val));
return get_function(lib.tr64_from_tag_ref, [], ctypes.c_uint64)();
assert(tr64_from_tag_ref("0x00") == 0x7ff0000000000002);
assert(tr64_from_tag_ref("0x3f") == 0x7fff800000000006);
\ No newline at end of file
......@@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os, subprocess, ctypes;
import os, subprocess, ctypes, sys;
import struct;
muc = os.environ.get('MUC', 'muc'); #type: str
emit = os.environ.get('MU_EMIT_DIR', 'emit'); #type: str
libext = '.dylib' if sys.platform.startswith('darwin') else \
'.so' if sys.platform.startswith('linux') else sys.exit("Unsupported platform");
prelude = """
.funcsig exit_sig = (int<32>) -> ()
......@@ -41,6 +43,7 @@ def get_output_file(name): # type: (str) -> str
return os.path.join(emit, name);
def execute_muc(bundle, name, primordial=None): # type: (str, str, Optional[str]) -> None
sys.stderr.write(bundle);
muc_proc = subprocess.Popen([muc, "-r"]
+ (["-f", primordial] if primordial is not None else [])
+ ["/dev/stdin", get_output_file(name)],
......@@ -48,13 +51,15 @@ def execute_muc(bundle, name, primordial=None): # type: (str, str, Optional[str]
muc_proc.communicate(bundle); # Send the bundle to muc
assert (muc_proc.returncode == 0); # Check that muc worked
def execute_bundle(bundle, name, args = [], main = None): # type: (str, str, Optional[List[str]], Optional[str]) -> int
def compile_bundle(bundle, name, main = None): # type: (str, str, Optional[str]) -> None
execute_muc(prelude + bundle + make_primordial(main if main is not None else name), name, "primordial");
def execute(name, args = []): # type: (str, Optional[List[str]]) -> int
return subprocess.call([get_output_file(name)] + args);
def load_bundle(bundle, name): # type: (str, str) -> ctypes.CDLL
execute_muc(prelude + bundle, name);
return ctypes.CDLL(get_output_file(name));
execute_muc(prelude + bundle, name + libext);
return ctypes.CDLL(get_output_file(name + libext));
def get_function(func, argtypes, restype): # type: (ctypes._FuncPtr) -> (ctypes._FuncPtr)
func.argtypes = argtypes;
......
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