@@ -65,7 +65,7 @@ struct function_entry {
65
65
function_entry (const function_entry& other) = delete ;
66
66
function_entry& operator =(const function_entry& other) = delete ;
67
67
68
- FunctionDecl* decl = nullptr ;
68
+ ir::Function* fun ;
69
69
std::string name;
70
70
};
71
71
@@ -123,7 +123,7 @@ class RttiBuilder
123
123
RttiBuilder (CompileContext& cc, CodeGenerator& cg, SmxNameTable* names);
124
124
125
125
void finish (SmxBuilder& builder);
126
- void add_method (FunctionDecl * fun);
126
+ void add_method (ir::Function * fun);
127
127
void add_native (FunctionDecl* sym);
128
128
129
129
private:
@@ -360,17 +360,19 @@ RttiBuilder::add_debug_var(SmxRttiTable<smx_rtti_debug_var>* table, DebugString&
360
360
var.type_id = type_id;
361
361
}
362
362
363
- void RttiBuilder::add_method (FunctionDecl * fun) {
363
+ void RttiBuilder::add_method (ir::Function * fun) {
364
364
assert (fun->is_live ());
365
365
366
366
uint32_t index = methods_->count ();
367
367
smx_rtti_method& method = methods_->add ();
368
- method.name = names_->add (fun->name ());
369
- method.pcode_start = fun->cg ()->label .offset ();
370
- method.pcode_end = fun->cg ()->pcode_end ;
371
- method.signature = encode_signature (fun->canonical ());
372
-
373
- if (!fun->cg ()->dbgstrs )
368
+ method.name = names_->add (fun->decl ()->name ());
369
+ method.pcode_start = fun->label ().offset ();
370
+ method.pcode_end = fun->pcode_end ();
371
+ method.signature = encode_signature (fun->decl ()->canonical ());
372
+
373
+ (void )index ;
374
+ #if 0
375
+ if (!fun->dbgstrs)
374
376
return;
375
377
376
378
smx_rtti_debug_method debug;
@@ -392,6 +394,7 @@ void RttiBuilder::add_method(FunctionDecl* fun) {
392
394
// Only add a method table entry if we actually had locals.
393
395
if (debug.first_local != dbg_locals_->count())
394
396
dbg_methods_->add(debug);
397
+ #endif
395
398
}
396
399
397
400
void RttiBuilder::add_native (FunctionDecl* fun) {
@@ -721,59 +724,44 @@ Assembler::Assemble(SmxByteBuffer* buffer)
721
724
std::vector<function_entry> functions;
722
725
std::unordered_set<Decl*> symbols;
723
726
724
- // Sort globals.
725
- std::vector<Decl*> global_symbols;
726
- cc_.globals ()->ForEachSymbol ([&](Decl* decl) -> void {
727
- global_symbols.push_back (decl);
727
+ auto mod = cg_.mod ();
728
728
729
- // This is only to assert that we embedded pointers properly in the assembly buffer.
730
- symbols.emplace (decl);
729
+ // Sort globals.
730
+ std::sort (mod->functions ().begin (), mod->functions ().end (),
731
+ [](const ir::Function* a, const ir::Function* b) {
732
+ return a->decl ()->name ()->str () < b->decl ()->name ()->str ();
731
733
});
732
- for (const auto & decl : cc_.functions ()) {
733
- if (symbols.count (decl))
734
- continue ;
735
- if (decl->canonical () != decl)
734
+
735
+ for (const auto & fun : mod->functions ()) {
736
+ auto decl = fun->decl ();
737
+
738
+ if (decl->is_native () || !fun->body ())
736
739
continue ;
737
- global_symbols.push_back (decl);
738
- symbols.emplace (decl);
739
- }
740
740
741
- std::sort (global_symbols.begin (), global_symbols.end (),
742
- [](const Decl* a, const Decl *b) -> bool {
743
- return a->name ()->str () < b->name ()->str ();
744
- });
741
+ function_entry entry;
742
+ entry.fun = fun;
743
+ if (decl->is_public ()) {
744
+ entry.name = decl->name ()->str ();
745
+ } else {
746
+ // Create a private name.
747
+ entry.name = ke::StringPrintf (" .%d.%s" , fun->label ().offset (), decl->name ()->chars ());
748
+ }
749
+
750
+ functions.emplace_back (std::move (entry));
751
+ }
745
752
753
+ #if 0
746
754
// Build the easy symbol tables.
747
755
for (const auto& decl : global_symbols) {
748
- if (auto fun = decl->as <FunctionDecl>()) {
749
- if (fun->is_native ())
750
- continue ;
751
-
752
- if (!fun->body ())
753
- continue ;
754
- if (!fun->is_live ())
755
- continue ;
756
- if (fun->canonical () != fun)
757
- continue ;
758
-
759
- function_entry entry;
760
- entry.decl = fun;
761
- if (fun->is_public ()) {
762
- entry.name = fun->name ()->str ();
763
- } else {
764
- // Create a private name.
765
- entry.name = ke::StringPrintf (" .%d.%s" , fun->cg ()->label .offset (), fun->name ()->chars ());
766
- }
767
-
768
- functions.emplace_back (std::move (entry));
769
- } else if (auto var = decl->as <VarDecl>()) {
756
+ if (auto var = decl->as<VarDecl>()) {
770
757
if (var->is_public() || (var->is_used() && !var->as<ConstDecl>())) {
771
758
sp_file_pubvars_t& pubvar = pubvars->add();
772
759
pubvar.address = var->addr();
773
760
pubvar.name = names->add(var->name());
774
761
}
775
762
}
776
763
}
764
+ #endif
777
765
778
766
// The public list must be sorted.
779
767
std::sort (functions.begin (), functions.end (),
@@ -783,31 +771,27 @@ Assembler::Assemble(SmxByteBuffer* buffer)
783
771
for (size_t i = 0 ; i < functions.size (); i++) {
784
772
function_entry& f = functions[i];
785
773
786
- assert (f.decl ->cg ()->label .offset () > 0 );
787
- assert (f.decl ->impl ());
788
- assert (f.decl ->cg ()->pcode_end > f.decl ->cg ()->label .offset ());
789
-
790
774
sp_file_publics_t & pubfunc = publics->add ();
791
- pubfunc.address = f.decl -> cg ()-> label .offset ();
775
+ pubfunc.address = f.fun -> label () .offset ();
792
776
pubfunc.name = names->add (*cc_.atoms (), f.name .c_str ());
793
777
794
778
auto id = (uint32_t (i) << 1 ) | 1 ;
795
779
if (!Label::ValueFits (id))
796
780
report (421 );
797
- cg_.LinkPublicFunction (f.decl , id);
781
+ cg_.LinkPublicFunction (f.fun , id);
798
782
799
- rtti.add_method (f.decl );
783
+ rtti.add_method (f.fun );
800
784
}
801
785
802
786
// Populate the native table.
803
787
for (size_t i = 0 ; i < cg_.native_list ().size (); i++) {
804
- FunctionDecl * sym = cg_.native_list ()[i];
805
- assert (size_t (sym->cg ()-> label .offset ()) == i);
788
+ ir::Function * sym = cg_.native_list ()[i];
789
+ assert (size_t (sym->label () .offset ()) == i);
806
790
807
791
sp_file_natives_t & entry = natives->add ();
808
- entry.name = names->add (sym->name ());
792
+ entry.name = names->add (sym->decl ()-> name ());
809
793
810
- rtti.add_native (sym);
794
+ rtti.add_native (sym-> decl () );
811
795
}
812
796
813
797
// Set up the code section.
0 commit comments