parallel assembly
This commit is contained in:
55
qbe_emit.cm
55
qbe_emit.cm
@@ -127,6 +127,8 @@ var qbe_emit = function(ir, qbe, export_name) {
|
||||
emit(` storel ${sv}, %${t}`)
|
||||
}
|
||||
|
||||
var needs_exc_ret = false
|
||||
|
||||
var refresh_fp = function() {
|
||||
emit(` %fp =l call $cell_rt_refresh_fp_checked(l %ctx)`)
|
||||
var exc = fresh()
|
||||
@@ -134,9 +136,8 @@ var qbe_emit = function(ir, qbe, export_name) {
|
||||
if (has_handler && !in_handler) {
|
||||
emit(` jnz %${exc}, @disruption_handler, @${exc}_ok`)
|
||||
} else {
|
||||
emit(` jnz %${exc}, @${exc}_exc, @${exc}_ok`)
|
||||
emit(`@${exc}_exc`)
|
||||
emit(` ret 15`)
|
||||
needs_exc_ret = true
|
||||
emit(` jnz %${exc}, @_exc_ret, @${exc}_ok`)
|
||||
}
|
||||
emit(`@${exc}_ok`)
|
||||
}
|
||||
@@ -161,9 +162,9 @@ var qbe_emit = function(ir, qbe, export_name) {
|
||||
}
|
||||
i = i + 1
|
||||
|
||||
// Labels are plain strings; skip _nop_ur_ pseudo-labels from streamline
|
||||
// Labels are plain strings; skip nop pseudo-labels from streamline
|
||||
if (is_text(instr)) {
|
||||
if (starts_with(instr, "_nop_ur_")) continue
|
||||
if (starts_with(instr, "_nop_ur_") || starts_with(instr, "_nop_tc_")) continue
|
||||
lbl = sanitize(instr)
|
||||
if (!last_was_term) {
|
||||
emit(` jmp @${lbl}`)
|
||||
@@ -839,9 +840,8 @@ var qbe_emit = function(ir, qbe, export_name) {
|
||||
if (has_handler) {
|
||||
emit(` jnz %${chk}, @disruption_handler, @${chk}_ok`)
|
||||
} else {
|
||||
emit(` jnz %${chk}, @${chk}_exc, @${chk}_ok`)
|
||||
emit(`@${chk}_exc`)
|
||||
emit(` ret 15`)
|
||||
needs_exc_ret = true
|
||||
emit(` jnz %${chk}, @_exc_ret, @${chk}_ok`)
|
||||
}
|
||||
emit(`@${chk}_ok`)
|
||||
refresh_fp()
|
||||
@@ -857,9 +857,8 @@ var qbe_emit = function(ir, qbe, export_name) {
|
||||
if (has_handler) {
|
||||
emit(` jnz %${chk}, @disruption_handler, @${chk}_ok`)
|
||||
} else {
|
||||
emit(` jnz %${chk}, @${chk}_exc, @${chk}_ok`)
|
||||
emit(`@${chk}_exc`)
|
||||
emit(` ret 15`)
|
||||
needs_exc_ret = true
|
||||
emit(` jnz %${chk}, @_exc_ret, @${chk}_ok`)
|
||||
}
|
||||
emit(`@${chk}_ok`)
|
||||
refresh_fp()
|
||||
@@ -886,9 +885,8 @@ var qbe_emit = function(ir, qbe, export_name) {
|
||||
refresh_fp()
|
||||
emit(` ret %${p}`)
|
||||
} else {
|
||||
emit(` jnz %${chk}, @${chk}_exc, @${chk}_ok`)
|
||||
emit(`@${chk}_exc`)
|
||||
emit(` ret 15`)
|
||||
needs_exc_ret = true
|
||||
emit(` jnz %${chk}, @_exc_ret, @${chk}_ok`)
|
||||
emit(`@${chk}_ok`)
|
||||
emit(` ret %${p}`)
|
||||
}
|
||||
@@ -1028,6 +1026,12 @@ var qbe_emit = function(ir, qbe, export_name) {
|
||||
emit(` call $cell_rt_disrupt(l %ctx)`)
|
||||
emit(` ret 15`)
|
||||
|
||||
// Shared exception return (for functions without disruption handler)
|
||||
if (needs_exc_ret) {
|
||||
emit("@_exc_ret")
|
||||
emit(" ret 15")
|
||||
}
|
||||
|
||||
emit("}")
|
||||
emit("")
|
||||
}
|
||||
@@ -1036,30 +1040,23 @@ var qbe_emit = function(ir, qbe, export_name) {
|
||||
// Main: compile all functions then main
|
||||
// ============================================================
|
||||
|
||||
var fn_bodies = []
|
||||
var fi = 0
|
||||
while (fi < length(ir.functions)) {
|
||||
out = []
|
||||
compile_fn(ir.functions[fi], fi, false)
|
||||
fn_bodies[] = text(out, "\n")
|
||||
fi = fi + 1
|
||||
}
|
||||
|
||||
out = []
|
||||
compile_fn(ir.main, -1, true)
|
||||
fn_bodies[] = text(out, "\n")
|
||||
|
||||
// Assemble: data section first, then function bodies
|
||||
var result = []
|
||||
var di = 0
|
||||
while (di < length(data_out)) {
|
||||
push(result, data_out[di])
|
||||
di = di + 1
|
||||
return {
|
||||
data: text(data_out, "\n"),
|
||||
functions: fn_bodies
|
||||
}
|
||||
if (length(data_out) > 0) push(result, "")
|
||||
|
||||
di = 0
|
||||
while (di < length(out)) {
|
||||
push(result, out[di])
|
||||
di = di + 1
|
||||
}
|
||||
|
||||
return text(result, "\n")
|
||||
}
|
||||
|
||||
return qbe_emit
|
||||
|
||||
Reference in New Issue
Block a user