⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 llvm.g

📁 一种将c高级语言转化给VHDL的编译器
💻 G
📖 第 1 页 / 共 4 页
字号:
	    }	  } 	  | TRUE	  {	    tok = LT(0);	    o =  new Boolean(true);	  }	  | FALSE	  {	    tok = LT(0);	    o =  new Boolean(false);	  }	  | HEX_FPCONSTANT 	  { 	    tok = LT(0); 	    s = tok.getText();	    s = s.substring(2, s.length());	    //System.err.println("FPConstant: " + s);	    if (s.length() <= Convert.ieeeFloatHexStringLength) {	      if (t == Type.Float) {		float f = Convert.ieeeFloatHexStringToFloat(s);		o = new Float(f); 	      } else if (t == Type.Double) {		double d = Convert.ieeeDoubleHexStringToDouble(s);		o = new Double(d); 	      }	    } else if (s.length() <= Convert.ieeeDoubleHexStringLength) {		if (t == Type.Double) {		  double d = Convert.ieeeDoubleHexStringToDouble(s);		  o = new Double(d); 		} else if (t == Type.Float) {		  float f = Convert.ieeeDoubleHexStringToFloat(s);		  o = new Float(f); 		} 	    } 	  }	  | (LBRACE  	  {	    len = ((ArrayType)t).getLen();	    eltType = ((ArrayType)t).getType();	  }	  iv=initialValue[eltType] 	  {	    if (iv == null) {	      // If it returned null, that means that the initial value of the inner 	      // arrays is supposed to be initialized to zero	      //System.out.println("Initialize array to zero!");	      // sorry this is painful...	      // First, make a list of the dimensions of the array              ll = new LinkedList();	      ll.addLast(new Integer(len));	      while (eltType.isArray()) {		ll.addLast(new Integer(((ArrayType)eltType).getLen()));		eltType = ((ArrayType)eltType).getType();	      }              //System.out.println("Linked List is: " + ll.toString());              //System.out.println("EltType is: " + eltType.toString());	      // Second, convert the dimensions (list of Integer's) to an array of ints	      dims = Array.newInstance(int.class, ll.size());	      for(ListIterator iter = ll.listIterator(); iter.hasNext(); ) {		nextInt = (Integer)iter.next();	        Array.setInt(dims, dim++, nextInt.intValue());	      }	      	      // Third, figure out the components of the array	      if ((eltType == Type.Long) || (eltType == Type.Ulong)) {	        cls = long.class; 	      } else if ((eltType == Type.Int) || (eltType == Type.Uint)) {	        cls = int.class;	      } else if (eltType == Type.Float) {	        cls = float.class;	      } else  if (eltType == Type.Double) {	        cls = double.class;	      } else if (eltType == Type.Bool) {		cls = boolean.class;	      }              System.out.println("Class of Array is: " + cls.toString());	      // Finally create an array of those components using the dimension array	      array = Array.newInstance(cls, (int[])dims);	    } else {              // Here we create an array that will be initialized to specified values	      //System.out.println("elt initialValue: " + iv.toString());	      //System.out.println("class: " + iv.getClass().toString());	      //System.out.println("len: " + len);	      //System.out.println("Array.newInstance");	      if (iv instanceof Long) {	        array = Array.newInstance(long.class, len); 	        Array.setLong(array, index++, ((Long)iv).longValue());	      } else if (iv instanceof Integer) {	        array = Array.newInstance(int.class, len); 	        Array.setInt(array, index++, ((Integer)iv).intValue());	      } else if (iv instanceof Float) {	        array = Array.newInstance(float.class, len); 	        Array.setFloat(array, index++, ((Float)iv).floatValue());	      } else if (iv instanceof Double) {	        array = Array.newInstance(double.class, len); 	        Array.setDouble(array, index++, ((Double)iv).doubleValue());	      } else if (iv instanceof Boolean) {	        array = Array.newInstance(boolean.class, len); 	        Array.setBoolean(array, index++, ((Boolean)iv).booleanValue());	      } else if (iv.getClass().isArray()) {	        array = Array.newInstance(iv.getClass(), len); 	        Array.set(array, index++, iv);	      } else {	        System.out.println("Array element type is unknown!");                System.exit(-1);	      }	    }	  }	  (COMMA iv=initialValue[eltType]	  {	    if (iv instanceof Long) {	      Array.setLong(array, index++, ((Long)iv).longValue());	    } else if (iv instanceof Integer) {	      Array.setInt(array, index++, ((Integer)iv).intValue());	    } else if (iv instanceof Float) {	      Array.setFloat(array, index++, ((Float)iv).floatValue());	    } else if (iv instanceof Double) {	      Array.setDouble(array, index++, ((Double)iv).doubleValue());	    } else if (iv instanceof Boolean) {	      Array.setBoolean(array, index++, ((Boolean)iv).booleanValue());	    } else if (iv.getClass().isArray()) {	      Array.set(array, index++, iv);	    }  	  }	  )* RBRACE	  {	    o = array;	  }	  )	{	    //System.out.println("initialValue: " + o.toString());	};		function [BlockGraph blockGraph]	{	  Loop firstLoop = null;	  BlockNode firstBlock = null;	  BlockNode blockNode = null;          Loop lp = null;          Loop parentLoop = null;	}:	FUNCTION id:DECLVARID 	{          parentLoop = new Loop(id.getText(), Loop.ROOT);          blockGraph.setRootLoop(parentLoop);	}        eol! ((blockNode=block[parentLoop] 	{	  if (firstBlock == null) {	    firstBlock = blockNode;	    blockGraph.setFirstBlock(blockNode);	    if (firstLoop == null) {	      parentLoop.setLoopEntry(blockNode);	      //System.out.println("Loop entry block is: " + blockNode.getName());	    }	  }	  blockGraph.addNode(blockNode);	  parentLoop.addLoopNode(blockNode);	  //System.out.println("Added block node to loop tree: " + blockNode.getName());	}	)| (lp=loop[parentLoop, blockGraph]	{	  if ((firstBlock == null) && (firstLoop == null)) {	    firstLoop = lp;	    parentLoop.setLoopEntry(lp);	    //System.out.println("Loop entry loop is: " + lp.getName());	  }	  parentLoop.addLoopNode(lp);	  //System.out.println("Added loop to loop tree: " + lp.getName());	}	))* FUNCTION END DECLVARID eol! 	{	  try {	    PhiInfo.patch();	  } catch (IllegalOperand e) {	    System.err.println("Error patching phi instruction.");	    throw(e);	  }	  if (parentLoop != null) {	    //System.out.println("Loop tree: " + parentLoop.toString());	  }	};block [Loop parentLoop] returns [BlockNode blockNode]	{	  blockNode = null;	  Instruction inst = null;	  Varid v = null;	  LinkedList iList = null;	}:	BLOCK v=varid	{	  blockNode = new BlockNode();	  if (v.isVersioned()) {	    blockNode.setName(v.getBasename(), v.getVersion());	  } else {	    blockNode.setName(v.getBasename());	  }	  //System.out.println("Processing block node: " + v.getBasename());	  blockNode.setLoopParent(parentLoop);	}	eol! (iList=instruction 	{	  for(ListIterator iter = iList.listIterator(); iter.hasNext(); ) {	    inst = (Instruction)iter.next();	    if (inst != null) {	      blockNode.addInstruction(inst);	    }	  }	})* BLOCK END VARID eol! 	{	};loop [Loop parent, BlockGraph blockGraph] returns [Loop lp]	{	  BlockNode blockNode = null;	  LoopNode entryNode = null;	  Loop childLoop = null;	  Loop firstLoop = null;	  lp = null;	}:	LOOP varid:VARID 	{	  lp = new Loop(varid.getText(), Loop.NORMAL);	  //System.out.println("Processing loop: " + varid.getText());	}	eol! (blockNode=block[parent]	{	  blockGraph.addNode(blockNode);	  if ((entryNode == null) && (firstLoop == null)) {	    entryNode = blockNode;	    lp.setLoopEntry(entryNode);	    //System.out.println("Loop entry block is: " + blockNode.getName());	  }	  lp.addLoopNode(blockNode);	  //System.out.println("Added block node to loop tree: " + blockNode.getName());	}	| childLoop=loop[lp, blockGraph]	{	  if ((entryNode == null) && (firstLoop == null)) {	    firstLoop = childLoop;	    lp.setLoopEntry(childLoop);	    //System.out.println("Loop entry loop is: " + childLoop.getName());	  }	  lp.addLoopNode(childLoop);	  //System.out.println("Added loop to loop tree: " + childLoop.getName());	}	)* LOOP END varid2:VARID eol!	{	  lp.setLoopParent(parent);	};instruction returns [ LinkedList iList]  	{	  iList = null;	}:	(iList=loadI 	 | iList=storeI	 | iList=terminatorI	 | iList=binaryI	 | iList=bitwiseBinaryI	 | iList=shiftI	 | iList=setccI	 | iList = selectI	 | iList = getelementptrI	 | iList = phiI	 | iList = callI	 | iList = castI	 | iList = switchI) eol! 	{	};loadI returns [ LinkedList iList ] 	{	  iList = new LinkedList();	  Type t = null;	  Instruction inst = null;	  Operand resOperand = null;	  Operand srcOperand = null;	  Varid resVarid, srcVarid = null;	  String addrOpName = null;	  GepInfo gepInfo = null;	}:	(resVarid=varid EQUAL LOAD t=type 	{	  if (!t.isPointer()) {	    System.err.println("Error:  Pointer type required for load: " + t + " on line: " + LT(0).getLine());	    System.exit(-1);	  }	  try {	    if (((PointerType)t).getType() == Type.Bool) {	      if (resVarid.isVersioned()) {	        resOperand = Operand.newBoolean(resVarid.getBasename(), resVarid.getVersion());	      } else {	        resOperand = Operand.newBoolean(resVarid.getBasename());	      }	    } else {	      if (resVarid.isVersioned()) {	        resOperand = Operand.newBlock(resVarid.getBasename(), resVarid.getVersion());	      } else {	        resOperand = Operand.newBlock(resVarid.getBasename());	      }	    }	  } catch (IllegalOperand e) {	    System.err.println("Error creating result operand: " + resVarid.getBasename() + " on line: " + LT(0).getLine());	    throw(e);	  }	}	(srcVarid=varid	{	  try {	    // If it has been assigned as an addr operand as a result of a phi, 	    // obtain it this way.  But what if the phi comes after?	    srcOperand = Operand.getOperand(srcVarid.getBasename(), srcVarid.getVersion());	    // otherwise make a primal for it	    if (srcOperand == null) {	      srcOperand = Operand.newPrimal(LT(0).getText());	    }	  } catch (IllegalOperand e) {	    System.err.println("Error creating primal operand: " + LT(0).getText() + " on line: " + LT(0).getLine());	    throw(e);	  }	  if (srcOperand.isAddr()) {	    Operand primalOp = (Operand)GepInfo.addrOperandHashMap.get(srcOperand);	    if (primalOp == null) {	      System.err.println("Yipes, addrOperandHashMap doesn't have a primal");	      System.exit(-1);	    }	    inst = ALoad.create(Operators.ALOAD, t, resOperand, srcOperand, primalOp);	  } else {  	    inst = Load.create(Operators.LOAD, t, resOperand, srcOperand);	  }	  iList.addLast(inst);	}	| GETELEMENTPTR LPAREN gepInfo=getelementptrInfo RPAREN 	{    	  // make unique variable for source operand	  addrOpName = GepInfo.names.getUniqueName("%load_addr");	  try {	    srcOperand = Operand.newAddr(addrOpName);	  } catch (IllegalOperand e) {	    System.err.println("Error creating addr operand: " + addrOpName + " on line: " + LT(0).getLine());	    throw(e);	  }	  inst = Getelementptr.create(Operators.GETELEMENTPTR, srcOperand, gepInfo.type, gepInfo.operand, gepInfo.pairs);	  iList.addLast(inst);	  inst = ALoad.create(Operators.ALOAD, t, resOperand, srcOperand, gepInfo.operand);	  iList.addLast(inst);	}	))	{	};storeI returns [ LinkedList iList ] 	{	  iList = new LinkedList();	  Instruction inst = null;	  Type t, t1, t2 = null;	  Operand srcOperand, dstOperand = null;	  GepInfo gepInfo = null;	  String addrOpName = null;	  Varid dstVarid = null;	}:	(STORE t=type srcOperand=value[t, false] COMMA t2=type        {	  if (!t2.isPointer()) {	    System.err.println("Error:  Pointer type required for store: " + t2 + " on line: " + LT(0).getLine());	    System.exit(-1);	  }	  t1 = ((PointerType)t2).getType();	} 	(dstVarid=varid 	{	  if (t!= t1) {	    System.err.println("Error:  In store instruction, type of source operand must be the same as the pointer type of the destination on line: " + LT(0).getLine());	    System.exit(-1);	  }	  try {	    // If it has been assigned as an addr operand as a result of a phi, 	    // obtain it this way.  But what if the phi comes after?	    dstOperand = Operand.getOperand(dstVarid.getBasename(), dstVarid.getVersion());	    // otherwise make a primal for it	    if (dstOperand == null) {	      dstOperand = Operand.newPrimal(LT(0).getText());	    }	  } catch (IllegalOperand e) {	    System.err.println("Error creating primal operand: " + LT(0).getText() + " on line: " + LT(0).getLine());	    throw(e);	  }	  if (dstOperand.isAddr()) {	    Operand primalOp = (Operand)GepInfo.addrOperandHashMap.get(dstOperand);	    if (primalOp == null) {	      System.err.println("Yipes, addrOperandHashMap doesn't have a primal");	      System.exit(-1);	    }	    inst = AStore.create(Operators.ASTORE, t1, dstOperand, primalOp, srcOperand);	  } else {  	    inst = Store.create(Operators.STORE, t1, dstOperand, srcOperand);	  }	  iList.addLast(inst);	}	| GETELEMENTPTR LPAREN gepInfo=getelementptrInfo RPAREN	{	// make unique variable for destination operand	  addrOpName = GepInfo.names.getUniqueName("%store_addr");	  try {	    dstOperand = Operand.newAddr(addrOpName);	  } catch (IllegalOperand e) {	    System.err.println("Error creating addr operand: " + addrOpName + " on line: " + LT(0).getLine());	    throw(e);	  }	  inst = Getelementptr.create(Operators.GETELEMENTPTR, dstOperand, gepInfo.type, 	    gepInfo.operand, gepInfo.pairs);	  iList.addLast(inst);	  inst = AStore.create(Operators.ASTORE, t1, dstOperand, gepInfo.operand, srcOperand);	  iList.addLast(inst);	}	 ))	{	};terminatorI returns [ LinkedList iList ] 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -