From e3db942b0cec38e4cf5af7d6ca6ce33d7f79d666 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 26 Dec 2018 11:35:55 +0100 Subject: [PATCH] Put default implementations of FuncWriter methods in a seperate method This is useful when you want to write extra information --- lib/codegen/src/write.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/codegen/src/write.rs b/lib/codegen/src/write.rs index 4a70574caa..6629f0f3be 100644 --- a/lib/codegen/src/write.rs +++ b/lib/codegen/src/write.rs @@ -41,6 +41,16 @@ pub trait FuncWriter { w: &mut Write, func: &Function, regs: Option<&RegInfo>, + ) -> Result { + self.super_preamble(w, func, regs) + } + + /// Default impl of `write_preamble` + fn super_preamble( + &mut self, + w: &mut Write, + func: &Function, + regs: Option<&RegInfo>, ) -> Result { let mut any = false; @@ -91,13 +101,24 @@ pub trait FuncWriter { } /// Write an entity definition defined in the preamble to `w`. - #[allow(unused_variables)] fn write_entity_definition( &mut self, w: &mut Write, func: &Function, entity: AnyEntity, value: &fmt::Display, + ) -> fmt::Result { + self.super_entity_definition(w, func, entity, value) + } + + /// Default impl of `write_entity_definition` + #[allow(unused_variables)] + fn super_entity_definition( + &mut self, + w: &mut Write, + func: &Function, + entity: AnyEntity, + value: &fmt::Display, ) -> fmt::Result { writeln!(w, " {} = {}", entity, value) }