File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,35 @@ impl Serialize for SymbolTable {
59
59
}
60
60
}
61
61
62
+ // A direct serialization for the goto SymbolTable (contrasting to the irep SymbolTable just above).
63
+ // This permits a "streaming optimization" where we reduce memory usage considerably by
64
+ // only holding the irep conversion of one symbol in memory at a time.
65
+ impl Serialize for crate :: goto_program:: SymbolTable {
66
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
67
+ where
68
+ S : Serializer ,
69
+ {
70
+ let mut obj = serializer. serialize_map ( None ) ?;
71
+ obj. serialize_entry ( "symbolTable" , & StreamingSymbols ( & self ) ) ?;
72
+ obj. end ( )
73
+ }
74
+ }
75
+ struct StreamingSymbols < ' a > ( & ' a crate :: goto_program:: SymbolTable ) ;
76
+ impl < ' a > Serialize for StreamingSymbols < ' a > {
77
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
78
+ where
79
+ S : Serializer ,
80
+ {
81
+ let mm = self . 0 . machine_model ( ) ;
82
+ let mut obj = serializer. serialize_map ( None ) ?;
83
+ for ( k, v) in self . 0 . iter ( ) {
84
+ // We're only storing the to_irep in RAM for one symbol at a time
85
+ obj. serialize_entry ( k, & v. to_irep ( mm) ) ?;
86
+ }
87
+ obj. end ( )
88
+ }
89
+ }
90
+
62
91
impl Serialize for Symbol {
63
92
fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
64
93
where
Original file line number Diff line number Diff line change @@ -157,7 +157,7 @@ impl CodegenBackend for GotocCodegenBackend {
157
157
if !sess. opts . debugging_opts . no_codegen && sess. opts . output_types . should_codegen ( ) {
158
158
// "path.o"
159
159
let base_filename = outputs. path ( OutputType :: Object ) ;
160
- write_file ( & base_filename, "symtab.json" , & result. symtab . to_irep ( ) ) ;
160
+ write_file ( & base_filename, "symtab.json" , & result. symtab ) ;
161
161
write_file ( & base_filename, "type_map.json" , & result. type_map ) ;
162
162
}
163
163
You can’t perform that action at this time.
0 commit comments