From 1e7a928d6422320c4bc20c0e8c8917614d46863e Mon Sep 17 00:00:00 2001 From: losfair Date: Tue, 14 May 2019 16:13:42 +0800 Subject: [PATCH] Add comments. --- lib/runtime-core/src/backend.rs | 3 +++ lib/runtime-core/src/codegen.rs | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/runtime-core/src/backend.rs b/lib/runtime-core/src/backend.rs index 51d27f964..1d493c314 100644 --- a/lib/runtime-core/src/backend.rs +++ b/lib/runtime-core/src/backend.rs @@ -91,9 +91,12 @@ pub trait RunnableModule: Send + Sync { unsafe fn do_early_trap(&self, data: Box) -> !; + /// Returns the machine code associated with this module. fn get_code(&self) -> Option<&[u8]> { None } + + /// Returns the beginning offsets of all functions, including import trampolines. fn get_offsets(&self) -> Option> { None } diff --git a/lib/runtime-core/src/codegen.rs b/lib/runtime-core/src/codegen.rs index f941fc882..1d9f30f1a 100644 --- a/lib/runtime-core/src/codegen.rs +++ b/lib/runtime-core/src/codegen.rs @@ -42,24 +42,29 @@ impl fmt::Debug for InternalEvent { pub struct BkptInfo {} pub trait ModuleCodeGenerator, RM: RunnableModule, E: Debug> { + /// Creates a new module code generator. fn new() -> Self; + + /// Returns the backend id associated with this MCG. fn backend_id() -> Backend; - fn check_precondition(&mut self, module_info: &ModuleInfo) -> Result<(), E>; - - /// Creates a new function and returns the function-scope code generator for it. - fn next_function(&mut self) -> Result<&mut FCG, E>; - fn finalize(self, module_info: &ModuleInfo) -> Result<(RM, Box), E>; - fn feed_signatures(&mut self, signatures: Map) -> Result<(), E>; - - /// Sets function signatures. - fn feed_function_signatures(&mut self, assoc: Map) -> Result<(), E>; - - /// Adds an import function. - fn feed_import_function(&mut self) -> Result<(), E>; + /// Feeds the compiler config. fn feed_compiler_config(&mut self, _config: &CompilerConfig) -> Result<(), E> { Ok(()) } + /// Adds an import function. + fn feed_import_function(&mut self) -> Result<(), E>; + fn feed_signatures(&mut self, signatures: Map) -> Result<(), E>; + /// Sets function signatures. + fn feed_function_signatures(&mut self, assoc: Map) -> Result<(), E>; + /// Checks the precondition for a module. + fn check_precondition(&mut self, module_info: &ModuleInfo) -> Result<(), E>; + /// Creates a new function and returns the function-scope code generator for it. + fn next_function(&mut self) -> Result<&mut FCG, E>; + /// Finalizes this module. + fn finalize(self, module_info: &ModuleInfo) -> Result<(RM, Box), E>; + + /// Creates a module from cache. unsafe fn from_cache(cache: Artifact, _: Token) -> Result; }