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:
oooooba
2018-10-20 02:49:41 +09:00
committed by Dan Gohman
parent e10a3434b8
commit 709eed21c1
5 changed files with 70 additions and 39 deletions

View File

@@ -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]))