@@ -22,13 +22,16 @@ class Program {
2222 var mainRootIndex = -1;
2323 var explicitName: string;
2424 var tprog: TargetProgram;
25+ var numImports = 0;
2526
2627 // dynamic portion of the program, including initialized state
2728 var initState: Array<InitState>;
2829 var compRecords: Array<Record>;
2930 var strRecords: Array<Record>;
3031 var recordCount: int;
3132 var system: SystemCallState;
33+ var wasmFuncId_imported = 0;
34+ var wasmFuncId_internal = 0;
3235
3336 new() {
3437 opBuilder = IrOpMethodBuilder.new(this);
@@ -193,6 +196,22 @@ class Program {
193196 if (trt != frt) requestMapper(frt, trt); // results are covariant
194197 }
195198 }
199+ def makeFunctionId(meth: IrSpec) -> int {
200+ // XXX: linear search for function id
201+ for (i < ir.roots.length) {
202+ var r = ir.roots[i];
203+ if (r.spec.equals(meth)) {
204+ if (r.functionId < 0) r.functionId = assignFunctionId(meth);
205+ return r.functionId;
206+ }
207+ }
208+ var r = IrRoot.new(null, meth);
209+ ir.roots.put(r);
210+ return r.functionId = assignFunctionId(meth);
211+ }
212+ def assignFunctionId(meth: IrSpec) -> int {
213+ return if(meth.asMethod().isImported(), wasmFuncId_imported++, wasmFuncId_internal++);
214+ }
196215}
197216// Representation of the program appropriate for the target, e.g. a machine.
198217class TargetProgram(prog: Program) {
0 commit comments