fixing formatter not reporting errors

This commit is contained in:
Jakub Doka 2024-11-07 17:02:22 +01:00
parent 513d2c7127
commit 0374848b28
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
6 changed files with 1420 additions and 23 deletions

1347
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,10 +8,10 @@ members = [
"xrt",
"xtask",
"lang",
#"depell",
#"depell/wasm-fmt",
#"depell/wasm-hbc",
#"depell/wasm-rt",
"depell",
"depell/wasm-fmt",
"depell/wasm-hbc",
"depell/wasm-rt",
]
[workspace.dependencies]

View file

@ -630,17 +630,23 @@ Structure := struct {}
BigStructure := struct {a: uint, b: uint}
MidStructure := struct {a: u8}
returner_fn := fn(): ?Structure {
return .()
}
returner_bn := fn(): ?BigStructure {
return .(0, 0)
}
returner_cn := fn(): ?MidStructure {
return .(0)
}
main := fn(): int {
ret := returner_fn()
if ret != null {
bet := returner_bn()
cet := returner_cn()
if ret != null & bet != null & cet != null {
return 1
}

View file

@ -81,10 +81,20 @@ pub fn run_compiler(root_file: &str, options: Options, out: &mut Vec<u8>) -> std
}
if options.fmt {
if !parsed.errors.is_empty() {
*out = parsed.errors.into_bytes();
return Err(std::io::Error::other("parsing fialed"));
}
for parsed in parsed.ast {
format_ast(parsed)?;
}
} else if options.fmt_stdout {
if !parsed.errors.is_empty() {
*out = parsed.errors.into_bytes();
return Err(std::io::Error::other("parsing fialed"));
}
let ast = parsed.ast.into_iter().next().unwrap();
write!(out, "{ast}").unwrap();
} else {

View file

@ -792,10 +792,8 @@ impl<'a> Env<'a> {
dom = self.ctx.nodes.idom(dom);
dom = self.ctx.idom_of(dom);
}
std::println!("{inst} {:?}", self.ctx.nodes[inst].key());
self.ctx.uses_of(inst, use_buf);
for uinst in use_buf.drain(..) {
std::println!("| {uinst} {:?}", self.ctx.nodes[uinst].key());
let cursor = self.ctx.use_block(inst, uinst);
self.reverse_cfg_dfs(cursor, dom, |_, n, b| {
let mut range = b.range.clone();
@ -808,7 +806,6 @@ impl<'a> Env<'a> {
.map_or(Nid::MAX, |n| n + 1) as usize,
);
std::println!("|- {range:?} {:?}", self.ctx.nodes[n].key());
bundle.add(range);
});
}
@ -824,7 +821,6 @@ impl<'a> Env<'a> {
self.res.node_to_reg[inst as usize] = self.res.bundles.len() as Reg;
}
}
std::println!("|= {}", self.res.node_to_reg[inst as usize]);
}
fn reverse_cfg_dfs(

View file

@ -1,21 +1,65 @@
main:
ADDI64 r254, r254, -16d
ST r31, r254, 0a, 16h
ADDI64 r254, r254, -122d
ST r31, r254, 26a, 96h
JAL r31, r0, :returner_fn
LI8 r32, 0b
CP r32, r1
ADDI64 r1, r254, 2d
JAL r31, r0, :returner_bn
ADDI64 r33, r254, 0d
JAL r31, r0, :returner_cn
ST r1, r254, 0a, 2h
LI8 r34, 0b
LI8 r35, 0b
LD r36, r254, 2a, 1h
CP r1, r32
ANDI r37, r37, 255d
ANDI r1, r1, 255d
ANDI r32, r32, 255d
JEQ r1, r32, :0
LI64 r1, 1d
CMPU r37, r1, r34
CMPUI r37, r37, 0d
ANDI r38, r38, 255d
ANDI r36, r36, 255d
CMPU r38, r36, r35
CMPUI r38, r38, 0d
LD r39, r254, 0a, 1h
AND r40, r38, r37
ANDI r41, r41, 255d
ANDI r39, r39, 255d
CMPU r41, r39, r35
CMPUI r41, r41, 0d
AND r42, r41, r40
ANDI r42, r42, 255d
JNE r42, r0, :0
LI64 r1, 0d
JMP :1
0: LI64 r1, 0d
1: LD r31, r254, 0a, 16h
ADDI64 r254, r254, 16d
0: LI64 r1, 1d
1: LD r31, r254, 26a, 96h
ADDI64 r254, r254, 122d
JALA r0, r31, 0a
returner_bn:
ADDI64 r254, r254, -24d
LI8 r6, 1b
ADDI64 r5, r254, 0d
ST r6, r254, 0a, 1h
LI64 r6, 0d
ST r6, r254, 8a, 8h
ST r6, r254, 16a, 8h
BMC r5, r1, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
returner_cn:
ADDI64 r254, r254, -2d
LI8 r4, 1b
ADDI64 r3, r254, 0d
ST r4, r254, 0a, 1h
LI8 r4, 0b
ST r4, r254, 1a, 1h
LD r1, r3, 0a, 2h
ADDI64 r254, r254, 2d
JALA r0, r31, 0a
returner_fn:
LD r1, r254, 0a, 0h
ORI r1, r1, 128d
JALA r0, r31, 0a
code size: 164
code size: 546
ret: 1
status: Ok(())