2
0

AsmCodeSets.cp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. (*
  2. * Code sets for ASM, to check for membership of
  3. * particular forbidden or permitted bytecode values.
  4. *)
  5. MODULE AsmCodeSets;
  6. IMPORT Jvm := JVMcodes;
  7. TYPE ByteBitSet = ARRAY 8 OF SET;
  8. VAR forbidden : ByteBitSet; (* bytecodes not allowed by ASM5 *)
  9. VAR deltaSpecial : ByteBitSet; (* bytecodes with variable delta *)
  10. (* ============================================================ *)
  11. (* Handling of byte code bit maps *)
  12. (* ============================================================ *)
  13. PROCEDURE Insert( VAR set : ByteBitSet; val : INTEGER );
  14. BEGIN
  15. IF (val < 0) OR (val > 255) THEN
  16. THROW( "Illegal insert in bit set - " );
  17. END;
  18. INCL(set[val DIV 32], val MOD 32);
  19. END Insert;
  20. (* -------------------- *)
  21. PROCEDURE badCode*( code : INTEGER ) : BOOLEAN;
  22. BEGIN
  23. RETURN (code MOD 32) IN forbidden[code DIV 32];
  24. END badCode;
  25. (* -------------------- *)
  26. PROCEDURE badFix*( code : INTEGER ) : BOOLEAN;
  27. BEGIN
  28. RETURN (code MOD 32) IN deltaSpecial[code DIV 32];
  29. END badFix;
  30. (* -------------------- *)
  31. PROCEDURE isOk*( code : INTEGER ) : INTEGER;
  32. BEGIN
  33. IF (code MOD 32) IN forbidden[code DIV 32] THEN
  34. THROW( "Illegal code called - " + Jvm.op[code] );
  35. (* Permissive variant *)
  36. (* Hlp.Msg( "Illegal code called - " + Jvm.op[code] ); *)
  37. END;
  38. RETURN code;
  39. END isOk;
  40. (* ============================================================ *)
  41. (* Initialization of module globals *)
  42. (* ============================================================ *)
  43. BEGIN
  44. (* -------------------------------------------- *)
  45. (* Initialize forbidden code set *)
  46. (* -------------------------------------------- *)
  47. Insert( deltaSpecial, Jvm.opc_getstatic );
  48. Insert( deltaSpecial, Jvm.opc_putstatic );
  49. Insert( deltaSpecial, Jvm.opc_getfield );
  50. Insert( deltaSpecial, Jvm.opc_putfield );
  51. Insert( deltaSpecial, Jvm.opc_invokevirtual );
  52. Insert( deltaSpecial, Jvm.opc_invokespecial );
  53. Insert( deltaSpecial, Jvm.opc_invokestatic);
  54. Insert( deltaSpecial, Jvm.opc_invokeinterface );
  55. Insert( deltaSpecial, Jvm.opc_multianewarray );
  56. (* -------------------------------------------- *)
  57. (* Initialize forbidden code set *)
  58. (* -------------------------------------------- *)
  59. Insert( forbidden, Jvm.opc_iload_0 );
  60. Insert( forbidden, Jvm.opc_iload_1 );
  61. Insert( forbidden, Jvm.opc_iload_2 );
  62. Insert( forbidden, Jvm.opc_iload_3 );
  63. Insert( forbidden, Jvm.opc_aload_0 );
  64. Insert( forbidden, Jvm.opc_aload_1 );
  65. Insert( forbidden, Jvm.opc_aload_2 );
  66. Insert( forbidden, Jvm.opc_aload_3 );
  67. Insert( forbidden, Jvm.opc_lload_0 );
  68. Insert( forbidden, Jvm.opc_lload_1 );
  69. Insert( forbidden, Jvm.opc_lload_2 );
  70. Insert( forbidden, Jvm.opc_lload_3 );
  71. Insert( forbidden, Jvm.opc_fload_0 );
  72. Insert( forbidden, Jvm.opc_fload_1 );
  73. Insert( forbidden, Jvm.opc_fload_2 );
  74. Insert( forbidden, Jvm.opc_fload_3 );
  75. Insert( forbidden, Jvm.opc_dload_0 );
  76. Insert( forbidden, Jvm.opc_dload_1 );
  77. Insert( forbidden, Jvm.opc_dload_2 );
  78. Insert( forbidden, Jvm.opc_dload_3 );
  79. Insert( forbidden, Jvm.opc_istore_0 );
  80. Insert( forbidden, Jvm.opc_istore_1 );
  81. Insert( forbidden, Jvm.opc_istore_2 );
  82. Insert( forbidden, Jvm.opc_istore_3 );
  83. Insert( forbidden, Jvm.opc_astore_0 );
  84. Insert( forbidden, Jvm.opc_astore_1 );
  85. Insert( forbidden, Jvm.opc_astore_2 );
  86. Insert( forbidden, Jvm.opc_astore_3 );
  87. Insert( forbidden, Jvm.opc_lstore_0 );
  88. Insert( forbidden, Jvm.opc_lstore_1 );
  89. Insert( forbidden, Jvm.opc_lstore_2 );
  90. Insert( forbidden, Jvm.opc_lstore_3 );
  91. Insert( forbidden, Jvm.opc_fstore_0 );
  92. Insert( forbidden, Jvm.opc_fstore_1 );
  93. Insert( forbidden, Jvm.opc_fstore_2 );
  94. Insert( forbidden, Jvm.opc_fstore_3 );
  95. Insert( forbidden, Jvm.opc_dstore_0 );
  96. Insert( forbidden, Jvm.opc_dstore_1 );
  97. Insert( forbidden, Jvm.opc_dstore_2 );
  98. Insert( forbidden, Jvm.opc_dstore_3 );
  99. (* ------------------------------------ *)
  100. END AsmCodeSets.
  101. (* ============================================================ *)