Esempio n. 1
0
void insertSymbol(Table T, char* s, int m, int b, int o) {
	if(T==NULL){
		fprintf(stderr, "Table Error: calling insert() on NULL Table reference\n");
		exit(EXIT_FAILURE);
	}
	if(T->top==NULL) {
		T->top = newSymbol(s, m, b, o);
		T->count++;
	}
	else {
		Symbol S = T->top;
		while(S!=NULL) {
			if(strcmp(S->sym, s)==0) {
				S->flag = 1;
				S = NULL;
				break;
			} else {
				if(S->next==NULL) {
					S->next = newSymbol(s, m, b, o);
					S = NULL;
					T->count++;
					break;
				}
				else S = S->next;
			}
		}
	}
}
Esempio n. 2
0
/*
 readDeclaration reads a declaration of a class
 */
static void readClassDeclaration()
{
    object classObj, super, vars;
    int i, size, instanceTop;
    object instanceVariables[15];

    if (nextToken() != nameconst)
        sysError("bad file format", "no name in declaration");
    classObj = findClass(tokenString);
    size = 0;
    if (nextToken() == nameconst)   /* read superclass name */
    {
        super = findClass(tokenString);
        basicAtPut(classObj, superClassInClass, super);
        size = intValue(basicAt(super, sizeInClass));
        nextToken();
    }
    if (token == nameconst)   /* read instance var names */
    {
        instanceTop = 0;
        while (token == nameconst)
        {
            instanceVariables[instanceTop++] = newSymbol(tokenString);
            size++;
            nextToken();
        }
        vars = newArray(instanceTop);
        for (i = 0; i < instanceTop; i++)
        {
            basicAtPut(vars, i+1, instanceVariables[i]);
        }
        basicAtPut(classObj, variablesInClass, vars);
    }
    basicAtPut(classObj, sizeInClass, newInteger(size));
}
Esempio n. 3
0
static numout* loadLib(void* handle, char * lib)
{ numout * cc=malloc(sizeof(numout));
  char name[100];
  if(!handle) {free(cc); return NULL;}   
  cc->handle=handle;
  sprintf(name,"interface_%s",lib);
  cc->interface=newSymbol(handle, name);
  if(!cc->interface || cc->interface->nprc==0){free(cc); return NULL;}
  else
  {  int i;
     cc->init=0;
     cc->Q=NULL, cc->SC=NULL;
     cc->link=malloc(sizeof(double*)*(1+cc->interface->nvar));
     cc->link[0]=NULL;
     for(i=1;i<=cc->interface->nvar;i++) 
     { char *name=cc->interface->varName[i];
       cc->link[i]=varAddress(name);
if(cc->link==NULL) printf("No link for %s\n",name);       
       if(strcmp(name,"Q")==0) cc->Q=cc->interface->va+i; 
       else if(strcmp(name,"SC")==0) cc->SC=cc->interface->va+i;
     }  
     *(cc->interface->aWidth)=&aWidth;
  }
  return cc;
}
Esempio n. 4
0
Symbol* newNumberSymbol(int pNum){
	int *num = (int*)malloc(sizeof(int));
	*num = pNum;
	Symbol* symbol = newSymbol();
	symbol->value = pNum;
	return symbol;
}
void QgsDataDefinedSizeLegendWidget::changeSymbol()
{
  std::unique_ptr<QgsMarkerSymbol> newSymbol( mSourceSymbol->clone() );
  QgsSymbolWidgetContext context;
  if ( mMapCanvas )
    context.setMapCanvas( mMapCanvas );

  QgsExpressionContext ec;
  ec << QgsExpressionContextUtils::globalScope()
     << QgsExpressionContextUtils::projectScope( QgsProject::instance() )
     << QgsExpressionContextUtils::atlasScope( nullptr );
  if ( mMapCanvas )
    ec << QgsExpressionContextUtils::mapSettingsScope( mMapCanvas->mapSettings() );
  context.setExpressionContext( &ec );

  QString crsAuthId = mMapCanvas ? mMapCanvas->mapSettings().destinationCrs().authid() : QString();
  std::unique_ptr<QgsVectorLayer> layer( new QgsVectorLayer( "Point?crs=" + crsAuthId, "tmp", "memory" ) );

  QgsSymbolSelectorDialog d( newSymbol.get(), QgsStyle::defaultStyle(), layer.get(), this );
  d.setContext( context );

  if ( d.exec() != QDialog::Accepted )
    return;

  mSourceSymbol.reset( newSymbol.release() );
  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSourceSymbol.get(), btnChangeSymbol->iconSize() );
  btnChangeSymbol->setIcon( icon );

  emit widgetChanged();
}
void QgsGraduatedSymbolRendererWidget::changeRangeSymbol( int rangeIdx )
{
  const QgsRendererRange &range = mRenderer->ranges()[rangeIdx];
  std::unique_ptr< QgsSymbol > newSymbol( range.symbol()->clone() );
  QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
  if ( panel && panel->dockMode() )
  {
    // bit tricky here - the widget doesn't take ownership of the symbol. So we need it to last for the duration of the
    // panel's existence. Accordingly, just kinda give it ownership here, and clean up in cleanUpSymbolSelector
    QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol.release(), mStyle, mLayer, panel );
    dlg->setContext( mContext );
    dlg->setPanelTitle( range.label() );
    connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget );
    connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector );
    openPanel( dlg );
  }
  else
  {
    QgsSymbolSelectorDialog dlg( newSymbol.get(), mStyle, mLayer, panel );
    dlg.setContext( mContext );
    if ( !dlg.exec() || !newSymbol )
    {
      return;
    }

    mGraduatedSymbol = std::move( newSymbol );
    applyChangeToSymbol();
  }
}
void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
{
  QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
  std::unique_ptr< QgsSymbol > newSymbol( mGraduatedSymbol->clone() );
  if ( panel && panel->dockMode() )
  {
    QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol.release(), mStyle, mLayer, panel );
    dlg->setContext( mContext );

    connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget );
    connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector );
    connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::updateGraduatedSymbolIcon );
    panel->openPanel( dlg );
  }
  else
  {
    QgsSymbolSelectorDialog dlg( newSymbol.get(), mStyle, mLayer, panel );
    if ( !dlg.exec() || !newSymbol )
    {
      return;
    }

    mGraduatedSymbol = std::move( newSymbol );
    updateGraduatedSymbolIcon();
    applyChangeToSymbol();
  }
}
Esempio n. 8
0
void
newAssoc(Name name, Any obj)
{ PceITFSymbol symbol;
  Any old;

  if ( (old = getObjectAssoc(name)) )
    deleteAssoc(old);
  deleteAssoc(obj);

  if ( onFlag(name, F_ITFNAME) )
  { symbol = getMemberHashTable(NameToITFTable, name);
    symbol->object = obj;
    appendHashTable(ObjectToITFTable, obj, symbol);
    setFlag(obj, F_ASSOC);
  } else
  { symbol = newSymbol(obj, name);

    setFlag(name, F_ITFNAME);
    if ( isObject(obj) )
      setFlag(obj, F_ASSOC);

    appendHashTable(ObjectToITFTable, obj,  symbol);
    appendHashTable(NameToITFTable,   name, symbol);
  }

  if ( isObject(obj) )
    lockObj(obj);
}
Esempio n. 9
0
LispRef content(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "content\n"));

    char tag;
    read_byte(tag);

    WITH_DEBUG(fprintf(stderr, "  tag: %x\n", tag));

    switch (tag)
    {
        case TC_NULL:
            return nullReference(stream, eos_error_p, eos_value);
        case TC_REFERENCE:
            return prevObject(stream, eos_error_p, eos_value);
        case TC_CLASS:
            return newClass(stream, eos_error_p, eos_value);
        case TC_OBJECT:
            return newObject(stream, eos_error_p, eos_value);
        case TC_STRING:
            return newString(stream, eos_error_p, eos_value);
        case TC_STATE:
            return newState(stream, eos_error_p, eos_value);
        case TC_VECTOR:
            return newVector(stream, eos_error_p, eos_value);
        case TC_STREAM:
            return newStream(stream, eos_error_p, eos_value);
        case TC_RESET:
            return reset(stream, eos_error_p, eos_value);
        case TC_SELF:
            return stream;
        case TC_FUNCTION:
            return newFunction(stream, eos_error_p, eos_value);
        case TC_BYTEVECTOR:
            return newBytevector(stream, eos_error_p, eos_value);
        case TC_INT:
            return newInt(stream, eos_error_p, eos_value);
        case TC_DOUBLE:
            return newDouble(stream, eos_error_p, eos_value);
        case TC_SYMBOL:
            return newSymbol(stream, eos_error_p, eos_value);
        case TC_KEYWORD:
            return newKeyword(stream, eos_error_p, eos_value);
        case TC_CHAR:
            return newChar(stream, eos_error_p, eos_value);
        case TC_CONS:
            return newCons(stream, eos_error_p, eos_value);
        default:
            {
                LispRef str, args;

                eul_allocate_string(str, "unknown tag in ~a");
                eul_allocate_cons(args, stream, eul_nil);
                eul_serial_error(stream, str, args);
                return eul_nil;
            }
    }
}
Esempio n. 10
0
/* --------------- init global variable ----------- */
void initPrimitiveVariable(){
  eval(newList(3, newSymbol("define"), newSymbol("nil"), newExp(&sNull, NULL_TAG)),
       sGlobalEnvironment);
  eval(newList(3, newSymbol("define"), newSymbol("#t"), newExp(&sTrue, TRUE_TAG)),
       sGlobalEnvironment);
  eval(newList(3, newSymbol("define"), newSymbol("#f"), newExp(&sFalse, FALSE_TAG)),
       sGlobalEnvironment);
  eval(newList(3, newSymbol("define"), newSymbol("#e"), newExp(&sError, ERROR_TAG)),
       sGlobalEnvironment);
}
Esempio n. 11
0
/* ------------- assingment value ---------------------*/
static sSymbol *assignSynbol(sExpression *exp){
  if(isList(exp)){
    sExpression *temp = cadr(toList(exp));
    if(isSymbol(temp)){
      return toSymb(temp);
    }
  }
  return toSymb(newSymbol("_error"));
}
bool dpLoader::loadMapFile(const char *path, void *imagebase)
{
    if(m_mapfiles_read.find(path)!=m_mapfiles_read.end()) {
        return true;
    }

    FILE *file = fopen(path, "rb");
    if(!file) { return false; }

    char line[MAX_SYM_NAME+1];

// C99 から size_t 用の scanf フォーマット %zx が加わったらしいが、VisualC++ は未対応な様子
#ifdef _WIN64
#   define ZX "%llx"
#else
#   define ZX "%x"
#endif

    size_t preferred_addr = 0;
    size_t gap = 0;
    {
        while(fgets(line, _countof(line), file)) {
            if(sscanf(line, " Preferred load address is " ZX, &preferred_addr)==1) {
                gap = (size_t)imagebase - preferred_addr;
                break;
            }
        }
    }
    {
        std::regex reg("^ [0-9a-f]{4}:[0-9a-f]{8}       ");
        std::cmatch m;
        while(fgets(line, _countof(line), file)) {
            if(std::regex_search(line, m, reg)) {
                const char *name_src = m[0].second;
                auto name_end = std::find(name_src, const_cast<const char *>(line+_countof(line)), ' ');
                auto rva_plus_base_start = std::find_if_not(name_end, const_cast<const char *>(line+_countof(line)), [](char c){ return c == ' '; });
                *(const_cast<char *>(rva_plus_base_start)+8) = '\0';
                size_t rva_plus_base = 0;
                sscanf(rva_plus_base_start, ZX, &rva_plus_base);
                if(rva_plus_base <= preferred_addr) { continue; }

                void *addr = (void*)(rva_plus_base + gap);
                size_t name_length = std::distance(name_src, name_end);
                char *name = new char[name_length+1];
                strncpy(name, name_src, name_length);
                name[name_length] = '\0';
                m_hostsymbols.addSymbol(newSymbol(name, addr, g_host_symbol_flags, 0, nullptr));
            }
        }
    }
    m_hostsymbols.sort();
    fclose(file);
    m_mapfiles_read.insert(path);
    return true;
}
Esempio n. 13
0
/* --------- define value --------------------- */
static sSymbol *definitionSymbol(sExpression *exp){
  if(isList(exp)){
    sExpression *temp = cadr(toList(exp));
    if(isSymbol(temp)){
      return toSymb(temp);
    }else{
      return toSymb(car(toList(temp)));
    }
  }
  return toSymb(newSymbol("_error"));
}
Esempio n. 14
0
// Insert a new symbol into the symbol table
bool SymbolTable::Insert(const string name,const Record record)
{
	// Disallow empty strings for critical structure members
	if (name.empty()) { throw new std::invalid_argument("Name cannot be empty"); }
	else if (record.type.empty()) { throw new std::invalid_argument("Record type cannot be empty"); }
	else if (record.use.empty()) { throw new std::invalid_argument("Record use cannot be empty"); }

	// Generate a new container with symbol information and add to symbol table
	std::pair<string, Record> newSymbol(name, record);
	std::pair<std::unordered_map<string,Record>::iterator, bool> insertionResult = symbol_bucket->insert(newSymbol);
	return std::get<1>(insertionResult);
}
Esempio n. 15
0
File: as.c Progetto: Logout22/Escape
Symbol *lookupEnter(char *name, int whichTable) {
  Symbol *p, *q, *r;
  int cmp;

  if (whichTable == GLOBAL_TABLE) {
    p = globalTable;
  } else {
    p = localTable;
  }
  if (p == NULL) {
    r = newSymbol(name);
    if (whichTable == GLOBAL_TABLE) {
      globalTable = r;
    } else {
      localTable = r;
    }
    return r;
  }
  while (1) {
    q = p;
    cmp = strcmp(name, q->name);
    if (cmp == 0) {
      return q;
    }
    if (cmp < 0) {
      p = q->left;
    } else {
      p = q->right;
    }
    if (p == NULL) {
      r = newSymbol(name);
      if (cmp < 0) {
        q->left = r;
      } else {
        q->right = r;
      }
      return r;
    }
  }
}
Esempio n. 16
0
File: eval3.c Progetto: NV/nile
static oop intern(char *cstr)
{
  oop list= nil;
  for (list= symbols;  is(Pair, list);  list= getTail(list)) {
    oop sym= getHead(list);
    if (!strcmp(cstr, get(sym, Symbol,bits))) return sym;
  }
  oop sym= nil;
  GC_PROTECT(sym);
  sym= newSymbol(cstr);
  symbols= newPair(sym, symbols);
  GC_UNPROTECT(sym);
  return sym;
}
Esempio n. 17
0
QPixmap symbolChooser::createSymbol(int index, const triC& color) const {

  const int drawDimension = symbolDimension_ - 2 * borderDimension_;
  QPixmap drawSymbol(drawDimension, drawDimension);
  drawSymbol.fill(Qt::white);
  if (index < numberOfSymbols()) {
    QPainter painter(&drawSymbol);
    painter.setRenderHint(QPainter::Antialiasing, true);
    const int interval = unicodeCharacters_.size();
    // type1 symbol doesn't need further editing
    if (index >= interval && index < 2*interval) {
      index -= interval;
      createSymbolType2(&painter, drawDimension);
    }
    else if (index >= 2*interval && index < 3*interval) {
      index -= 2*interval;
      createSymbolType3(&painter, drawDimension);
    }
    else if (index >= 3*interval && index < 4*interval) {
      index -= 3*interval;
      createSymbolType4(&painter, drawDimension);
    }
    const QChar symbolChar = unicodeCharacters_[index];
    const QString symbolString(symbolChar);
    painter.setFont(unicodeFont_.qFont());
    const int heightBuffer = 2;
    ::setFontHeight(&painter, drawDimension - heightBuffer);
    const QRect textRect(0, heightBuffer/2, drawDimension,
                         drawDimension - heightBuffer/2);
    painter.drawText(textRect, Qt::AlignCenter, symbolString);
  }
  else { // no symbols left, so just make it the original color
    QPainter painter(&drawSymbol);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.fillRect(0, 0, drawDimension, drawDimension, color.qc());
  }

  if (borderDimension_) {
    QPixmap newSymbol(symbolDimension_, symbolDimension_);
    newSymbol.fill(color.qrgb());
    QPainter painter(&newSymbol);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.drawPixmap(QPoint(borderDimension_, borderDimension_),
                       drawSymbol);
    return newSymbol;
  }
  else {
    return drawSymbol;
  }
}
Esempio n. 18
0
sExpression *cloneList(sExpression *exp){
  if(isList(exp)){
    sList *temp = toList(exp);
    return cons(cloneList(car(temp)),
                cloneList(cdr(temp)));
  }
  if(isSymbol(exp)){
    return newSymbol(toSymb(exp)->name);
  }
  if(isNumber(exp)){
    return newNumber(toNum(exp)->value);
  }
  if(isString(exp)){
    return newString(toString(exp)->value);
  }
  return exp;
}
dpSymbol* dpLoader::findHostSymbolByAddress(void *addr)
{
    if(dpSymbol *sym = m_hostsymbols.findSymbolByAddress(addr)) {
        return sym;
    }

    char buf[sizeof(SYMBOL_INFO)+1024];
    PSYMBOL_INFO sinfo = (PSYMBOL_INFO)buf;
    sinfo->SizeOfStruct = sizeof(SYMBOL_INFO);
    sinfo->MaxNameLen = 1024;
    if(::SymFromAddr(::GetCurrentProcess(), (DWORD64)addr, 0, sinfo)==FALSE) {
        return false;
    }
    char *namebuf = new char[sinfo->NameLen+1];
    strncpy(namebuf, sinfo->Name, sinfo->NameLen+1);
    m_hostsymbols.addSymbol(newSymbol(namebuf, (void*)sinfo->Address, g_host_symbol_flags, 0, nullptr));
    m_hostsymbols.sort();
    return m_hostsymbols.findSymbolByAddress(addr);
}
Esempio n. 20
0
static sExpression *definitionValue(sExpression *exp, sEnvironment *env){
  if(isList(exp)){
    sExpression *temp = cadr(toList(exp));
    if(isSymbol(temp)){
      temp = cdr(toList( cdr(toList(exp))));
      if(isList(temp)){
        return car(toList(temp));
      }else{
        return temp;
      }
    }else{
      sExpression *parameters = cdr(toList(temp));
      sExpression *body = cdr(toList( cdr(toList(exp))));
      return cons(newSymbol("lambda"),
                  cons(parameters,
                       body));
    }
  }
  return &sNull;
}
Esempio n. 21
0
/*--------------------------------------------------------------------*/
void
ptrPseudoSymConvert (symbol *sym, iCode *dic, char *name)
{
  symbol *psym = newSymbol (name, 1);
  psym->psbase = ptrBaseRematSym (OP_SYMBOL (IC_LEFT (dic)));
  psym->type = sym->type;
  psym->etype = psym->psbase->etype;

  strcpy (psym->rname, psym->name);
  sym->isspilt = 1;
  sym->usl.spillLoc = psym;
#if 0 // an alternative fix for bug #480076
  /* now this is a useless assignment to itself */
  remiCodeFromeBBlock (ebbs, dic);
#else
  /* now this really is an assignment to itself, make it so;
     it will be optimized out later */
  dic->op='=';
  ReplaceOpWithCheaperOp(&IC_RIGHT(dic), IC_RESULT(dic));
  IC_LEFT(dic)=NULL;
#endif
}
Esempio n. 22
0
static void
_xa51_genAssemblerPreamble (FILE * of)
{
  symbol *mainExists=newSymbol("main", 0);
  mainExists->block=0;

  if ((mainExists=findSymWithLevel(SymbolTab, mainExists))) {
    fprintf (of, "\t.area GSINIT\t(CODE)\n");
    fprintf (of, "__interrupt_vect:\n");
    fprintf (of, "\t.dw\t0x8f00\n");
    fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n");
    fprintf (of, "\n");
    fprintf (of, "__sdcc_gsinit_startup:\n");
    fprintf (of, ";\tmov.b\t_SCR,#0x01\t; page zero mode\n");
    fprintf (of, "\t.db 0x96,0x48,0x40,0x01\n");
    fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc);
    fprintf (of, "\tcall\t_external_startup\n");
    _xa51_genXINIT(of);
    fprintf (of, "\t.area CSEG\t(CODE)\n");
    fprintf (of, "\tcall\t_main\n");
    fprintf (of, "\treset\t;main should not return\n");
  }
}
Esempio n. 23
0
static void *applySyntaxToRule(sExpression *key, sExpression *value, sExpression *rule){
  if(isList(key) && isList(cdr(toList(key))) && isSymbol(cadr(toList(key))) && (strcmp(toSymb(cadr(toList(key)))->name, "...") == 0) &&
     isList(rule) && isList(cdr(toList(rule))) && isSymbol(cadr(toList(rule))) && (strcmp(toSymb(cadr(toList(rule)))->name, "...") == 0))
  {
    if(isList(value)){
      if(isSymbol(car(toList(rule)))){
        sExpression *tempRule = newSymbol(toSymb(car(toList(rule)))->name);
        evalSyntaxRuleIter(car(toList(key)), car(toList(value)), tempRule);

        if(isSymbol(tempRule) && strcmp(toSymb(tempRule)->name, toSymb(car(toList(rule)))->name) == 0){
          //printExp(rule);
        }
        else{
          if(isNull(cdr(toList(value)))){
            rule->value = cons(tempRule, &sNull)->value;
          }
          else{
            rule->value = cons(tempRule,
                             cons(car(toList(rule)),
                                  cdr(toList(rule))))->value;
            rule->type = LIST_TAG;
            applySyntaxToRule(key, cdr(toList(value)), cdr(toList(rule)));
          }
        }
      }
    }
  }
  else if(isList(rule)){
    applySyntaxToRule(key, value, car(toList(rule)));
    applySyntaxToRule(key, value, cdr(toList(rule)));
  }
  else if(isSymbol(rule) && strcmp(toSymb(key)->name, toSymb(rule)->name) == 0){
    rule->value = value->value;
    rule->type = value->type;
  }
}
Esempio n. 24
0
/*-----------------------------------------------------------------*/
static void
pic14createInterruptVect (struct dbuf_s * vBuf)
{
        mainf = newSymbol ("main", 0);
        mainf->block = 0;

        /* only if the main function exists */
        if (!(mainf = findSymWithLevel (SymbolTab, mainf)))
        {
                struct options *op = &options;
                if (!(op->cc_only || noAssemble))
                        //      werror (E_NO_MAIN);
                        fprintf(stderr,"WARNING: function 'main' undefined\n");
                return;
        }

        /* if the main is only a prototype ie. no body then do nothing */
        if (!IFFUNC_HASBODY(mainf->type))
        {
                /* if ! compile only then main function should be present */
                if (!(options.cc_only || noAssemble))
                        //      werror (E_NO_MAIN);
                        fprintf(stderr,"WARNING: function 'main' undefined\n");
                return;
        }

        dbuf_printf (vBuf, "%s", iComments2);
        dbuf_printf (vBuf, "; reset vector \n");
        dbuf_printf (vBuf, "%s", iComments2);
        // Lkr file should place section STARTUP at address 0x0, but does not ...
        dbuf_printf (vBuf, "STARTUP\t%s 0x0000\n", CODE_NAME);
        dbuf_printf (vBuf, "\tnop\n"); /* first location for used by incircuit debugger */
        dbuf_printf (vBuf, "\tpagesel __sdcc_gsinit_startup\n");
        dbuf_printf (vBuf, "\tgoto\t__sdcc_gsinit_startup\n");
        popGetExternal("__sdcc_gsinit_startup", 0);
}
Esempio n. 25
0
S si(const C *n)
{
  S s,a=(S)(((S *)(SymHashTable->b))+((SymHashTable->nb-1)&HA(n)));

  for(;(s=a->s)&&strneq(n,s->n);a=s) ;
  if(s==0)
    {
      int rc;

#if defined(linux)
      static int initMutex=1;
      if(initMutex)
	initMutex=_initMutex();
#endif

      if(0!=(rc=pthread_mutex_lock(&newSymbol_lock)))
        {
          perror("si() pthread_mutex_lock");
        }
      {
        /* Need to re-check for Symbol after getting lock */
        S a=(S)(((S *)(SymHashTable->b))+((SymHashTable->nb-1)&HA(n)));
        for(;(s=a->s)&&strneq(n,s->n);a=s) ;
        if(s==0)
          {
            s=newSymbol(n,a);
          }
      }

      if(rc==0 && pthread_mutex_unlock(&newSymbol_lock))
        {
          perror("si() pthread_mutex_unlock");
        }
    }
  R s;
}
Esempio n. 26
0
/*-----------------------------------------------------------------*/
void
picglue ()
{
        FILE *asmFile;
        struct dbuf_s ovrBuf;
        struct dbuf_s vBuf;

        dbuf_init(&ovrBuf, 4096);
        dbuf_init(&vBuf, 4096);

        pCodeInitRegisters();

        /* check for main() */
        mainf = newSymbol ("main", 0);
        mainf->block = 0;
        mainf = findSymWithLevel (SymbolTab, mainf);

        if (!mainf || !IFFUNC_HASBODY(mainf->type))
        {
                /* main missing -- import stack from main module */
                //fprintf (stderr, "main() missing -- assuming we are NOT the main module\n");
                pic14_options.isLibrarySource = 1;
        }

        /* At this point we've got all the code in the form of pCode structures */
        /* Now it needs to be rearranged into the order it should be placed in the */
        /* code space */

        movepBlock2Head('P');              // Last
        movepBlock2Head(code->dbName);
        movepBlock2Head('X');
        movepBlock2Head(statsg->dbName);   // First


        /* print the global struct definitions */
        if (options.debug)
                cdbStructBlock (0);

        /* do the overlay segments */
        pic14emitOverlay(&ovrBuf);

        /* PENDING: this isnt the best place but it will do */
        if (port->general.glue_up_main) {
                /* create the interrupt vector table */
                pic14createInterruptVect (&vBuf);
        }

        AnalyzepCode('*');

        ReuseReg(); // ReuseReg where call tree permits

        InlinepCode();

        AnalyzepCode('*');

        if (options.debug) pcode_test();


        /* now put it all together into the assembler file */
        /* create the assembler file name */

        if ((noAssemble || options.c1mode) && fullDstFileName)
        {
                sprintf (buffer, "%s", fullDstFileName);
        }
        else
        {
                sprintf (buffer, "%s", dstFileName);
                strcat (buffer, ".asm");
        }

        if (!(asmFile = fopen (buffer, "w"))) {
                werror (E_FILE_OPEN_ERR, buffer);
                exit (1);
        }

        /* prepare statistics */
        resetpCodeStatistics ();

        /* initial comments */
        pic14initialComments (asmFile);

        /* print module name */
        fprintf (asmFile, "%s\t.file\t\"%s\"\n",
            options.debug ? "" : ";", fullSrcFileName);

        /* Let the port generate any global directives, etc. */
        if (port->genAssemblerPreamble)
        {
                port->genAssemblerPreamble(asmFile);
        }

        /* Put all variables into a cblock */
        AnalyzeBanking();

        /* emit initialized data */
        showAllMemmaps(asmFile);

        /* print the locally defined variables in this module */
        writeUsedRegs(asmFile);

        /* create the overlay segments */
        fprintf (asmFile, "%s", iComments2);
        fprintf (asmFile, "; overlayable items in internal ram \n");
        fprintf (asmFile, "%s", iComments2);
        dbuf_write_and_destroy (&ovrBuf, asmFile);

        /* copy the interrupt vector table */
        if (mainf && IFFUNC_HASBODY(mainf->type))
          dbuf_write_and_destroy (&vBuf, asmFile);
        else
          dbuf_destroy(&vBuf);

        /* create interupt ventor handler */
        pic14_emitInterruptHandler (asmFile);

        /* copy over code */
        fprintf (asmFile, "%s", iComments2);
        fprintf (asmFile, "; code\n");
        fprintf (asmFile, "%s", iComments2);
        fprintf (asmFile, "code_%s\t%s\n", moduleName, port->mem.code_name);

        /* unknown */
        copypCode(asmFile, 'X');

        /* _main function */
        copypCode(asmFile, 'M');

        /* other functions */
        copypCode(asmFile, code->dbName);

        /* unknown */
        copypCode(asmFile, 'P');

        dumppCodeStatistics (asmFile);

        fprintf (asmFile,"\tend\n");

        fclose (asmFile);
        pic14_debugLogClose();
}
Esempio n. 27
0
/*-----------------------------------------------------------------*/
eBBlock *
iCode2eBBlock (iCode * ic)
{
  iCode *loop;
  eBBlock *ebb = neweBBlock (); /* allocate an entry */

  /* put the first one unconditionally */
  ebb->sch = ic;

  /* if this is a label then */
  if (ic->op == LABEL)
    ebb->entryLabel = ic->label;
  else
    {
      SNPRINTF (buffer, sizeof(buffer), "_eBBlock%d", eBBNum++);
      ebb->entryLabel = newSymbol (buffer, 1);
      ebb->entryLabel->key = labelKey++;
    }

  if (ic &&
      (ic->op == GOTO ||
       ic->op == JUMPTABLE ||
       ic->op == IFX))
    {
      ebb->ech = ebb->sch;
      return ebb;
    }

  /* if this is a function call */
  if (ic->op == CALL || ic->op == PCALL)
    {
      ebb->hasFcall = 1;
      if (currFunc)
        FUNC_HASFCALL(currFunc->type) = 1;
    }

  if ((ic->next && ic->next->op == LABEL) ||
      !ic->next)
    {
      ebb->ech = ebb->sch;
      return ebb;
    }

  /* loop thru till we find one with a label */
  for (loop = ic->next; loop; loop = loop->next)
    {

      /* if this is the last one */
      if (!loop->next)
        break;
      /* if this is a function call */
      if (loop->op == CALL || loop->op == PCALL)
        {
          ebb->hasFcall = 1;
          if (currFunc)
            FUNC_HASFCALL(currFunc->type) = 1;
        }

      /* if the next one is a label */
      /* if this is a goto or ifx */
      if (loop->next->op == LABEL ||
          loop->op == GOTO ||
          loop->op == JUMPTABLE ||
          loop->op == IFX)
        break;
    }

  /* mark the end of the chain */
  ebb->ech = loop;

  return ebb;
}
Esempio n. 28
0
// a != b → R( a, i_{a,b} ) = R( b, i_{a,b} )
void Egraph::ExtAxiom( Enode * a, Enode * b )
{
  assert( isDynamic( a ) );
  assert( isDynamic( b ) );
  Enode * as = dynamicToStatic( a );
  Enode * bs = dynamicToStatic( b );
  assert( isStatic( as ) );
  assert( isStatic( bs ) );

  assert( as->isDTypeArray( ) );
  assert( bs->isDTypeArray( ) );

  // create fresh index i_a,b for pair a,b
  char def_name[ 48 ];
  sprintf( def_name, IND_STR, as->getId( ), bs->getId( ) );
  const unsigned type = DTYPE_ARRAY_INDEX;
  if ( lookupSymbol( def_name ) == NULL )
    newSymbol( def_name, type );
  // Create new variable
  Enode * i = mkVar( def_name );
  // Create two new selections
  Enode * select1  = mkSelect( as, i );
  Enode * select2  = mkSelect( bs, i );
  // Create new literals
  Enode * lit1     = mkEq( cons( as, cons( bs ) ) );
  Enode * lit2_pos = mkEq( cons( select1, cons( select2 ) ) );
  Enode * lit2     = mkNot( cons( lit2_pos ) );
#ifdef PRODUCE_PROOF
  if ( config.gconfig.print_inter > 0 )
  {
    const uint64_t shared = getIPartitions( as ) 
			  & getIPartitions( bs );
    // Mixed can't be one at this point
    assert( shared != 1 );
    // Set AB-mixed partition if no intersection
    if ( shared == 0 )
    {
      setIPartitions( i, 1 );
      setIPartitions( select1, 1 );
      setIPartitions( select2, 1 );
      setIPartitions( lit1, 1 );
      setIPartitions( lit2_pos, 1 );
      setIPartitions( lit2, 1 );
    }
    // Otherwise they share something
    else
    {
      setIPartitions( i, shared );
      setIPartitions( select1, shared );
      setIPartitions( select2, shared );
      setIPartitions( lit1, shared );
      setIPartitions( lit2_pos, shared );
      setIPartitions( lit2, shared );
    }
  }
#endif
  vector< Enode * > v;
  v.push_back( lit1 );
  v.push_back( lit2 );
#ifdef ARR_VERB
  cout << "Axiom Ext ->   " << "( or " << lit1 << " " << lit2 << " )" << endl;
#endif
  splitOnDemand( v, id );

  handleArrayAssertedAtomTerm( select1 );
  handleArrayAssertedAtomTerm( select2 );

  // New contexts to propagate info about new index
  // Given R(a,new) look for all store users W(a,i,e) 
  // and instantiate RoW over R(W(a,i,e),new)
  vector< Enode * > sela;
  vector< Enode * > stoa;
  vector< Enode * > selb;
  vector< Enode * > stob;
  Enode * select3 = NULL;

  // Act over a
  getUsers( a, sela, stoa );
  for( size_t j = 0 ; j < stoa.size( ) ; j++ )
  {
    assert( isDynamic( stoa[ j ] ) );
    Enode * ss = dynamicToStatic( stoa[ j ] );
    assert( isStatic( ss ) );
    // Creation new select for each store user of a
    select3 = mkSelect( ss, i );
    // RoW over new select
    handleArrayAssertedAtomTerm( select3 );
#ifdef PRODUCE_PROOF
    if ( config.gconfig.print_inter > 0 )
    {
      const uint64_t shared = getIPartitions( ss ) 
	                    & getIPartitions( i );
      // Mixed can't be one at this point
      assert( shared != 1 );
      // Set AB-mixed partition if no intersection
      if ( shared == 0 )
	setIPartitions( select3, 1 );
      // Otherwise they share something
      else
	setIPartitions( select3, shared );
    }
#endif
  }

  // Act over b
  getUsers( b, selb, stob );
  for ( size_t j = 0 ; j < stob.size( ) ; j++ )
  {
    assert( isDynamic( stoa[ j ] ) );
    Enode * ss = dynamicToStatic( stob[ j ] );
    assert( isStatic( ss ) );
    // Creation new select for each store user of b
    select3 = mkSelect( ss, i );
#ifdef PRODUCE_PROOF
    if ( config.gconfig.print_inter > 0 )
    {
      const uint64_t shared = getIPartitions( ss ) 
	                    & getIPartitions( i );
      // Mixed can't be one at this point
      assert( shared != 1 );
      // Set AB-mixed partition if no intersection
      if ( shared == 0 )
	setIPartitions( select3, 1 );
      // Otherwise they share something
      else
	setIPartitions( select3, shared );
    }
#endif
    // RoW over new select
    handleArrayAssertedAtomTerm( select3 );
  }
}
Esempio n. 29
0
int Database::setBars (Bars *symbol)
{
    if (! symbol)
        return 0;

    if (! getSymbol(symbol))
    {
        if (! newSymbol(symbol))
            return 0;
    }
    else
    {
        // check if we need to save the name
        if (! symbol->name().isEmpty())
            setName(symbol);
    }

    if (! init())
        return 0;

    _db.transaction();

    QSqlQuery q(_db);

    QList<int> keys = symbol->keys();

    BarType bt;
    int loop = 0;
    for (; loop < keys.size(); loop++)
    {
        CBar *bar = symbol->bar(keys.at(loop));

        QDateTime dt = bar->date();

        QString date = dt.toString("yyyyMMddHHmmss");

        // first check if record exists so we know to do an update or insert
        QString s = "SELECT date FROM " + symbol->table() + " WHERE date =" + date;
        q.exec(s);
        if (q.lastError().isValid())
        {
            qDebug() << "Database::setBars:" << q.lastError().text();
            qDebug() << s;
            continue;
        }

        if (q.next()) // record exists, use update
        {
            s = "UPDATE " + symbol->table() + " SET ";

            QStringList tl;
            double v = 0;
            if (bar->get(bt.indexToString(BarType::_OPEN), v))
                tl << "open=" + QString::number(v);

            v = 0;
            if (bar->get(bt.indexToString(BarType::_HIGH), v))
                tl << "high=" + QString::number(v);

            v = 0;
            if (bar->get(bt.indexToString(BarType::_LOW), v))
                tl << "low=" + QString::number(v);

            v = 0;
            if (bar->get(bt.indexToString(BarType::_CLOSE), v))
                tl << "close=" + QString::number(v);

            v = 0;
            if (bar->get(bt.indexToString(BarType::_VOLUME), v))
                tl << "volume=" + QString::number(v);

            s.append(tl.join(","));
            s.append(" WHERE date=" + date);
        }
        else // new record, use insert
        {
            QStringList tl;
            s = "INSERT INTO " + symbol->table() + " (date,open,high,low,close,volume) VALUES(";

            tl << date;

            double v = 0;
            bar->get(bt.indexToString(BarType::_OPEN), v);
            tl << QString::number(v);

            v = 0;
            bar->get(bt.indexToString(BarType::_HIGH), v);
            tl << QString::number(v);

            v = 0;
            bar->get(bt.indexToString(BarType::_LOW), v);
            tl << QString::number(v);

            v = 0;
            bar->get(bt.indexToString(BarType::_CLOSE), v);
            tl << QString::number(v);

            v = 0;
            bar->get(bt.indexToString(BarType::_VOLUME), v);
            tl << QString::number(v);

            s.append(tl.join(","));
            s.append(")");
        }

        q.exec(s);
        if (q.lastError().isValid())
        {
            qDebug() << "Database::setBars:" << q.lastError().text();
            qDebug() << s;
            continue;
        }
    }
    _db.commit();
    return 1;
}
Esempio n. 30
0
static void
_hc08_genAssemblerPreamble (FILE * of)
{
    int i;
    int needOrg = 1;
    symbol *mainExists=newSymbol("main", 0);
    mainExists->block=0;

    fprintf (of, "\t.area %s\n",HOME_NAME);
    fprintf (of, "\t.area GSINIT0 (CODE)\n");
    fprintf (of, "\t.area %s\n",port->mem.static_name);
    fprintf (of, "\t.area %s\n",port->mem.post_static_name);
    fprintf (of, "\t.area %s\n",CODE_NAME);
    fprintf (of, "\t.area %s\n",port->mem.xinit_name);
    fprintf (of, "\t.area %s\n",port->mem.const_name);
    fprintf (of, "\t.area %s\n",port->mem.data_name);
    fprintf (of, "\t.area %s\n",port->mem.overlay_name);
    fprintf (of, "\t.area %s\n",port->mem.xdata_name);
    fprintf (of, "\t.area %s\n",port->mem.xidata_name);

    if ((mainExists=findSymWithLevel(SymbolTab, mainExists)))
    {
        // generate interrupt vector table
        fprintf (of, "\t.area\tCODEIVT (ABS)\n");

        for (i=maxInterrupts; i>0; i--)
        {
            if (interrupts[i])
            {
                if (needOrg)
                {
                    fprintf (of, "\t.org\t0x%04x\n", (0xfffe - (i * 2)));
                    needOrg = 0;
                }
                fprintf (of, "\t.dw\t%s\n", interrupts[i]->rname);
            }
            else
                needOrg = 1;
        }
        if (needOrg)
            fprintf (of, "\t.org\t0xfffe\n");
        fprintf (of, "\t.dw\t%s", "__sdcc_gs_init_startup\n\n");

        fprintf (of, "\t.area GSINIT0\n");
        fprintf (of, "__sdcc_gs_init_startup:\n");
        if (options.stack_loc)
        {
            fprintf (of, "\tldhx\t#0x%04x\n", options.stack_loc+1);
            fprintf (of, "\ttxs\n");
        }
        else
            fprintf (of, "\trsp\n");
        fprintf (of, "\tjsr\t__sdcc_external_startup\n");
        fprintf (of, "\tbeq\t__sdcc_init_data\n");
        fprintf (of, "\tjmp\t__sdcc_program_startup\n");
        fprintf (of, "__sdcc_init_data:\n");

        fprintf (of, "; _hc08_genXINIT() start\n");
        fprintf (of, "        ldhx #0\n");
        fprintf (of, "00001$:\n");
        fprintf (of, "        cphx #l_XINIT\n");
        fprintf (of, "        beq  00002$\n");
        fprintf (of, "        lda  s_XINIT,x\n");
        fprintf (of, "        sta  s_XISEG,x\n");
        fprintf (of, "        aix  #1\n");
        fprintf (of, "        bra  00001$\n");
        fprintf (of, "00002$:\n");
        fprintf (of, "; _hc08_genXINIT() end\n");

        fprintf (of, "\t.area GSFINAL\n");
        fprintf (of, "\tjmp\t__sdcc_program_startup\n\n");

        fprintf (of, "\t.area CSEG\n");
        fprintf (of, "__sdcc_program_startup:\n");
        fprintf (of, "\tjsr\t_main\n");
        fprintf (of, "\tbra\t.\n");

    }
}