MCPcopy Index your code
hub / github.com/acsoto/BUAA-Compiler / getAddress

Method getAddress

src/CodeGeneration/PCodeExecutor.java:339–362  ·  view source on GitHub ↗
(Var var, int intType)

Source from the content-addressed store, hash-verified

337 }
338
339 private int getAddress(Var var, int intType) {
340 // reminder: n is the actual type
341 // for example, to int a[3][2] ,a[0][0] is 0, a[0] is 1, a is 2
342 // so when search for address, the real [] num is defined dim - n
343 int address = 0;
344 int n = var.getDimension() - intType;
345 if (n == 0) {
346 address = var.getIndex();
347 }
348 if (n == 1) {
349 int i = pop();
350 if (var.getDimension() == 1) {
351 address = var.getIndex() + i;
352 } else {
353 address = var.getIndex() + var.getDim2() * i;
354 }
355 }
356 if (n == 2) {
357 int j = pop();
358 int i = pop();
359 address = var.getIndex() + var.getDim2() * i + j;
360 }
361 return address;
362 }
363
364 public void print() throws IOException {
365 //System.out.println("—————————输出———————————");

Callers 1

runMethod · 0.95

Calls 4

popMethod · 0.95
getDimensionMethod · 0.80
getDim2Method · 0.80
getIndexMethod · 0.45

Tested by

no test coverage detected