Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.14 KB | None | 0 0
  1. /*******************************************************************************
  2. * Copyright (C) 2016 Embedded Systems and Applications Group
  3. * Department of Computer Science, Technische Universitaet Darmstadt,
  4. * Hochschulstr. 10, 64289 Darmstadt, Germany.
  5. *
  6. * All rights reserved.
  7. *
  8. * This software is provided free for educational use only.
  9. * It may not be used for commercial purposes without the
  10. * prior written permission of the authors.
  11. ******************************************************************************/
  12.  
  13. /* TODO: Please fill this out!
  14. *
  15. * EiCB group number:
  16. * Names and student ID numbers of group members:
  17. */
  18.  
  19. package mavlc.codegen;
  20.  
  21. import MTAM.Instruction;
  22. import mavlc.ast.nodes.ASTNode;
  23. import mavlc.ast.nodes.expression.Addition;
  24. import mavlc.ast.nodes.expression.And;
  25. import mavlc.ast.nodes.expression.BoolNot;
  26. import mavlc.ast.nodes.expression.BoolValue;
  27. import mavlc.ast.nodes.expression.CallExpression;
  28. import mavlc.ast.nodes.expression.Compare;
  29. import mavlc.ast.nodes.expression.Compare.Comparison;
  30. import mavlc.ast.nodes.expression.Division;
  31. import mavlc.ast.nodes.expression.DotProduct;
  32. import mavlc.ast.nodes.expression.ElementSelect;
  33. import mavlc.ast.nodes.expression.Expression;
  34. import mavlc.ast.nodes.expression.FloatValue;
  35. import mavlc.ast.nodes.expression.IdentifierReference;
  36. import mavlc.ast.nodes.expression.IntValue;
  37. import mavlc.ast.nodes.expression.MatrixMultiplication;
  38. import mavlc.ast.nodes.expression.MatrixXDimension;
  39. import mavlc.ast.nodes.expression.MatrixYDimension;
  40. import mavlc.ast.nodes.expression.Multiplication;
  41. import mavlc.ast.nodes.expression.Or;
  42. import mavlc.ast.nodes.expression.StringValue;
  43. import mavlc.ast.nodes.expression.StructureInit;
  44. import mavlc.ast.nodes.expression.SubMatrix;
  45. import mavlc.ast.nodes.expression.SubVector;
  46. import mavlc.ast.nodes.expression.Subtraction;
  47. import mavlc.ast.nodes.expression.UnaryMinus;
  48. import mavlc.ast.nodes.expression.VectorDimension;
  49. import mavlc.ast.nodes.function.FormalParameter;
  50. import mavlc.ast.nodes.function.Function;
  51. import mavlc.ast.nodes.module.Module;
  52. import mavlc.ast.nodes.statement.CallStatement;
  53. import mavlc.ast.nodes.statement.CompoundStatement;
  54. import mavlc.ast.nodes.statement.Declaration;
  55. import mavlc.ast.nodes.statement.ForLoop;
  56. import mavlc.ast.nodes.statement.IfStatement;
  57. import mavlc.ast.nodes.statement.LeftHandIdentifier;
  58. import mavlc.ast.nodes.statement.MatrixLHSIdentifier;
  59. import mavlc.ast.nodes.statement.ReturnStatement;
  60. import mavlc.ast.nodes.statement.Statement;
  61. import mavlc.ast.nodes.statement.ValueDefinition;
  62. import mavlc.ast.nodes.statement.VariableAssignment;
  63. import mavlc.ast.nodes.statement.VariableDeclaration;
  64. import mavlc.ast.nodes.statement.VectorLHSIdentifier;
  65. import mavlc.ast.type.FloatType;
  66. import mavlc.ast.type.IntType;
  67. import mavlc.ast.type.MatrixType;
  68. import mavlc.ast.type.StructType;
  69. import mavlc.ast.type.Type;
  70. import mavlc.ast.type.VectorType;
  71. import mavlc.ast.visitor.ASTNodeBaseVisitor;
  72. import mavlc.codegen.TAMAssembler.Register;
  73. import mavlc.context_analysis.ModuleEnvironment;
  74.  
  75. public class CodeGeneration extends ASTNodeBaseVisitor<Instruction, Integer> {
  76.  
  77. protected TAMAssembler assembler;
  78.  
  79. protected final ModuleEnvironment env;
  80.  
  81. public CodeGeneration(ModuleEnvironment environment, TAMAssembler ass) {
  82. env = environment;
  83. assembler = ass;
  84. }
  85.  
  86. /*
  87. * (non-Javadoc)
  88. *
  89. * @see
  90. * mavlc.ast.visitor.ASTNodeBaseVisitor#defaultOperation(mavlc.ast.nodes.
  91. * ASTNode, java.lang.Function)
  92. */
  93. @Override
  94. protected Instruction defaultOperation(ASTNode node, Integer arg1) {
  95. throw new UnsupportedOperationException("Code generation for this element is not implemented!");
  96. }
  97.  
  98. /*
  99. * (non-Javadoc)
  100. *
  101. * @see
  102. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitModule(mavlc.ast.nodes.module.
  103. * Module, java.lang.Function)
  104. */
  105. @Override
  106. public Instruction visitModule(Module module, Integer arg1) {
  107. for (Function func : module.getFunctions()) {
  108. func.accept(this, null);
  109. }
  110. return null;
  111. }
  112.  
  113. /*
  114. * (non-Javadoc)
  115. *
  116. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitFunction(mavlc.ast.nodes.
  117. * function.Function, java.lang.Function)
  118. */
  119. @Override
  120. public Instruction visitFunction(Function functionNode, Integer arg1) {
  121. assembler.addNewFunction(functionNode);
  122. /*
  123. * Visit all parameters.
  124. */
  125. int parameterSize = 0;
  126. for (FormalParameter param : functionNode.getParameters()) {
  127. parameterSize += param.getType().wordSize();
  128. }
  129. int argSize = parameterSize;
  130. parameterSize *= -1;
  131. for (FormalParameter param : functionNode.getParameters()) {
  132. /*
  133. * Calculate the (negative) offset relative to this functions LB.
  134. */
  135. param.accept(this, parameterSize);
  136. parameterSize += param.getType().wordSize();
  137. }
  138. /*
  139. * Visit all statements in the loop.
  140. */
  141. for (Statement stmt : functionNode.getFunctionBody()) {
  142. stmt.accept(this, argSize);
  143. }
  144. /*
  145. * Emit halt instruction for the main method
  146. */
  147. if (functionNode.getName().equals("main")) {
  148. assembler.emitHaltInstruction();
  149. }
  150. /*
  151. * Explicitly emit return for void functions.
  152. */
  153. else if (functionNode.getReturnType().equals(Type.getVoidType())) {
  154. assembler.emitReturn(0, argSize);
  155. }
  156. return null;
  157. }
  158.  
  159. /*
  160. * (non-Javadoc)
  161. *
  162. * @see
  163. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitFormalParameter(mavlc.ast.nodes
  164. * .function.FormalParameter, java.lang.Function)
  165. */
  166. @Override
  167. public Instruction visitFormalParameter(FormalParameter formalParameter, Integer arg1) {
  168. int startOffset = arg1;
  169. formalParameter.setLocalBaseOffset(startOffset);
  170. return null;
  171. }
  172.  
  173. /*
  174. * (non-Javadoc)
  175. *
  176. * @see
  177. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitValueDefinition(mavlc.ast.nodes
  178. * .statement.ValueDefinition, java.lang.Function)
  179. */
  180. @Override
  181. public Instruction visitValueDefinition(ValueDefinition valueDefinition, Integer arg1) {
  182. valueDefinition.getValue().accept(this, null);
  183. assembler.addDeclaredEntity(valueDefinition);
  184. return null;
  185. }
  186.  
  187. /*
  188. * (non-Javadoc)
  189. *
  190. * @see
  191. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitVariableDeclaration(mavlc.ast.
  192. * nodes.statement.VariableDeclaration, java.lang.Function)
  193. */
  194. @Override
  195. public Instruction visitVariableDeclaration(VariableDeclaration variableDeclaration, Integer arg1) {
  196. assembler.emitPush(variableDeclaration.getType().wordSize());
  197. assembler.addDeclaredEntity(variableDeclaration);
  198. return null;
  199. }
  200.  
  201. /*
  202. * (non-Javadoc)
  203. *
  204. * @see
  205. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitVariableAssignment(mavlc.ast.
  206. * nodes.statement.VariableAssignment, java.lang.Function)
  207. */
  208. @Override
  209. public Instruction visitVariableAssignment(VariableAssignment variableAssignment, Integer arg1) {
  210.  
  211. int wordsize = variableAssignment.getValue().getType().wordSize();
  212. variableAssignment.getValue().accept(this, null);
  213. variableAssignment.getIdentifier().accept(this, null);
  214. assembler.storeToStackAddress(wordsize);
  215.  
  216. // // load address of lhi
  217. // variableAssignment.getIdentifier().accept(this, null);
  218. //
  219. // assembler.storeValue(Register.LB, wordsize,
  220. // variableAssignment.getIdentifier().getDeclaration().getLocalBaseOffset());
  221. //
  222. // assembler.emitPop(0, wordsize);
  223.  
  224. return null;
  225. }
  226.  
  227. /*
  228. * (non-Javadoc)
  229. *
  230. * @see
  231. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitLeftHandIdentifier(mavlc.ast.
  232. * nodes.statement.LeftHandIdentifier, java.lang.Function)
  233. */
  234. @Override
  235. public Instruction visitLeftHandIdentifier(LeftHandIdentifier leftHandIdentifier, Integer arg1) {
  236. assembler.loadAddress(Register.LB, leftHandIdentifier.getDeclaration().getLocalBaseOffset());
  237.  
  238. return null;
  239. }
  240.  
  241. /*
  242. * (non-Javadoc)
  243. *
  244. * @see
  245. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitMatrixLHSIdentifier(mavlc.ast.
  246. * nodes.statement.MatrixLHSIdentifier, java.lang.Function)
  247. */
  248. @Override
  249. public Instruction visitMatrixLHSIdentifier(MatrixLHSIdentifier matrixLHSIdentifier, Integer arg1) {
  250. MatrixType mat = (MatrixType) matrixLHSIdentifier.getDeclaration().getType();
  251. matrixLHSIdentifier.getXIndex().accept(this, null);
  252. assembler.loadIntegerValue(mat.getyDimension());
  253. assembler.emitIntegerMultiplication();
  254. matrixLHSIdentifier.getYIndex().accept(this, null);
  255. assembler.emitIntegerAddition();
  256.  
  257. assembler.loadAddress(Register.LB, matrixLHSIdentifier.getDeclaration().getLocalBaseOffset());
  258. assembler.emitIntegerAddition();
  259.  
  260. return null;
  261. }
  262.  
  263. /*
  264. * (non-Javadoc)
  265. *
  266. * @see
  267. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitVectorLHSIdentifier(mavlc.ast.
  268. * nodes.statement.VectorLHSIdentifier, java.lang.Function)
  269. */
  270. @Override
  271. public Instruction visitVectorLHSIdentifier(VectorLHSIdentifier vectorLHSIdentifier, Integer arg1) {
  272. if (vectorLHSIdentifier.getDeclaration().getType() instanceof MatrixType) {
  273. MatrixType mat = (MatrixType) vectorLHSIdentifier.getDeclaration().getType();
  274. assembler.loadIntegerValue(mat.getyDimension());
  275. vectorLHSIdentifier.getIndex().accept(this, null);
  276. assembler.emitFloatMultiplication();
  277. } else {
  278. vectorLHSIdentifier.getIndex().accept(this, null);
  279. }
  280. assembler.loadAddress(Register.LB, vectorLHSIdentifier.getDeclaration().getLocalBaseOffset());
  281. assembler.emitIntegerAddition();
  282. return null;
  283. }
  284.  
  285. /*
  286. * (non-Javadoc)
  287. *
  288. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitForLoop(mavlc.ast.nodes.
  289. * statement.ForLoop, java.lang.Function)
  290. */
  291. @Override
  292. public Instruction visitForLoop(ForLoop forLoop, Integer arg1) {
  293. throw new UnsupportedOperationException("Not implemented yet.");
  294. }
  295.  
  296. /*
  297. * (non-Javadoc)
  298. *
  299. * @see
  300. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitIfStatement(mavlc.ast.nodes.
  301. * statement.IfStatement, java.lang.Function)
  302. */
  303. @Override
  304. public Instruction visitIfStatement(IfStatement ifStatement, Integer arg1) {
  305. // throw new UnsupportedOperationException("Not implemented yet.");
  306.  
  307. ifStatement.getTestExpression().accept(this, null);
  308.  
  309. if (ifStatement.hasElseStatement()) {
  310. // adresse ist im moment noch nicht bekannt
  311. ifStatement.getTestExpression().accept(this, null);
  312. assembler.emitConditionalJump(false, 0);
  313. ifStatement.getThenStatement().accept(this, null);
  314. assembler.emitJump(0);
  315. int ad1 = assembler.getNextInstructionAddress();
  316. ifStatement.getElseStatement().accept(this, null);
  317. int ad2 = assembler.getNextInstructionAddress();
  318. assembler.backPatchJump(assembler.emitConditionalJump(false, 0), ad1);
  319. assembler.backPatchJump(assembler.emitJump(0), ad2);
  320.  
  321. } else {
  322. ifStatement.getTestExpression().accept(this, null);
  323. assembler.emitConditionalJump(false, 0);
  324. ifStatement.getThenStatement().accept(this, null);
  325. int ad1 = assembler.getNextInstructionAddress();
  326. assembler.backPatchJump(assembler.emitConditionalJump(false, 0), ad1);
  327. }
  328.  
  329. // expression liegt nun ua fdem stack
  330.  
  331. // assembler.emitConditionalJump(condition, address)
  332.  
  333. return null;
  334. }
  335.  
  336. /*
  337. * (non-Javadoc)
  338. *
  339. * @see
  340. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitCallStatement(mavlc.ast.nodes.
  341. * statement.CallStatement, java.lang.Function)
  342. */
  343. @Override
  344. public Instruction visitCallStatement(CallStatement callStatement, Integer arg1) {
  345. callStatement.getCall().accept(this, null);
  346. /*
  347. * We need to clean the stack, i.e. pop the unused result if a non-void
  348. * function was called in this call statement.
  349. */
  350. Function callee = env.getFunctionDeclaration(callStatement.getCall().getCalleeName());
  351. if (!callee.getReturnType().equals(Type.getVoidType())) {
  352. assembler.emitPop(0, callee.getReturnType().wordSize());
  353. }
  354. return null;
  355. }
  356.  
  357. /*
  358. * (non-Javadoc)
  359. *
  360. * @see
  361. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitReturnStatement(mavlc.ast.nodes
  362. * .statement.ReturnStatement, java.lang.Function)
  363. */
  364. @Override
  365. public Instruction visitReturnStatement(ReturnStatement returnStatement, Integer arg1) {
  366. returnStatement.getReturnValue().accept(this, null);
  367. int resultSize = returnStatement.getReturnValue().getType().wordSize();
  368. int argSize = arg1;
  369. // Function func = (Function) obj;
  370. // for(FormalParameter param : func.getParameters()){
  371. // argSize += param.getType().wordSize();
  372. // }
  373. assembler.emitReturn(resultSize, argSize);
  374. return null;
  375. }
  376.  
  377. /*
  378. * (non-Javadoc)
  379. *
  380. * @see
  381. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitCompoundStatement(mavlc.ast.
  382. * nodes.statement.CompoundStatement, java.lang.Function)
  383. */
  384. @Override
  385. public Instruction visitCompoundStatement(CompoundStatement compoundStatement, Integer arg1) {
  386. int nextOffset = assembler.getNextOffset();
  387. for (Statement stmt : compoundStatement.getStatements()) {
  388. stmt.accept(this, null);
  389. }
  390. int size = assembler.getNextOffset() - nextOffset;
  391. assembler.emitPop(0, size);
  392. assembler.setNextOffset(nextOffset);
  393. return null;
  394. }
  395.  
  396. /*
  397. * (non-Javadoc)
  398. *
  399. * @see
  400. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitMatrixMultiplication(mavlc.ast.
  401. * nodes.expression.MatrixMultiplication, java.lang.Function)
  402. */
  403. @Override
  404. public Instruction visitMatrixMultiplication(MatrixMultiplication matrixMultiplication, Integer arg1) {
  405. matrixMultiplication.getLeftOp().accept(this, null);
  406. matrixMultiplication.getRightOp().accept(this, null);
  407. StructType structAType = (StructType) matrixMultiplication.getLeftOp().getType();
  408. StructType structBType = (StructType) matrixMultiplication.getRightOp().getType();
  409. if (structAType instanceof MatrixType && structBType instanceof MatrixType) {
  410. MatrixType matAType = (MatrixType) structAType;
  411. MatrixType matBType = (MatrixType) structBType;
  412. assembler.loadIntegerValue(matAType.getxDimension());
  413. assembler.loadIntegerValue(matAType.getyDimension());
  414. assembler.loadIntegerValue(matBType.getyDimension());
  415. assembler.emitMatrixMultiplication();
  416. return null;
  417. } else if (structAType instanceof VectorType && structBType instanceof MatrixType) {
  418. VectorType vecAType = (VectorType) structAType;
  419. MatrixType matBType = (MatrixType) structBType;
  420. assembler.loadIntegerValue(1);
  421. assembler.loadIntegerValue(vecAType.getDimension());
  422. assembler.loadIntegerValue(matBType.getyDimension());
  423. assembler.emitMatrixMultiplication();
  424. return null;
  425. } else {
  426. MatrixType matAType = (MatrixType) structAType;
  427. VectorType vecBType = (VectorType) structBType;
  428. assembler.loadIntegerValue(matAType.getxDimension());
  429. assembler.loadIntegerValue(matAType.getyDimension());
  430. assembler.loadIntegerValue(1);
  431. assembler.emitMatrixMultiplication();
  432. return null;
  433. }
  434. }
  435.  
  436. /*
  437. * (non-Javadoc)
  438. *
  439. * @see
  440. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitDotProduct(mavlc.ast.nodes.
  441. * expression.DotProduct, java.lang.Function)
  442. */
  443. @Override
  444. public Instruction visitDotProduct(DotProduct dotProduct, Integer arg1) {
  445. throw new UnsupportedOperationException("Not implemented yet.");
  446. }
  447.  
  448. /*
  449. * (non-Javadoc)
  450. *
  451. * @see
  452. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitMultiplication(mavlc.ast.nodes.
  453. * expression.Multiplication, java.lang.Function)
  454. */
  455. @Override
  456. public Instruction visitMultiplication(Multiplication multiplication, Integer arg1) {
  457. Type resultType = multiplication.getType();
  458. Type leftType = multiplication.getLeftOp().getType();
  459. Type rightType = multiplication.getRightOp().getType();
  460. if (resultType.equals(IntType.getIntType())) {
  461. multiplication.getLeftOp().accept(this, null);
  462. multiplication.getRightOp().accept(this, null);
  463. assembler.emitIntegerMultiplication();
  464. } else if (resultType.equals(FloatType.getFloatType())) {
  465. multiplication.getLeftOp().accept(this, null);
  466. multiplication.getRightOp().accept(this, null);
  467. assembler.emitFloatMultiplication();
  468. } else if (leftType instanceof StructType && rightType instanceof StructType) {
  469. multiplication.getLeftOp().accept(this, null);
  470. multiplication.getRightOp().accept(this, null);
  471. StructType structType = (StructType) multiplication.getLeftOp().getType();
  472. assembler.loadIntegerValue(0);
  473. int loopBegin = assembler.getNextInstructionAddress();
  474. assembler.loadValue(Register.ST, 1, -1);
  475. assembler.loadAddress(Register.ST, -2 - multiplication.getLeftOp().getType().wordSize()
  476. - multiplication.getRightOp().getType().wordSize());
  477. assembler.emitIntegerAddition();
  478. assembler.loadFromStackAddress(1);
  479. assembler.loadValue(Register.ST, 1, -2);
  480. assembler.loadAddress(Register.ST, -3 - multiplication.getRightOp().getType().wordSize());
  481. assembler.emitIntegerAddition();
  482. assembler.loadFromStackAddress(1);
  483. if (structType.getElementType().equals(Type.getIntType())) {
  484. assembler.emitIntegerMultiplication();
  485. } else {
  486. assembler.emitFloatMultiplication();
  487. }
  488. assembler.loadValue(Register.ST, 1, -2);
  489. assembler.loadAddress(Register.ST, -3 - multiplication.getLeftOp().getType().wordSize()
  490. - multiplication.getRightOp().getType().wordSize());
  491. assembler.emitIntegerAddition();
  492. assembler.storeToStackAddress(1);
  493. assembler.loadValue(Register.ST, 1, -1);
  494. assembler.loadIntegerValue(1);
  495. assembler.emitIntegerAddition();
  496. assembler.loadAddress(Register.ST, -2);
  497. assembler.storeToStackAddress(1);
  498. assembler.loadValue(Register.ST, 1, -1);
  499. assembler.loadIntegerValue(multiplication.getLeftOp().getType().wordSize());
  500. assembler.emitIntegerComparison(Comparison.LESS);
  501. assembler.emitConditionalJump(true, loopBegin);
  502. assembler.emitPop(0, 1 + multiplication.getRightOp().getType().wordSize());
  503. } else {
  504. /*
  505. * One Operand is Skalar and one is matrix or vector. Since the
  506. * Mat/Vec scalar multiplication is commutative, we may switch them
  507. * to always have the same Stack Layout. Additionally we load a
  508. * counter.
  509. *
  510. */
  511. int matSize;
  512. Type scalarType;
  513. if (leftType instanceof StructType) {
  514. multiplication.getLeftOp().accept(this, null);
  515. multiplication.getRightOp().accept(this, null);
  516. matSize = multiplication.getLeftOp().getType().wordSize();
  517. scalarType = multiplication.getRightOp().getType();
  518. } else {
  519. multiplication.getRightOp().accept(this, null);
  520. multiplication.getLeftOp().accept(this, null);
  521. matSize = multiplication.getRightOp().getType().wordSize();
  522. scalarType = multiplication.getLeftOp().getType();
  523. }
  524. assembler.loadIntegerValue(0);
  525. /*
  526. * We now get started with the loop. Since every value is multiplied
  527. * with the same scalar, we can use the same loop with matrizes and
  528. * vectors. Each Iteration loads a Vec/Mat-element, as well as the
  529. * scalar and then stores the scalar back to the mat/vec. Afterwards
  530. * we increment the counter and check if it is LESSEQUAL to the
  531. * wordSize of Mat/vec. If so we continue, else we clean up the
  532. * stack and are done.
  533. */
  534. int loopStart = assembler.getNextInstructionAddress();
  535. assembler.loadValue(Register.ST, 1, -1);
  536. assembler.loadAddress(Register.ST, -3 - matSize);
  537. assembler.emitIntegerAddition();
  538. assembler.loadFromStackAddress(1);
  539. assembler.loadValue(Register.ST, 1, -3);
  540. if (scalarType.equals(Type.getIntType())) {
  541. assembler.emitIntegerMultiplication();
  542. } else {
  543. assembler.emitFloatMultiplication();
  544. }
  545. assembler.loadValue(Register.ST, 1, -2);
  546. assembler.loadAddress(Register.ST, -4 - matSize);
  547. assembler.emitIntegerAddition();
  548. assembler.storeToStackAddress(1);
  549. /*
  550. * Loop Body ends here... Now we increment and check.
  551. */
  552. assembler.loadValue(Register.ST, 1, -1);
  553. assembler.loadIntegerValue(1);
  554. assembler.emitIntegerAddition();
  555. assembler.storeValue(Register.ST, 1, -2);
  556. assembler.loadValue(Register.ST, 1, -1);
  557. assembler.loadIntegerValue(matSize);
  558. assembler.emitIntegerComparison(Comparison.LESS_EQUAL);
  559. assembler.emitConditionalJump(true, loopStart);
  560. assembler.emitPop(0, 2);
  561. }
  562. return null;
  563. }
  564.  
  565. /*
  566. * (non-Javadoc)
  567. *
  568. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitDivision(mavlc.ast.nodes.
  569. * expression.Division, java.lang.Function)
  570. */
  571. @Override
  572. public Instruction visitDivision(Division division, Integer arg1) {
  573.  
  574. Type resultType = division.getType();
  575. if (resultType.equals(IntType.getIntType())) {
  576. division.getLeftOp().accept(this, null);
  577. division.getRightOp().accept(this, null);
  578. assembler.emitIntegerDivision();
  579. } else if (resultType.equals(FloatType.getFloatType())) {
  580. division.getLeftOp().accept(this, null);
  581. division.getRightOp().accept(this, null);
  582. assembler.emitFloatDivision();
  583. }
  584.  
  585. return null;
  586. }
  587.  
  588. /*
  589. * (non-Javadoc)
  590. *
  591. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitAddition(mavlc.ast.nodes.
  592. * expression.Addition, java.lang.Function)
  593. */
  594. @Override
  595. public Instruction visitAddition(Addition addition, Integer arg1) {
  596. Type resultType = addition.getType();
  597. Type leftType = addition.getLeftOp().getType();
  598. Type rightType = addition.getRightOp().getType();
  599. if (resultType.equals(IntType.getIntType())) {
  600. addition.getLeftOp().accept(this, null);
  601. addition.getRightOp().accept(this, null);
  602. assembler.emitIntegerAddition();
  603. } else if (resultType.equals(FloatType.getFloatType())) {
  604. addition.getLeftOp().accept(this, null);
  605. addition.getRightOp().accept(this, null);
  606. assembler.emitFloatAddition();
  607. } else if (leftType instanceof StructType && rightType instanceof StructType) {
  608. addition.getLeftOp().accept(this, null);
  609. addition.getRightOp().accept(this, null);
  610. StructType structType = (StructType) addition.getLeftOp().getType();
  611. assembler.loadIntegerValue(0);
  612. int loopBegin = assembler.getNextInstructionAddress();
  613. assembler.loadValue(Register.ST, 1, -1);
  614. assembler.loadAddress(Register.ST,
  615. -2 - addition.getLeftOp().getType().wordSize() - addition.getRightOp().getType().wordSize());
  616. assembler.emitIntegerAddition();
  617. assembler.loadFromStackAddress(1);
  618. assembler.loadValue(Register.ST, 1, -2);
  619. assembler.loadAddress(Register.ST, -3 - addition.getRightOp().getType().wordSize());
  620. assembler.emitIntegerAddition();
  621. assembler.loadFromStackAddress(1);
  622. if (structType.getElementType().equals(Type.getIntType())) {
  623. assembler.emitIntegerAddition();
  624. } else {
  625. assembler.emitFloatAddition();
  626. }
  627. assembler.loadValue(Register.ST, 1, -2);
  628. assembler.loadAddress(Register.ST,
  629. -3 - addition.getLeftOp().getType().wordSize() - addition.getRightOp().getType().wordSize());
  630. assembler.emitIntegerAddition();
  631. assembler.storeToStackAddress(1);
  632. assembler.loadValue(Register.ST, 1, -1);
  633. assembler.loadIntegerValue(1);
  634. assembler.emitIntegerAddition();
  635. assembler.loadAddress(Register.ST, -2);
  636. assembler.storeToStackAddress(1);
  637. assembler.loadValue(Register.ST, 1, -1);
  638. assembler.loadIntegerValue(addition.getLeftOp().getType().wordSize());
  639. assembler.emitIntegerComparison(Comparison.LESS);
  640. assembler.emitConditionalJump(true, loopBegin);
  641. assembler.emitPop(0, 1 + addition.getRightOp().getType().wordSize());
  642. } else {
  643. /*
  644. * One Operand is Skalar and one is matrix or vector. Since the
  645. * Mat/Vec scalar multiplication is commutative, we may switch them
  646. * to always have the same Stack Layout. Additionally we load a
  647. * counter.
  648. *
  649. */
  650. int matSize;
  651. Type scalarType;
  652. if (leftType instanceof StructType) {
  653. addition.getLeftOp().accept(this, null);
  654. addition.getRightOp().accept(this, null);
  655. matSize = addition.getLeftOp().getType().wordSize();
  656. scalarType = addition.getRightOp().getType();
  657. } else {
  658. addition.getRightOp().accept(this, null);
  659. addition.getLeftOp().accept(this, null);
  660. matSize = addition.getRightOp().getType().wordSize();
  661. scalarType = addition.getLeftOp().getType();
  662. }
  663. assembler.loadIntegerValue(0);
  664. /*
  665. * We now get started with the loop. Since every value is multiplied
  666. * with the same scalar, we can use the same loop with matrizes and
  667. * vectors. Each Iteration loads a Vec/Mat-element, as well as the
  668. * scalar and then stores the scalar back to the mat/vec. Afterwards
  669. * we increment the counter and check if it is LESSEQUAL to the
  670. * wordSize of Mat/vec. If so we continue, else we clean up the
  671. * stack and are done.
  672. */
  673. int loopStart = assembler.getNextInstructionAddress();
  674. assembler.loadValue(Register.ST, 1, -1);
  675. assembler.loadAddress(Register.ST, -3 - matSize);
  676. assembler.emitIntegerAddition();
  677. assembler.loadFromStackAddress(1);
  678. assembler.loadValue(Register.ST, 1, -3);
  679. if (scalarType.equals(Type.getIntType())) {
  680. assembler.emitIntegerAddition();
  681. } else {
  682. assembler.emitFloatAddition();
  683. }
  684. assembler.loadValue(Register.ST, 1, -2);
  685. assembler.loadAddress(Register.ST, -4 - matSize);
  686. assembler.emitIntegerAddition();
  687. assembler.storeToStackAddress(1);
  688. /*
  689. * Loop Body ends here... Now we increment and check.
  690. */
  691. assembler.loadValue(Register.ST, 1, -1);
  692. assembler.loadIntegerValue(1);
  693. assembler.emitIntegerAddition();
  694. assembler.storeValue(Register.ST, 1, -2);
  695. assembler.loadValue(Register.ST, 1, -1);
  696. assembler.loadIntegerValue(matSize);
  697. assembler.emitIntegerComparison(Comparison.LESS_EQUAL);
  698. assembler.emitConditionalJump(true, loopStart);
  699. assembler.emitPop(0, 2);
  700. }
  701. return null;
  702. }
  703.  
  704. /*
  705. * (non-Javadoc)
  706. *
  707. * @see
  708. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitSubtraction(mavlc.ast.nodes.
  709. * expression.Subtraction, java.lang.Function)
  710. */
  711. @Override
  712. public Instruction visitSubtraction(Subtraction subtraction, Integer arg1) {
  713. subtraction.getLeftOp().accept(this, null);
  714. subtraction.getRightOp().accept(this, null);
  715. if (subtraction.getType().equals(IntType.getIntType())) {
  716. assembler.emitIntegerSubtraction();
  717. } else if (subtraction.getType().equals(FloatType.getFloatType())) {
  718. assembler.emitFloatSubtraction();
  719. } else {
  720. StructType structType = (StructType) subtraction.getLeftOp().getType();
  721. assembler.loadIntegerValue(0);
  722. int loopBegin = assembler.getNextInstructionAddress();
  723. assembler.loadValue(Register.ST, 1, -1);
  724. assembler.loadAddress(Register.ST,
  725. -2 - subtraction.getLeftOp().getType().wordSize() - subtraction.getRightOp().getType().wordSize());
  726. assembler.emitIntegerAddition();
  727. assembler.loadFromStackAddress(1);
  728. assembler.loadValue(Register.ST, 1, -2);
  729. assembler.loadAddress(Register.ST, -3 - subtraction.getRightOp().getType().wordSize());
  730. assembler.emitIntegerAddition();
  731. assembler.loadFromStackAddress(1);
  732. if (structType.getElementType().equals(Type.getIntType())) {
  733. assembler.emitIntegerSubtraction();
  734. } else {
  735. assembler.emitFloatSubtraction();
  736. }
  737. assembler.loadValue(Register.ST, 1, -2);
  738. assembler.loadAddress(Register.ST,
  739. -3 - subtraction.getLeftOp().getType().wordSize() - subtraction.getRightOp().getType().wordSize());
  740. assembler.emitIntegerAddition();
  741. assembler.storeToStackAddress(1);
  742. assembler.loadValue(Register.ST, 1, -1);
  743. assembler.loadIntegerValue(1);
  744. assembler.emitIntegerAddition();
  745. assembler.loadAddress(Register.ST, -2);
  746. assembler.storeToStackAddress(1);
  747. assembler.loadValue(Register.ST, 1, -1);
  748. assembler.loadIntegerValue(subtraction.getLeftOp().getType().wordSize());
  749. assembler.emitIntegerComparison(Comparison.LESS);
  750. assembler.emitConditionalJump(true, loopBegin);
  751. assembler.emitPop(0, 1 + subtraction.getRightOp().getType().wordSize());
  752.  
  753. }
  754. return null;
  755. }
  756.  
  757. /*
  758. * (non-Javadoc)
  759. *
  760. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitCompare(mavlc.ast.nodes.
  761. * expression.Compare, java.lang.Function)
  762. */
  763. @Override
  764. public Instruction visitCompare(Compare compare, Integer arg1) {
  765. compare.getLeftOp().accept(this, null);
  766. compare.getRightOp().accept(this, null);
  767. if (compare.getLeftOp().getType().equals(IntType.getIntType())) {
  768. assembler.emitIntegerComparison(compare.getComparator());
  769. } else if (compare.getLeftOp().getType().equals(FloatType.getFloatType())) {
  770. assembler.emitFloatComparison(compare.getComparator());
  771. }
  772. return null;
  773. }
  774.  
  775. /*
  776. * (non-Javadoc)
  777. *
  778. * @see
  779. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitAnd(mavlc.ast.nodes.expression.
  780. * And, java.lang.Function)
  781. */
  782. @Override
  783. public Instruction visitAnd(And and, Integer arg1) {
  784. and.getLeftOp().accept(this, null);
  785. and.getRightOp().accept(this, null);
  786. assembler.emitLogicalAnd();
  787. return null;
  788. }
  789.  
  790. /*
  791. * (non-Javadoc)
  792. *
  793. * @see
  794. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitOr(mavlc.ast.nodes.expression.
  795. * Or, java.lang.Function)
  796. */
  797. @Override
  798. public Instruction visitOr(Or or, Integer arg1) {
  799. or.getLeftOp().accept(this, null);
  800. or.getRightOp().accept(this, null);
  801. assembler.emitLogicalOr();
  802. return null;
  803. }
  804.  
  805. /*
  806. * (non-Javadoc)
  807. *
  808. * @see
  809. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitMatrixXDimension(mavlc.ast.
  810. * nodes.expression.MatrixXDimension, java.lang.Function)
  811. */
  812. @Override
  813. public Instruction visitMatrixXDimension(MatrixXDimension xDimension, Integer arg1) {
  814. MatrixType type = (MatrixType) xDimension.getOperand().getType();
  815. assembler.loadIntegerValue(type.getxDimension());
  816. return null;
  817. }
  818.  
  819. /*
  820. * (non-Javadoc)
  821. *
  822. * @see
  823. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitMatrixYDimension(mavlc.ast.
  824. * nodes.expression.MatrixYDimension, java.lang.Function)
  825. */
  826. @Override
  827. public Instruction visitMatrixYDimension(MatrixYDimension yDimension, Integer arg1) {
  828. MatrixType type = (MatrixType) yDimension.getOperand().getType();
  829. assembler.loadIntegerValue(type.getyDimension());
  830. return null;
  831. }
  832.  
  833. /*
  834. * (non-Javadoc)
  835. *
  836. * @see
  837. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitVectorDimension(mavlc.ast.nodes
  838. * .expression.VectorDimension, java.lang.Function)
  839. */
  840. @Override
  841. public Instruction visitVectorDimension(VectorDimension vectorDimension, Integer arg1) {
  842. VectorType type = (VectorType) vectorDimension.getOperand().getType();
  843. assembler.loadIntegerValue(type.getDimension());
  844. return null;
  845. }
  846.  
  847. /*
  848. * (non-Javadoc)
  849. *
  850. * @see
  851. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitUnaryMinus(mavlc.ast.nodes.
  852. * expression.UnaryMinus, java.lang.Function)
  853. */
  854. @Override
  855. public Instruction visitUnaryMinus(UnaryMinus unaryMinus, Integer arg1) {
  856. unaryMinus.getOperand().accept(this, null);
  857. if (unaryMinus.getType().equals(IntType.getIntType())) {
  858. assembler.emitIntegerNegation();
  859. } else if (unaryMinus.getType().equals(FloatType.getFloatType())) {
  860. assembler.emitFloatNegation();
  861. }
  862. return null;
  863. }
  864.  
  865. /*
  866. * (non-Javadoc)
  867. *
  868. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitBoolNot(mavlc.ast.nodes.
  869. * expression.BoolNot, java.lang.Function)
  870. */
  871. @Override
  872. public Instruction visitBoolNot(BoolNot boolNot, Integer arg1) {
  873. boolNot.getOperand().accept(this, null);
  874. assembler.emitLogicalNot();
  875. return null;
  876. }
  877.  
  878. /*
  879. * (non-Javadoc)
  880. *
  881. * @see
  882. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitCallExpression(mavlc.ast.nodes.
  883. * expression.CallExpression, java.lang.Function)
  884. */
  885. @Override
  886. public Instruction visitCallExpression(CallExpression callExpression, Integer arg1) {
  887. /*
  888. * Evaluate operands, placing them on the stack one after the other.
  889. */
  890. for (Expression arg : callExpression.getActualParameters()) {
  891. arg.accept(this, null);
  892. }
  893. assembler.emitFunctionCall(env.getFunctionDeclaration(callExpression.getCalleeName()));
  894. return null;
  895. }
  896.  
  897. /*
  898. * (non-Javadoc)
  899. *
  900. * @see
  901. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitElementSelect(mavlc.ast.nodes.
  902. * expression.ElementSelect, java.lang.Function)
  903. */
  904. @Override
  905. public Instruction visitElementSelect(ElementSelect elementSelect, Integer arg1) {
  906.  
  907. if (elementSelect.getStruct().getType() instanceof VectorType) {
  908. VectorType vec = (VectorType) elementSelect.getStruct().getType();
  909. elementSelect.getStruct().accept(this, null);
  910. assembler.loadAddress(Register.ST, -vec.getDimension());
  911. elementSelect.getIndex().accept(this, null);
  912. assembler.emitIntegerAddition();
  913. assembler.loadFromStackAddress(1);
  914. assembler.emitPop(1, vec.getDimension());
  915.  
  916. } else {
  917. MatrixType matr = (MatrixType) elementSelect.getStruct().getType();
  918. elementSelect.getStruct().accept(this, null);
  919. // matrix auf dem stack
  920. elementSelect.getIndex().accept(this, null);
  921. assembler.loadAddress(Register.ST, -(matr.getxDimension() * matr.getyDimension()));
  922. elementSelect.getIndex().accept(this, null);
  923. assembler.loadIntegerValue(matr.getyDimension());
  924. assembler.emitIntegerMultiplication();
  925. assembler.emitIntegerAddition();
  926. assembler.loadFromStackAddress(matr.getyDimension());
  927. assembler.emitPop(matr.getyDimension(), matr.getxDimension() * matr.getyDimension());
  928. }
  929. return null;
  930. }
  931.  
  932. /*
  933. * (non-Javadoc)
  934. *
  935. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitSubMatrix(mavlc.ast.nodes.
  936. * expression.SubMatrix, java.lang.Function)
  937. */
  938. @Override
  939. public Instruction visitSubMatrix(SubMatrix subMatrix, Integer arg1) {
  940. MatrixType matRes = (MatrixType) subMatrix.getType();
  941. int resSize = matRes.wordSize();
  942. int resyDim = matRes.getyDimension();
  943. MatrixType matA = (MatrixType) subMatrix.getStruct().getType();
  944. int ASize = matA.wordSize();
  945. int AyDim = matA.getyDimension();
  946.  
  947. subMatrix.getStruct().accept(this, null);
  948. assembler.emitPush(resSize);
  949.  
  950. subMatrix.getXStartIndex().accept(this, null);
  951. subMatrix.getXBaseIndex().accept(this, null);
  952. subMatrix.getXEndIndex().accept(this, null);
  953. subMatrix.getYStartIndex().accept(this, null);
  954. subMatrix.getYBaseIndex().accept(this, null);
  955. subMatrix.getYEndIndex().accept(this, null);
  956. /*
  957. * All needed Expressions are now evaluated and on the Stack The next
  958. * step is the calculation of the Bounds.
  959. */
  960. assembler.loadValue(Register.ST, 2, -5);
  961. assembler.emitIntegerAddition();
  962.  
  963. assembler.loadValue(Register.ST, 2, -3);
  964. assembler.emitIntegerAddition();
  965.  
  966. assembler.loadValue(Register.ST, 2, -8);
  967. assembler.emitIntegerAddition();
  968.  
  969. assembler.loadValue(Register.ST, 2, -6);
  970. assembler.emitIntegerAddition();
  971.  
  972. assembler.emitPop(4, 6);
  973. assembler.loadIntegerValue(AyDim);
  974. assembler.loadValue(Register.ST, 2, -3);
  975. assembler.loadIntegerValue(0);
  976. /*
  977. * Stack at this Point: inMat, outMat, xEnd, yEnd ,xStart, yStart,
  978. * AyDim, i, j, c Everything on here is called Base in following
  979. * comments
  980. */
  981. int loop = assembler.getNextInstructionAddress();
  982. assembler.loadValue(Register.ST, 2, -4);
  983. assembler.emitIntegerMultiplication();
  984. assembler.loadValue(Register.ST, 1, -3);
  985. assembler.emitIntegerAddition();
  986. assembler.loadAddress(Register.ST, -1 - 8 - resSize - ASize);
  987. assembler.emitIntegerAddition();
  988. assembler.loadFromStackAddress(1); // Stack: Base, A[i*AyDim+j]
  989. assembler.loadValue(Register.ST, 1, -2);
  990. assembler.loadAddress(Register.ST, -2 - 8 - resSize);
  991. assembler.emitIntegerAddition();
  992. assembler.storeToStackAddress(1); // Stack: Base
  993. /*
  994. * Now we increment the counters and check for loop breaks;
  995. */
  996. assembler.loadValue(Register.ST, 1, -1);
  997. assembler.loadIntegerValue(1);
  998. assembler.emitIntegerAddition();
  999. assembler.storeValue(Register.ST, 1, -2);
  1000.  
  1001. assembler.loadValue(Register.ST, 1, -2);
  1002. assembler.loadIntegerValue(1);
  1003. assembler.emitIntegerAddition();
  1004. assembler.storeValue(Register.ST, 1, -3);
  1005.  
  1006. assembler.loadValue(Register.ST, 1, -2);
  1007. assembler.loadValue(Register.ST, 1, -8);
  1008. assembler.emitIntegerComparison(Comparison.LESS_EQUAL);
  1009. assembler.emitConditionalJump(true, loop);
  1010. // Inner Loop Done!
  1011. // Reset j, then increment i
  1012. assembler.loadValue(Register.ST, 1, -5);
  1013. assembler.storeValue(Register.ST, 1, -3);
  1014.  
  1015. assembler.loadValue(Register.ST, 1, -3);
  1016. assembler.loadIntegerValue(1);
  1017. assembler.emitIntegerAddition();
  1018. assembler.storeValue(Register.ST, 1, -4);
  1019.  
  1020. assembler.loadValue(Register.ST, 1, -3);
  1021. assembler.loadValue(Register.ST, 1, -9);
  1022. assembler.emitIntegerComparison(Comparison.LESS_EQUAL);
  1023. assembler.emitConditionalJump(true, loop);
  1024. // Both Loops done, clean stack and return
  1025. assembler.emitPop(0, 8);
  1026. assembler.emitPop(resSize, ASize);
  1027. return null;
  1028. }
  1029.  
  1030. /*
  1031. * (non-Javadoc)
  1032. *
  1033. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitSubVector(mavlc.ast.nodes.
  1034. * expression.SubVector, java.lang.Function)
  1035. */
  1036. @Override
  1037. public Instruction visitSubVector(SubVector subVector, Integer arg1) {
  1038. VectorType res = (VectorType) subVector.getType();
  1039. VectorType struct = (VectorType) subVector.getStruct().getType();
  1040. assembler.emitPush(res.wordSize());
  1041. subVector.getStruct().accept(this, null);
  1042. subVector.getBaseIndex().accept(this, null);
  1043. subVector.getStartIndex().accept(this, null);
  1044. subVector.getEndIndex().accept(this, null);
  1045. assembler.loadValue(Register.ST, 1, -3);
  1046. assembler.loadValue(Register.ST, 1, -3);
  1047. assembler.emitIntegerAddition();
  1048. assembler.emitPop(1, 3);
  1049. assembler.loadAddress(Register.ST, -1 - struct.wordSize());
  1050. assembler.emitIntegerAddition();
  1051. assembler.loadFromStackAddress(res.wordSize());
  1052. assembler.loadAddress(Register.ST, -res.wordSize() - res.wordSize() - struct.wordSize());
  1053. assembler.storeToStackAddress(res.wordSize());
  1054. assembler.emitPop(0, struct.wordSize());
  1055. return null;
  1056. }
  1057.  
  1058. /*
  1059. * (non-Javadoc)
  1060. *
  1061. * @see
  1062. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitStructureInit(mavlc.ast.nodes.
  1063. * expression.StructureInit, java.lang.Function)
  1064. */
  1065. @Override
  1066. public Instruction visitStructureInit(StructureInit structureInit, Integer arg1) {
  1067. for (Expression elem : structureInit.getElements()) {
  1068. elem.accept(this, null);
  1069. }
  1070. return null;
  1071. }
  1072.  
  1073. /*
  1074. * (non-Javadoc)
  1075. *
  1076. * @see
  1077. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitStringValue(mavlc.ast.nodes.
  1078. * expression.StringValue, java.lang.Function)
  1079. */
  1080. @Override
  1081. public Instruction visitStringValue(StringValue stringValue, Integer arg1) {
  1082. assembler.loadStringValue(stringValue.getValue());
  1083. return null;
  1084. }
  1085.  
  1086. /*
  1087. * (non-Javadoc)
  1088. *
  1089. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitBoolValue(mavlc.ast.nodes.
  1090. * expression.BoolValue, java.lang.Function)
  1091. */
  1092. @Override
  1093. public Instruction visitBoolValue(BoolValue boolValue, Integer arg1) {
  1094. assembler.loadBooleanValue(boolValue.getValue());
  1095. return null;
  1096. }
  1097.  
  1098. /*
  1099. * (non-Javadoc)
  1100. *
  1101. * @see mavlc.ast.visitor.ASTNodeBaseVisitor#visitIntValue(mavlc.ast.nodes.
  1102. * expression.IntValue, java.lang.Function)
  1103. */
  1104. @Override
  1105. public Instruction visitIntValue(IntValue intValue, Integer arg1) {
  1106. assembler.loadIntegerValue(intValue.getValue());
  1107. return null;
  1108. }
  1109.  
  1110. /*
  1111. * (non-Javadoc)
  1112. *
  1113. * @see
  1114. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitFloatValue(mavlc.ast.nodes.
  1115. * expression.FloatValue, java.lang.Function)
  1116. */
  1117. @Override
  1118. public Instruction visitFloatValue(FloatValue floatValue, Integer arg1) {
  1119. assembler.loadFloatValue(floatValue.getValue());
  1120. return null;
  1121. }
  1122.  
  1123. /*
  1124. * (non-Javadoc)
  1125. *
  1126. * @see
  1127. * mavlc.ast.visitor.ASTNodeBaseVisitor#visitIdentifierReference(mavlc.ast.
  1128. * nodes.expression.IdentifierReference, java.lang.Function)
  1129. */
  1130. @Override
  1131. public Instruction visitIdentifierReference(IdentifierReference identifierReference, Integer arg1) {
  1132. Declaration decl = identifierReference.getDeclaration();
  1133. int wordSize = decl.getType().wordSize();
  1134. int offset = decl.getLocalBaseOffset();
  1135. assembler.loadLocalValue(wordSize, offset);
  1136. return null;
  1137. }
  1138.  
  1139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement