Added machine plugin project to repository
authorChristian Femers <femers@in.tum.de>
Sun, 18 Aug 2019 12:33:12 +0000 (14:33 +0200)
committerChristian Femers <femers@in.tum.de>
Sun, 18 Aug 2019 12:43:17 +0000 (14:43 +0200)
29 files changed:
net.mograsim.machine/.classpath [new file with mode: 0644]
net.mograsim.machine/.gitignore [new file with mode: 0644]
net.mograsim.machine/.project [new file with mode: 0644]
net.mograsim.machine/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
net.mograsim.machine/META-INF/MANIFEST.MF [new file with mode: 0644]
net.mograsim.machine/build.properties [new file with mode: 0644]
net.mograsim.machine/plugin.xml [new file with mode: 0644]
net.mograsim.machine/schema/net.mograsim.machinedefinition.exsd [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/AddressingScema.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/ISA.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/ISASchema.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/Machine.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/MachineDefinition.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/MainMemory.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/MainMemoryDefinition.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/MicroInstruction.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/Register.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/AsmElement.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/AsmFloatOperand.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/AsmInstruction.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/AsmIntegerOperand.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/AsmLabel.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperand.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperands.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperation.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/NumericOperand.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/types/AsmException.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/isa/types/AsmNumberFormatException.java [new file with mode: 0644]

diff --git a/net.mograsim.machine/.classpath b/net.mograsim.machine/.classpath
new file mode 100644 (file)
index 0000000..e801ebf
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/net.mograsim.machine/.gitignore b/net.mograsim.machine/.gitignore
new file mode 100644 (file)
index 0000000..ae3c172
--- /dev/null
@@ -0,0 +1 @@
+/bin/
diff --git a/net.mograsim.machine/.project b/net.mograsim.machine/.project
new file mode 100644 (file)
index 0000000..d179b4c
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>net.mograsim.machine</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/net.mograsim.machine/.settings/org.eclipse.jdt.core.prefs b/net.mograsim.machine/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..cd95f14
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
+org.eclipse.jdt.core.compiler.compliance=11
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=11
diff --git a/net.mograsim.machine/META-INF/MANIFEST.MF b/net.mograsim.machine/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..3be14f8
--- /dev/null
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Mograsim Machine Definition
+Bundle-SymbolicName: net.mograsim.machine;singleton:=true
+Bundle-Version: 0.1.0.qualifier
+Bundle-Vendor: Mograsim Team
+Automatic-Module-Name: net.mograsim.machine
+Bundle-RequiredExecutionEnvironment: JavaSE-11
+Require-Bundle: net.mograsim.logic.core;bundle-version="0.1.0",
+ net.mograsim.logic.model;bundle-version="0.1.0"
+Export-Package: net.mograsim.machine.isa
diff --git a/net.mograsim.machine/build.properties b/net.mograsim.machine/build.properties
new file mode 100644 (file)
index 0000000..e9863e2
--- /dev/null
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml
diff --git a/net.mograsim.machine/plugin.xml b/net.mograsim.machine/plugin.xml
new file mode 100644 (file)
index 0000000..4171a8d
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension-point id="net.mograsim.machinedefinition" name="Mograsim Machine Definition" schema="schema/net.mograsim.machinedefinition.exsd"/>
+
+</plugin>
diff --git a/net.mograsim.machine/schema/net.mograsim.machinedefinition.exsd b/net.mograsim.machine/schema/net.mograsim.machinedefinition.exsd
new file mode 100644 (file)
index 0000000..ea6d258
--- /dev/null
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="net.mograsim.machine" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="net.mograsim.machine" id="net.mograsim.machinedefinition" name="Mograsim Machine Definition"/>
+      </appinfo>
+      <documentation>
+         Mograsim extension for defining a machine
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <choice minOccurs="1" maxOccurs="unbounded">
+            <element ref="MachineDefinitionImplementation"/>
+         </choice>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="MachineDefinitionImplementation">
+      <complexType>
+         <attribute name="name" type="string" use="required">
+            <annotation>
+               <documentation>
+                  The machines name
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  A Class that implements the Mograsim Machine Definition
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn=":net.mograsim.machine.MachineDefinition"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         0.1.0
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+
+</schema>
diff --git a/net.mograsim.machine/src/net/mograsim/machine/AddressingScema.java b/net.mograsim.machine/src/net/mograsim/machine/AddressingScema.java
new file mode 100644 (file)
index 0000000..884fa0b
--- /dev/null
@@ -0,0 +1,5 @@
+package net.mograsim.machine;
+
+public interface AddressingScema {
+       
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/ISA.java b/net.mograsim.machine/src/net/mograsim/machine/ISA.java
new file mode 100644 (file)
index 0000000..9f322e4
--- /dev/null
@@ -0,0 +1,4 @@
+package net.mograsim.machine;
+
+public interface ISA {
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/ISASchema.java b/net.mograsim.machine/src/net/mograsim/machine/ISASchema.java
new file mode 100644 (file)
index 0000000..249a892
--- /dev/null
@@ -0,0 +1,11 @@
+package net.mograsim.machine;
+
+import java.util.Set;
+
+import net.mograsim.machine.isa.AsmOperand;
+
+public interface ISASchema {
+       Set<AsmOperand> getSupportedOperands();
+       
+       AddressingScema getAddressingSchema();
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/Machine.java b/net.mograsim.machine/src/net/mograsim/machine/Machine.java
new file mode 100644 (file)
index 0000000..00a1e34
--- /dev/null
@@ -0,0 +1,19 @@
+package net.mograsim.machine;
+
+import net.mograsim.logic.core.components.Clock;
+import net.mograsim.logic.core.types.BitVector;
+import net.mograsim.logic.model.model.ViewModel;
+
+public interface Machine {
+       MachineDefinition getDefinition();
+       
+       void reset();
+       
+       ViewModel getModel();
+       
+       Clock getClock();
+       
+       BitVector getRegister(Register r);
+       
+       void setRegister(Register r, BitVector value);
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/MachineDefinition.java b/net.mograsim.machine/src/net/mograsim/machine/MachineDefinition.java
new file mode 100644 (file)
index 0000000..cfed1ef
--- /dev/null
@@ -0,0 +1,50 @@
+package net.mograsim.machine;
+
+import java.util.Set;
+
+public interface MachineDefinition {
+
+       /**
+        * Creates a new instance of the machine
+        * 
+        * @return a new object of an {@link Machine} implementation.
+        * @author Christian Femers
+        */
+       Machine createNew();
+
+       /**
+        * Returns the schema that all possible ISAs (Instruction Set Architecture) must
+        * be based on.
+        * 
+        * @return an {@link ISASchema} implementation fitting the machine
+        * @author Christian Femers
+        */
+       ISASchema getISASchema();
+
+       /**
+        * Returns a set of all {@link Register}s present in the machine.
+        * 
+        * @return all registers present in the machine.
+        * @author Christian Femers
+        */
+       Set<Register> getRegisters();
+
+       /**
+        * The number of bits used by the machine to address main memory. Note that this
+        * should be the number of bits used in the CPU, not a possibly different one
+        * used by the bus system.
+        * 
+        * @return the number of bits used by the CPU
+        * @see MainMemoryDefinition#getMemoryAddressBits()
+        * @author Christian Femers
+        */
+       int getAddressBits();
+
+       /**
+        * Returns the definition of the machines main memory.
+        * 
+        * @return the {@link MainMemoryDefinition} that defines the main memory.
+        * @author Christian Femers
+        */
+       MainMemoryDefinition getMainMemoryDefinition();
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java b/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java
new file mode 100644 (file)
index 0000000..78c0ca0
--- /dev/null
@@ -0,0 +1,5 @@
+package net.mograsim.machine;
+
+public interface MainMemory {
+       
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/MainMemoryDefinition.java b/net.mograsim.machine/src/net/mograsim/machine/MainMemoryDefinition.java
new file mode 100644 (file)
index 0000000..3128cdd
--- /dev/null
@@ -0,0 +1,45 @@
+package net.mograsim.machine;
+
+/**
+ * This interface provides a means to get information about the machines memory
+ * architecture. It is not bound to any actual memory.
+ *
+ * @author Christian Femers
+ *
+ */
+public interface MainMemoryDefinition {
+
+       /**
+        * The number of bits that the main memory uses to address cells. Note that this
+        * does not need to equal {@link MachineDefinition#getAddressBits()}.
+        * 
+        * @return the number of bits used to address a memory cell
+        * @author Christian Femers
+        */
+       int getMemoryAddressBits();
+
+       /**
+        * The width in bits of an addressable memory cell/unit. This is often 8 (= one
+        * byte). The actual cells/lines of the memory may be a lot larger.
+        * 
+        * @return the addressable unit width in bits
+        * @author Christian Femers
+        */
+       int getCellWidth();
+
+       /**
+        * The minimal address possible to address/use. This is usually 0.
+        * 
+        * @return the minimal possible address.
+        * @author Christian Femers
+        */
+       long getMinimalAddress();
+
+       /**
+        * The maximal address possible to address/use.
+        * 
+        * @return the maximal possible address as <b>unsigned long</b>
+        * @author Christian Femers
+        */
+       long getMaximalAddress();
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/MicroInstruction.java b/net.mograsim.machine/src/net/mograsim/machine/MicroInstruction.java
new file mode 100644 (file)
index 0000000..0846cd5
--- /dev/null
@@ -0,0 +1,5 @@
+package net.mograsim.machine;
+
+public interface MicroInstruction {
+
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java b/net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java
new file mode 100644 (file)
index 0000000..c12d676
--- /dev/null
@@ -0,0 +1,5 @@
+package net.mograsim.machine;
+
+public interface MicroprogramMemory {
+
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/Register.java b/net.mograsim.machine/src/net/mograsim/machine/Register.java
new file mode 100644 (file)
index 0000000..5ecf1cf
--- /dev/null
@@ -0,0 +1,58 @@
+package net.mograsim.machine;
+
+import java.util.Set;
+
+/**
+ * A register in a machine is defined by this interface. A hardware register may
+ * have {@link Register#names() named sub-registers}.
+ *
+ *
+ * @author Christian Femers
+ *
+ */
+public interface Register {
+       /**
+        * The unique identifier of the register. This does not have to be the display
+        * name or name in the assembly language.
+        * 
+        * @return the registers id as case sensitive String
+        * @author Christian Femers
+        */
+       String id();
+
+       /**
+        * The name(s) of this register. This is the displayed name and the name used in
+        * the assembly language. All names of all registers must be case-insensitive
+        * unique. A register can have multiple names if these names address different
+        * regions (but still have a common hardware structure), e.g. <code>EAX</code>,
+        * <code>AX</code>, <code>AL</code>, <code>AH</code>.
+        * 
+        * @return all the names of regions addressing this register, must be
+        *         case-insensitive.
+        * @author Christian Femers
+        */
+       Set<String> names();
+
+       /**
+        * Returns the complete width in bits of the underlying hardware structure the
+        * register and possible sub-registers are part of.
+        * 
+        * @param name the name of the register
+        * @return the width of the (sub-)register in bits.
+        * 
+        * @see #names()
+        * @author Christian Femers
+        */
+       int getWidth();
+
+       /**
+        * Returns the width in bits of the register or a named part of it.
+        * 
+        * @param name the name of the register
+        * @return the width of the (sub-)register in bits.
+        * 
+        * @see #names()
+        * @author Christian Femers
+        */
+       int getWidth(String name);
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmElement.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmElement.java
new file mode 100644 (file)
index 0000000..07b56c2
--- /dev/null
@@ -0,0 +1,6 @@
+package net.mograsim.machine.isa;
+
+public interface AsmElement
+{
+       // only marker at the moment
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmFloatOperand.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmFloatOperand.java
new file mode 100644 (file)
index 0000000..7a1a6eb
--- /dev/null
@@ -0,0 +1,98 @@
+package net.mograsim.machine.isa;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
+import net.mograsim.logic.core.types.BitVector.BitVectorMutator;
+import net.mograsim.machine.isa.types.AsmNumberFormatException;
+
+public class AsmFloatOperand implements AsmOperand
+{
+       private final int size;
+       private final int mantissa;
+       private final int exponent;
+
+       public AsmFloatOperand(int size)
+       {
+               this.size = size;
+               switch (size)
+               {
+               case 8:
+                       exponent = 4;
+                       mantissa = 3;
+                       break;
+               case 16:
+                       exponent = 5;
+                       mantissa = 10;
+                       break;
+               case 32:
+                       exponent = 8;
+                       mantissa = 23;
+                       break;
+               case 64:
+                       exponent = 11;
+                       mantissa = 52;
+                       break;
+               case 128:
+                       exponent = 15;
+                       mantissa = 112;
+                       break;
+               default:
+                       if (size > 128 && size % 32 == 0)
+                       {
+                               exponent = (int) Math.round(Math.log(size) / Math.log(2)) - 13;
+                               mantissa = size - exponent - 1;
+                       } else
+                       {
+                               throw new IllegalArgumentException("Illegal floating point size: " + size);
+                       }
+               }
+       }
+
+       public AsmFloatOperand(int exponent, int mantissa)
+       {
+               if (exponent < 1 || mantissa < 1)
+                       throw new IllegalArgumentException("illegal floating point specification: e=" + exponent + ", m=" + mantissa);
+               this.exponent = exponent;
+               this.mantissa = mantissa;
+               this.size = exponent + mantissa + 1;
+       }
+
+       @Override
+       public int getSize()
+       {
+               return size;
+       }
+
+       @Override
+       public BitVector parse(String s) throws AsmNumberFormatException
+       {
+               String cleaned = s.replace("_", "").toLowerCase();
+               int len = cleaned.length();
+               BigInteger res;
+               try
+               {
+                       return bigDecToBitVector(new BigDecimal(cleaned));
+               }
+               catch (NumberFormatException e)
+               {
+                       throw new AsmNumberFormatException(e, "Error parsing %s: no valid float format", s);
+               }
+       }
+
+       BitVector bigDecToBitVector(BigDecimal bi) throws AsmNumberFormatException
+       {
+               BigInteger raw = bi.unscaledValue();
+               int mantLen = raw.bitLength();
+//             bi.
+               int bitLength = raw.bitLength() - (bi.signum() - 1) / 2;
+               if (bitLength > size)
+                       throw new AsmNumberFormatException("Error parsing %s: bit count %d exceeds size %d", bi, bitLength, size);
+               BitVectorMutator bvm = BitVectorMutator.ofLength(size);
+               for (int i = 0; i < size; i++)
+                       bvm.setLSBit(i, Bit.of(raw.testBit(i)));
+               return bvm.toBitVector();
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmInstruction.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmInstruction.java
new file mode 100644 (file)
index 0000000..29bbf73
--- /dev/null
@@ -0,0 +1,39 @@
+package net.mograsim.machine.isa;
+
+import java.util.Objects;
+
+public final class AsmInstruction implements AsmElement
+{
+       private final AsmOperation operation;
+       private final AsmOperands operands;
+
+       public AsmInstruction(AsmOperation operation, AsmOperands operands)
+       {
+               this.operation = Objects.requireNonNull(operation);
+               this.operands = Objects.requireNonNull(operands);
+       }
+
+       @Override
+       public int hashCode()
+       {
+               return Objects.hash(operands, operation);
+       }
+
+       @Override
+       public boolean equals(Object obj)
+       {
+               if (this == obj)
+                       return true;
+               if (!(obj instanceof AsmInstruction))
+                       return false;
+               AsmInstruction other = (AsmInstruction) obj;
+               return Objects.equals(operands, other.operands) && Objects.equals(operation, other.operation);
+       }
+
+       @Override
+       public String toString()
+       {
+               return String.format("%s %s", operation, operands).trim();
+       }
+
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmIntegerOperand.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmIntegerOperand.java
new file mode 100644 (file)
index 0000000..d3ac80f
--- /dev/null
@@ -0,0 +1,95 @@
+package net.mograsim.machine.isa;
+
+import java.math.BigInteger;
+
+import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
+import net.mograsim.logic.core.types.BitVector.BitVectorMutator;
+import net.mograsim.machine.isa.types.AsmNumberFormatException;
+
+public class AsmIntegerOperand implements AsmOperand
+{
+       private final int size;
+
+       public AsmIntegerOperand(int size)
+       {
+               this.size = size;
+       }
+
+       @Override
+       public int getSize()
+       {
+               return size;
+       }
+
+       @Override
+       public BitVector parse(String s) throws AsmNumberFormatException
+       {
+               String cleaned = s.replace("_", "").toLowerCase();
+               int len = cleaned.length();
+               BigInteger res;
+               try
+               {
+                       if (cleaned.startsWith("0x"))
+                               res = new BigInteger(cleaned.substring(2), 16);
+                       else if (cleaned.endsWith("h"))
+                               res = new BigInteger(cleaned.substring(0, len - 1), 16);
+                       else if (cleaned.startsWith("0b"))
+                               res = new BigInteger(cleaned.substring(2), 2);
+                       else if (cleaned.endsWith("b"))
+                               res = new BigInteger(cleaned.substring(2), 2);
+                       else if (cleaned.endsWith("q"))
+                               res = new BigInteger(cleaned.substring(0, len - 1), 8);
+                       else
+                               res = new BigInteger(cleaned);
+               }
+               catch (NumberFormatException e)
+               {
+                       throw new AsmNumberFormatException(e, "Error parsing %s: no valid integer format", s);
+               }
+               return bigIntToBitVector(res);
+       }
+
+       BitVector bigIntToBitVector(BigInteger bi) throws AsmNumberFormatException
+       {
+               int bitLength = bi.bitLength() - (bi.signum() - 1) / 2;
+               if (bitLength > size)
+                       throw new AsmNumberFormatException("Error parsing %s: bit count %d exceeds size %d", bi, bitLength, size);
+               BitVectorMutator bvm = BitVectorMutator.ofLength(size);
+               for (int i = 0; i < size; i++)
+                       bvm.setLSBit(i, Bit.of(bi.testBit(i)));
+               return bvm.toBitVector();
+       }
+
+       public static void main(String[] args) throws AsmNumberFormatException
+       {
+               AsmIntegerOperand aio = new AsmIntegerOperand(4);
+               System.out.println(aio.parse("0"));
+               System.out.println(aio.parse("1"));
+               System.out.println(aio.parse("2"));
+               System.out.println(aio.parse("3"));
+               System.out.println(aio.parse("4"));
+               System.out.println(aio.parse("5"));
+               System.out.println(aio.parse("6"));
+               System.out.println(aio.parse("7"));
+               System.out.println(aio.parse("8"));
+               System.out.println(aio.parse("9"));
+               System.out.println(aio.parse("10"));
+               System.out.println(aio.parse("11"));
+               System.out.println(aio.parse("12"));
+               System.out.println(aio.parse("13"));
+               System.out.println(aio.parse("14"));
+               System.out.println(aio.parse("15"));
+//             System.out.println(aio.parse("16"));
+               System.out.println(aio.parse("-0"));
+               System.out.println(aio.parse("-1"));
+               System.out.println(aio.parse("-2"));
+               System.out.println(aio.parse("-3"));
+               System.out.println(aio.parse("-4"));
+               System.out.println(aio.parse("-5"));
+               System.out.println(aio.parse("-6"));
+               System.out.println(aio.parse("-7"));
+               System.out.println(aio.parse("-8"));
+//             System.out.println(aio.parse("-9"));
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmLabel.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmLabel.java
new file mode 100644 (file)
index 0000000..ddb5658
--- /dev/null
@@ -0,0 +1,49 @@
+package net.mograsim.machine.isa;
+
+import java.util.Objects;
+
+public final class AsmLabel implements AsmElement
+{
+       private final String name;
+       private AsmInstruction inst;
+
+       public AsmLabel(String name)
+       {
+               this.name = Objects.requireNonNull(name);
+       }
+
+       public String getName()
+       {
+               return name;
+       }
+
+       public void setInst(AsmInstruction inst)
+       {
+               if (inst != null)
+                       throw new IllegalStateException("Instrution already set for " + name);
+               this.inst = inst;
+       }
+
+       @Override
+       public String toString()
+       {
+               return name + ":";
+       }
+
+       @Override
+       public int hashCode()
+       {
+               return Objects.hash(inst, name);
+       }
+
+       @Override
+       public boolean equals(Object obj)
+       {
+               if (this == obj)
+                       return true;
+               if (!(obj instanceof AsmLabel))
+                       return false;
+               AsmLabel other = (AsmLabel) obj;
+               return Objects.equals(inst, other.inst) && Objects.equals(name, other.name);
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperand.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperand.java
new file mode 100644 (file)
index 0000000..ad641d6
--- /dev/null
@@ -0,0 +1,11 @@
+package net.mograsim.machine.isa;
+
+import net.mograsim.logic.core.types.BitVector;
+import net.mograsim.machine.isa.types.AsmException;
+
+public interface AsmOperand
+{
+       int getSize();
+
+       BitVector parse(String s) throws AsmException;
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperands.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperands.java
new file mode 100644 (file)
index 0000000..f286c31
--- /dev/null
@@ -0,0 +1,43 @@
+package net.mograsim.machine.isa;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public final class AsmOperands
+{
+       private final List<AsmOperand> operands;
+
+       public AsmOperands(List<AsmOperand> operands)
+       {
+               this.operands = List.copyOf(Objects.requireNonNull(operands));
+       }
+
+       public List<AsmOperand> getOperands()
+       {
+               return operands;
+       }
+
+       @Override
+       public int hashCode()
+       {
+               return operands.hashCode();
+       }
+
+       @Override
+       public boolean equals(Object obj)
+       {
+               if (this == obj)
+                       return true;
+               if (!(obj instanceof AsmOperands))
+                       return false;
+               AsmOperands other = (AsmOperands) obj;
+               return operands.equals(other.operands);
+       }
+
+       @Override
+       public String toString()
+       {
+               return operands.stream().map(AsmOperand::toString).collect(Collectors.joining(", "));
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperation.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmOperation.java
new file mode 100644 (file)
index 0000000..abafc45
--- /dev/null
@@ -0,0 +1,41 @@
+package net.mograsim.machine.isa;
+
+import java.util.Objects;
+
+public final class AsmOperation
+{
+       private final String mnemonic;
+
+       public AsmOperation(String mnemonic)
+       {
+               this.mnemonic = Objects.requireNonNull(mnemonic.toLowerCase());
+       }
+
+       public String getMnemonic()
+       {
+               return mnemonic;
+       }
+
+       @Override
+       public String toString()
+       {
+               return getMnemonic();
+       }
+
+       @Override
+       public int hashCode()
+       {
+               return mnemonic.hashCode();
+       }
+
+       @Override
+       public boolean equals(Object obj)
+       {
+               if (this == obj)
+                       return true;
+               if (!(obj instanceof AsmOperation))
+                       return false;
+               AsmOperation other = (AsmOperation) obj;
+               return mnemonic.equals(other.mnemonic);
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/NumericOperand.java b/net.mograsim.machine/src/net/mograsim/machine/isa/NumericOperand.java
new file mode 100644 (file)
index 0000000..8de6626
--- /dev/null
@@ -0,0 +1,6 @@
+package net.mograsim.machine.isa;
+
+public class NumericOperand
+{
+
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/types/AsmException.java b/net.mograsim.machine/src/net/mograsim/machine/isa/types/AsmException.java
new file mode 100644 (file)
index 0000000..8a9d2d0
--- /dev/null
@@ -0,0 +1,32 @@
+package net.mograsim.machine.isa.types;
+
+public class AsmException extends Exception
+{
+       private static final long serialVersionUID = 1L;
+
+       public AsmException()
+       {
+               super();
+       }
+
+       public AsmException(Throwable cause, String message, boolean enableSuppression, boolean writableStackTrace)
+       {
+               super(message, cause, enableSuppression, writableStackTrace);
+       }
+
+       public AsmException(Throwable cause, String formatString, Object... formatArgs)
+       {
+               super(String.format(formatString, formatArgs), cause);
+       }
+
+       public AsmException(String formatString, Object... formatArgs)
+       {
+               super(String.format(formatString, formatArgs));
+       }
+
+       public AsmException(Throwable cause)
+       {
+               super(cause);
+       }
+
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/types/AsmNumberFormatException.java b/net.mograsim.machine/src/net/mograsim/machine/isa/types/AsmNumberFormatException.java
new file mode 100644 (file)
index 0000000..4fb4af6
--- /dev/null
@@ -0,0 +1,16 @@
+package net.mograsim.machine.isa.types;
+
+public class AsmNumberFormatException extends AsmException
+{
+       private static final long serialVersionUID = 1L;
+
+       public AsmNumberFormatException(Exception cause, String message, Object... formatArgs)
+       {
+               super(cause, message, formatArgs);
+       }
+
+       public AsmNumberFormatException(String message, Object... formatArgs)
+       {
+               super(message, formatArgs);
+       }
+}