Пример #1
0
Type *NewAggregateType(char *name, Member *members, int kind)
{
    Type *t;

    t = NewType(name, NULL, TYF_NONE, kind);
    t->u.agg.members = members;
    return t;
}
Пример #2
0
Type *NewArrayType(char *name, int len, Type *base)
{
    Type *t;

    t = NewType(name, base, TYF_NONE, TYK_ARRAY);
    t->u.array.len = len;
    return t;
}
Пример #3
0
Type *NewClassType(char *name, Member *members)
{
    Type *t;

    t = NewType(name, NULL, TYF_NONE, TYK_CLASS);
    t->u.agg.members = members;
    return t;
}
Пример #4
0
Type *NewStructType(char *name, Member *members)
{
    Type *t;

    t = NewType(name, NULL, TYF_NONE, TYK_STRUCT);
    t->u.agg.members = members;
    return t;
}
Пример #5
0
Type *NewUnionType(char *name, Member *members)
{
    Type *t;

    t = NewType(name, NULL, TYF_NONE, TYK_UNION);
    t->u.agg.members = members;
    return t;
}
Пример #6
0
Type *NewPackedArrayType(Type *elType, int numels, int properties)
{
    Type *lType;

    lType = NewType(TYPE_CATEGORY_ARRAY | TYPE_MISC_PACKED | properties | GetBase(elType), 0);
    lType->arr.eltype = elType;
    lType->arr.numels = numels;
    lType->arr.size = Cg->theHAL->GetSizeof(lType);
    return lType;
} // NewPakedArrayType
Пример #7
0
Type *NewPackedArrayType( CgContext *cg, Type *elType, int numels, int properties)
{
  Type *lType;
  
  lType = NewType( cg,elType->name, GetBase( elType ), TC_Array, TD_Unknown, TQ_None, elType->isConst, TYPE_MISC_PACKED | properties, 0);
	TypeArray *arrType = static_cast< TypeArray * >( lType );
  arrType->eltype = elType;
  arrType->numels = numels;
  arrType->size = cg->theHal->GetSizeof(lType);
  return lType;
} // NewPakedArrayType
Пример #8
0
Symbol *AddTag( CgContext *cg, SourceLoc *loc, Scope *fScope, Atom atom, TypeCategory category)
{
  Symbol *lSymb;
  Type *pType;
  
  if (!fScope)
    fScope = cg->currentScope;
  pType = NewType( cg,atom, TB_NoType, category, TD_Unknown, TQ_None, false, 0, 0);
  static_cast< TypeStruct * >( pType )->unqualifiedtype = pType;
  lSymb = NewSymbol( cg, loc, fScope, atom, pType, SK_Tag);
  lAddToTree( cg, &fScope->tags, lSymb, pType);
  return lSymb;
} // AddTag
Пример #9
0
Symbol *AddTag(SourceLoc *loc, Scope *fScope, int atom, int category)
{
    Symbol *lSymb;
    Type *pType;

    if (!fScope)
        fScope = CurrentScope;
    pType = NewType(category, 0);
    pType->str.unqualifiedtype = pType;
    lSymb = NewSymbol(loc, fScope, atom, pType, TAG_S);
    lAddToTree(&fScope->tags, lSymb, pType);
    return lSymb;
} // AddTag
Пример #10
0
// Initialize internal variables of the compiler
void initialize()
{
	int i;

	ArmVersion=400;  // default ARM version
	// variables for predefined types
	halfword_t IntegerTypeNode;
	halfword_t BooleanTypeNode;
	halfword_t RealTypeNode;
	halfword_t PointerTypeNode;

	// initialization of variables
	for (i=0;i<NB_FILES;i++) Files[i].f=NULL;
    iStackPtr=0;  // declare that no input file is open

    HiPoolMin=POOL_SIZE;
    LoPoolMax=0;

    InitMem();   // memory initialization
    InitStrings();
    InitHTable();
    InitCode();
    InitParse();

	// read the time
	start_time=clock();
	// initialize initial stack value
	initial_stack_value=get_stack_value();

	// Predefined identifier initialisation
	NewSymbol("write",sWRITE,0);
	NewSymbol("writeln",sWRITE,1);
	NewSymbol("sizeof",sSIZEOF,0);

	NewConst("true",TBOOLEAN,1);
	NewConst("false",TBOOLEAN,0);
	NewConst("maxint",TINTEGER,0x7fffffff);

	// predefined types
	IntegerTypeNode=NewType("integer",TINTEGER);
	BooleanTypeNode=NewType("boolean",TBOOLEAN);
	RealTypeNode=NewType("real",TREAL);
	CharTypeNode=NewType("char",TCHAR);
	PointerTypeNode=NewType("pointer",TPOINTER);
	NewType("text",TTEXT);

	NewSymbol("ord", sORDF,0);
	NewSymbol("pred", sORDF,1);
	NewSymbol("succ", sORDF,2);
	NewSymbol("abs",sNUMF,0);
	NewSymbol("sqr",sNUMF,1);
	NewSymbol("chr",sCHR,0);
	NewSymbol("new",sNEW,0);
	NewSymbol("dispose",sNEW,1);

	// predefined inlines functions
	NewInline1("odd",IntegerTypeNode,BooleanTypeNode,-1,1,0xe2100001);
	NewInline1("sqrt",RealTypeNode,RealTypeNode,-2,2,0xE1A0E00F, 	//  MOV lr,pc
											0xE599F000+REALSQRT);
	NewInline1("round",RealTypeNode,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALROUND);
	NewInline1("trunc",RealTypeNode,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALTRUNC);

	NewInline1("ln",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALLN);
	NewInline1("exp",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALEXP);
	NewInline1("sin",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALSIN);
	NewInline1("cos",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALCOS);
	NewInline1("arctan",RealTypeNode,RealTypeNode,-4,2,0xE1A0E00F,0xE599F000+REALATAN);

	NewFunc1("halt",IntegerTypeNode,NADA,HALT);

	NewInlineProc("clrscr",-10,2,0xE1A0E00F,0xE599F000+CLRSCR);

	InputVar=NewVar("input", TTEXT, -36);
	OutputVar=NewVar("output", TTEXT, -24);

	NewSymbol("rewrite",sOPEN,1);
	NewSymbol("reset",sOPEN,0);

	NewSymbol("close",sFILEP,CLOSE);
	NewSymbol("get",sFILEP,GET);
	NewSymbol("put",sFILEP,PUT);

// crt functions
    NewInline1("wherex",NADA,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+WHEREX);
    NewInline1("wherey",NADA,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+WHEREY);
    NewInline1("screenwidth",NADA,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+SCREENWIDTH);
    NewInline1("screenheight",NADA,IntegerTypeNode,-4,2,0xE1A0E00F,0xE599F000+SCREENHEIGHT);

    NewInline2("gotoxy",IntegerTypeNode, IntegerTypeNode, -4,2,0xE1A0E00F,0xE599F000+GOTOXY);

    NewSymbol("read",sREAD,0);
    NewSymbol("readln",sREAD,1);

    NewSymbol("eof",sEOF,0);
    NewSymbol("eoln",sEOF,1);

    NewFunc1("length",StringTypeNode,IntegerTypeNode,LENGTH);
}
Пример #11
0
Type *NewFunctionType(char *name)
{
    return NewType(name, NULL, TYF_NONE, TYK_FUNCTION);
}
Пример #12
0
Type *NewEnumType(char *name)
{
    return NewType(name, NULL, TYF_NONE, TYK_ENUM);
}
Пример #13
0
Type *NewPointerType(char *name, Type *base)
{
    return NewType(name, base, TYF_NONE, TYK_POINTER);
}
Пример #14
0
Type *NewTypedefType(char *name, Type *base)
{
    return NewType(name, base, TYF_NONE, TYK_TYPEDEF);
}
Пример #15
0
Type *NewQualifiedType(char *name, int flags, Type *base)
{
    return NewType(name, base, flags, TYK_QUALIFIER);
}
Пример #16
0
Type *NewBaseType(char *name)
{
    return NewType(name, NULL, TYF_NONE, TYK_BASE);
}
Пример #17
0
csShaderVariable& csShaderVariable::operator= (const csShaderVariable& copyFrom)
{
  SetName (copyFrom.GetName());
  //Type = copyFrom.Type;
  if (copyFrom.accessor != 0)
  {
    AllocAccessor (*copyFrom.accessor);
  }
  else
  {
    FreeAccessor ();
  }

  VariableType oldType = GetTypeI();
  NewType (copyFrom.GetTypeI());

  // Handle payload
  switch (GetTypeI())
  {
  case UNKNOWN:
    break;

  case INT:      
    Int = copyFrom.Int;
    break; 

  case TEXTURE:
    if (oldType == TEXTURE)
    {
      if (texture.HandValue)
	texture.HandValue->DecRef ();
      if (texture.WrapValue)
	texture.WrapValue->DecRef ();
    }
    texture = copyFrom.texture;
    if (texture.HandValue)
      texture.HandValue->IncRef ();
    if (texture.WrapValue)
      texture.WrapValue->IncRef ();
    break;

  case RENDERBUFFER:
    if (oldType == RENDERBUFFER)
    {
      if (RenderBuffer)
	RenderBuffer->DecRef ();
    }
    RenderBuffer = copyFrom.RenderBuffer;
    if (RenderBuffer)
      RenderBuffer->IncRef ();
    break;

  case FLOAT:
  case VECTOR2:
  case VECTOR3:
  case VECTOR4:
    memcpy (&Vector, &copyFrom.Vector, sizeof (Vector));
    break;

  case MATRIX3X3:
    *MatrixValuePtr = *copyFrom.MatrixValuePtr;
    break;

  case MATRIX4X4:
    *Matrix4ValuePtr = *copyFrom.Matrix4ValuePtr;
    break;

  case TRANSFORM:
    *TransformPtr = *copyFrom.TransformPtr;
    break;

  case ARRAY:
    *ShaderVarArray = *copyFrom.ShaderVarArray;
    break;

  default:
    ;
  }

  return *this;
}
Пример #18
0
int InitSymbolTable(CgStruct *Cg)
{
    SourceLoc dummyLoc = { 0, 0 };
    int ii, name;

    // Create the super-global scope and add predefined types and symbols:

    PushScope(NewScopeInPool(mem_CreatePool(0, 0)));
    UndefinedType = NewType(TYPE_BASE_UNDEFINED_TYPE | TYPE_CATEGORY_SCALAR, 0);
    CFloatType = NewType(TYPE_BASE_CFLOAT | TYPE_CATEGORY_SCALAR | TYPE_QUALIFIER_CONST, 1);
    CIntType = NewType(TYPE_BASE_CINT | TYPE_CATEGORY_SCALAR | TYPE_QUALIFIER_CONST, 1);
    VoidType = NewType(TYPE_BASE_VOID | TYPE_CATEGORY_SCALAR | TYPE_MISC_VOID, 0);
    FloatType = NewType(TYPE_BASE_FLOAT | TYPE_CATEGORY_SCALAR, 1);
    IntType = NewType(TYPE_BASE_INT | TYPE_CATEGORY_SCALAR, 1);
    BooleanType = NewType(TYPE_BASE_BOOLEAN | TYPE_CATEGORY_SCALAR, 1);

    CFloat1Type = NewPackedArrayType(CFloatType, 1, TYPE_QUALIFIER_CONST);
    CFloat2Type = NewPackedArrayType(CFloatType, 2, TYPE_QUALIFIER_CONST);
    CFloat3Type = NewPackedArrayType(CFloatType, 3, TYPE_QUALIFIER_CONST);
    CFloat4Type = NewPackedArrayType(CFloatType, 4, TYPE_QUALIFIER_CONST);
    CInt1Type = NewPackedArrayType(CIntType, 1, TYPE_QUALIFIER_CONST);
    CInt2Type = NewPackedArrayType(CIntType, 2, TYPE_QUALIFIER_CONST);
    CInt3Type = NewPackedArrayType(CIntType, 3, TYPE_QUALIFIER_CONST);
    CInt4Type = NewPackedArrayType(CIntType, 4, TYPE_QUALIFIER_CONST);
    Float1Type = NewPackedArrayType(FloatType, 1, 0);
    Float2Type = NewPackedArrayType(FloatType, 2, 0);
    Float3Type = NewPackedArrayType(FloatType, 3, 0);
    Float4Type = NewPackedArrayType(FloatType, 4, 0);
    Int1Type = NewPackedArrayType(IntType, 1, 0);
    Int2Type = NewPackedArrayType(IntType, 2, 0);
    Int3Type = NewPackedArrayType(IntType, 3, 0);
    Int4Type = NewPackedArrayType(IntType, 4, 0);
    Boolean1Type = NewPackedArrayType(BooleanType, 1, 0);
    Boolean2Type = NewPackedArrayType(BooleanType, 2, 0);
    Boolean3Type = NewPackedArrayType(BooleanType, 3, 0);
    Boolean4Type = NewPackedArrayType(BooleanType, 4, 0);

    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat"), CFloatType, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint"), CIntType, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, VOID_SY, VoidType, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, FLOAT_SY, FloatType, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, INT_SY, IntType, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, BOOLEAN_SY, BooleanType, TYPEDEF_S);

    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat1"), CFloat1Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat2"), CFloat2Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat3"), CFloat3Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat4"), CFloat4Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint1"), CInt1Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint2"), CInt2Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint3"), CInt3Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint4"), CInt4Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "float1"), Float1Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "float2"), Float2Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "float3"), Float3Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "float4"), Float4Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "int1"), Int1Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "int2"), Int2Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "int3"), Int3Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "int4"), Int4Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "bool1"), Boolean1Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "bool2"), Boolean2Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "bool3"), Boolean3Type, TYPEDEF_S);
    AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "bool4"), Boolean4Type, TYPEDEF_S);

    FalseSymb = AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "false"), BooleanType, CONSTANT_S);
    TrueSymb = AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "true"), BooleanType, CONSTANT_S);
    FalseSymb->details.con.value = 0;
    TrueSymb->details.con.value = 1;

    SetScalarTypeName(TYPE_BASE_NO_TYPE, LookUpAddString(atable, "***no-base-type***"), UndefinedType);
    SetScalarTypeName(TYPE_BASE_UNDEFINED_TYPE, LookUpAddString(atable, "***undefined-base-type***"), UndefinedType);
    SetScalarTypeName(TYPE_BASE_CFLOAT, LookUpAddString(atable, "cfloat"), CFloatType);
    SetScalarTypeName(TYPE_BASE_CINT, LookUpAddString(atable, "cint"), CIntType);
    SetScalarTypeName(TYPE_BASE_VOID, LookUpAddString(atable, "void"), VoidType);
    SetScalarTypeName(TYPE_BASE_FLOAT, LookUpAddString(atable, "float"), FloatType);
    SetScalarTypeName(TYPE_BASE_INT, LookUpAddString(atable, "int"), IntType);
    SetScalarTypeName(TYPE_BASE_BOOLEAN, LookUpAddString(atable, "bool"), BooleanType);

    name = LookUpAddString(atable, "***unknown-profile-base-type***");
    for (ii = TYPE_BASE_FIRST_USER; ii <= TYPE_BASE_LAST_USER; ii++)
        SetScalarTypeName(ii, name, UndefinedType);

    // Add profile specific symbols and types:

    Cg->theHAL->RegisterNames(Cg->theHAL);
    AddAtom(atable, "<*** end hal specific atoms ***>");

    // Initialize misc. other globals:

    CurrentDeclTypeSpecs.basetype = UndefinedType;
    CurrentDeclTypeSpecs.IsDerived = 0;
    CurrentDeclTypeSpecs.type = *UndefinedType;

    return 1;
} // InitSymbolTable