Use types to represent wasm global/table/memory/signature indices (#560)
* Use a type to represent wasm table indices. * Use a type to represent wasm global variable indices. * Use a type to represent wasm memory indices. * Use a type to represent wasm signature indices. * Use PrimaryMap instead of Vec to protect against using wrong indices.
This commit is contained in:
@@ -287,7 +287,7 @@ impl TranslationState {
|
||||
index: u32,
|
||||
environ: &mut FE,
|
||||
) -> GlobalVariable {
|
||||
let index = index as GlobalIndex;
|
||||
let index = GlobalIndex::new(index as usize);
|
||||
*self
|
||||
.globals
|
||||
.entry(index)
|
||||
@@ -302,7 +302,7 @@ impl TranslationState {
|
||||
index: u32,
|
||||
environ: &mut FE,
|
||||
) -> ir::Heap {
|
||||
let index = index as MemoryIndex;
|
||||
let index = MemoryIndex::new(index as usize);
|
||||
*self
|
||||
.heaps
|
||||
.entry(index)
|
||||
@@ -317,7 +317,7 @@ impl TranslationState {
|
||||
index: u32,
|
||||
environ: &mut FE,
|
||||
) -> ir::Table {
|
||||
let index = index as TableIndex;
|
||||
let index = TableIndex::new(index as usize);
|
||||
*self
|
||||
.tables
|
||||
.entry(index)
|
||||
@@ -334,7 +334,7 @@ impl TranslationState {
|
||||
index: u32,
|
||||
environ: &mut FE,
|
||||
) -> (ir::SigRef, usize) {
|
||||
let index = index as SignatureIndex;
|
||||
let index = SignatureIndex::new(index as usize);
|
||||
*self.signatures.entry(index).or_insert_with(|| {
|
||||
let sig = environ.make_indirect_sig(func, index);
|
||||
(sig, normal_args(&func.dfg.signatures[sig]))
|
||||
|
||||
Reference in New Issue
Block a user