Exemple #1
0
static void NewSymbol (const char* SymName, long Val)
/* Define a symbol with a fixed numeric value in the current scope */
{
    ExprNode* Expr;
    SymEntry* Sym;

    /* Convert the name to a string buffer */
    StrBuf SymBuf = STATIC_STRBUF_INITIALIZER;
    SB_CopyStr (&SymBuf, SymName);

    /* Search for the symbol, allocate a new one if it doesn't exist */
    Sym = SymFind (CurrentScope, &SymBuf, SYM_ALLOC_NEW);

    /* Check if have already a symbol with this name */
    if (SymIsDef (Sym)) {
        AbEnd ("`%s' is already defined", SymName);
    }

    /* Generate an expression for the symbol */
    Expr = GenLiteralExpr (Val);

    /* Mark the symbol as defined */
    SymDef (Sym, Expr, ADDR_SIZE_DEFAULT, SF_NONE);

    /* Free string buffer memory */
    SB_Done (&SymBuf);
}
Exemple #2
0
static void CheckSegName (const char* Seg)
/* Abort if the given name is not a valid segment name */
{
    /* Print an error and abort if the name is not ok */
    if (!ValidSegName (Seg)) {
        AbEnd ("Segment name `%s' is invalid", Seg);
    }
}
Exemple #3
0
static void FileNameOption (const char* Opt, const char* Arg, StrBuf* Name)
/* Handle an option that remembers a file name for later */
{
    /* Cannot have the option twice */
    if (SB_NotEmpty (Name)) {
        AbEnd ("Cannot use option `%s' twice", Opt);
    }
    /* Remember the file name for later */
    SB_CopyStr (Name, Arg);
    SB_Terminate (Name);
}
Exemple #4
0
static OptFunc* GetOptFunc (const char* Name)
/* Find an optimizer step by name in the table and return a pointer. Print an
** error and call AbEnd if not found.
*/
{
    /* Search for the function in the list */
    OptFunc* F = FindOptFunc (Name);
    if (F == 0) {
        /* Not found */
        AbEnd ("Optimization step `%s' not found", Name);
    }
    return F;
}
Exemple #5
0
static void SetSys (const char* Sys)
/* Define a target system */
{
    switch (Target = FindTarget (Sys)) {

        case TGT_NONE:
            break;

        case TGT_MODULE:
            AbEnd ("Cannot use `module' as a target for the assembler");
            break;

        case TGT_ATARI:
            NewSymbol ("__ATARI__", 1);
            break;

        case TGT_ATARIXL:
            NewSymbol ("__ATARI__", 1);
            NewSymbol ("__ATARIXL__", 1);
            break;

        case TGT_C16:
            CBMSystem ("__C16__");
            break;

        case TGT_C64:
            CBMSystem ("__C64__");
            break;

        case TGT_VIC20:
            CBMSystem ("__VIC20__");
            break;

        case TGT_C128:
            CBMSystem ("__C128__");
            break;

        case TGT_PLUS4:
            CBMSystem ("__C16__");
            NewSymbol ("__PLUS4__", 1);
            break;

        case TGT_CBM510:
            CBMSystem ("__CBM510__");
            break;

        case TGT_CBM610:
            CBMSystem ("__CBM610__");
            break;

        case TGT_PET:
            CBMSystem ("__PET__");
            break;

        case TGT_BBC:
            NewSymbol ("__BBC__", 1);
            break;

        case TGT_APPLE2:
            NewSymbol ("__APPLE2__", 1);
            break;

        case TGT_APPLE2ENH:
            NewSymbol ("__APPLE2__", 1);
            NewSymbol ("__APPLE2ENH__", 1);
            break;

        case TGT_GEOS_CBM:
            /* Do not handle as a CBM system */
            NewSymbol ("__GEOS__", 1);
            NewSymbol ("__GEOS_CBM__", 1);
            break;

        case TGT_GEOS_APPLE:
            NewSymbol ("__GEOS__", 1);
            NewSymbol ("__GEOS_APPLE__", 1);
            break;

        case TGT_LUNIX:
            NewSymbol ("__LUNIX__", 1);
            break;

        case TGT_ATMOS:
            NewSymbol ("__ATMOS__", 1);
            break;

        case TGT_NES:
            NewSymbol ("__NES__", 1);
            break;

        case TGT_SUPERVISION:
            NewSymbol ("__SUPERVISION__", 1);
            break;

        case TGT_SNES:
            NewSymbol ("__SNES__", 1);
            break;

        case TGT_LYNX:
            NewSymbol ("__LYNX__", 1);
            break;

        case TGT_SIM6502:
            NewSymbol ("__SIM6502__", 1);
            break;

        case TGT_SIM65C02:
            NewSymbol ("__SIM65C02__", 1);
            break;

        default:
            AbEnd ("Invalid target name: `%s'", Sys);

    }

    /* Initialize the translation tables for the target system */
    TgtTranslateInit ();
}
Exemple #6
0
static void SetSys (const char* Sys)
/* Define a target system */
{
    switch (Target = FindTarget (Sys)) {

        case TGT_NONE:
            break;

        case TGT_MODULE:
            AbEnd ("Cannot use `module' as a target for the compiler");
            break;

        case TGT_ATARI:
            DefineNumericMacro ("__ATARI__", 1);
            break;

        case TGT_ATARIXL:
            DefineNumericMacro ("__ATARI__", 1);
            DefineNumericMacro ("__ATARIXL__", 1);
            break;

        case TGT_C16:
            cbmsys ("__C16__");
            break;

        case TGT_C64:
            cbmsys ("__C64__");
            break;

        case TGT_VIC20:
            cbmsys ("__VIC20__");
            break;

        case TGT_C128:
            cbmsys ("__C128__");
            break;

        case TGT_PLUS4:
            cbmsys ("__C16__");
            DefineNumericMacro ("__PLUS4__", 1);
            break;

        case TGT_CBM510:
            cbmsys ("__CBM510__");
            break;

        case TGT_CBM610:
            cbmsys ("__CBM610__");
            break;

        case TGT_PET:
            cbmsys ("__PET__");
            break;

        case TGT_BBC:
            DefineNumericMacro ("__BBC__", 1);
            break;

        case TGT_APPLE2:
            DefineNumericMacro ("__APPLE2__", 1);
            break;

        case TGT_APPLE2ENH:
            DefineNumericMacro ("__APPLE2__", 1);
            DefineNumericMacro ("__APPLE2ENH__", 1);
            break;

        case TGT_GEOS_CBM:
            /* Do not handle as a CBM system */
            DefineNumericMacro ("__GEOS__", 1);
            DefineNumericMacro ("__GEOS_CBM__", 1);
            break;

        case TGT_GEOS_APPLE:
            DefineNumericMacro ("__GEOS__", 1);
            DefineNumericMacro ("__GEOS_APPLE__", 1);
            break;

        case TGT_LUNIX:
            DefineNumericMacro ("__LUNIX__", 1);
            break;

        case TGT_ATMOS:
            DefineNumericMacro ("__ATMOS__", 1);
            break;

        case TGT_NES:
            DefineNumericMacro ("__NES__", 1);
            break;

        case TGT_SUPERVISION:
            DefineNumericMacro ("__SUPERVISION__", 1);
            break;

        case TGT_LYNX:
            DefineNumericMacro ("__LYNX__", 1);
            break;

        case TGT_SIM6502:
            DefineNumericMacro ("__SIM6502__", 1);
            break;

        case TGT_SIM65C02:
            DefineNumericMacro ("__SIM65C02__", 1);
            break;

        default:
            AbEnd ("Unknown target system type %d", Target);
    }

    /* Initialize the translation tables for the target system */
    TgtTranslateInit ();
}
Exemple #7
0
static void InternalDumpExpr (const ExprNode* Expr, const ExprNode* (*ResolveSym) (const struct SymEntry*))
/* Dump an expression in RPN to stdout */
{
    if (Expr == 0) {
        return;
    }
    InternalDumpExpr (Expr->Left, ResolveSym);
    InternalDumpExpr (Expr->Right, ResolveSym);

    switch (Expr->Op) {

        case EXPR_LITERAL:
        case EXPR_ULABEL:
            printf (" $%04lX", Expr->V.IVal);
            break;

        case EXPR_SYMBOL:
            printf (" SYM(");
            if (ResolveSym && (Expr = ResolveSym (Expr->V.Sym)) != 0) {
                InternalDumpExpr (Expr, ResolveSym);
            }
            printf (") ");
            break;

        case EXPR_SECTION:
            printf (" SEC");
            break;

        case EXPR_SEGMENT:
            printf (" SEG");
            break;

        case EXPR_MEMAREA:
            printf (" MEM");
            break;

        case EXPR_PLUS:
            printf (" +");
            break;

        case EXPR_MINUS:
            printf (" -");
            break;

        case EXPR_MUL:
            printf (" *");
            break;

        case EXPR_DIV:
            printf (" /");
            break;

        case EXPR_MOD:
            printf (" MOD");
            break;

        case EXPR_OR:
            printf (" OR");
            break;

        case EXPR_XOR:
            printf (" XOR");
            break;

        case EXPR_AND:
            printf (" AND");
            break;

        case EXPR_SHL:
            printf (" SHL");
            break;

        case EXPR_SHR:
            printf (" SHR");
            break;

        case EXPR_EQ:
            printf (" =");
            break;

        case EXPR_NE:
            printf ("<>");
            break;

        case EXPR_LT:
            printf (" <");
            break;

        case EXPR_GT:
            printf (" >");
            break;

        case EXPR_LE:
            printf (" <=");
            break;

        case EXPR_GE:
            printf (" >=");
            break;

        case EXPR_BOOLAND:
            printf (" BOOL_AND");
            break;

        case EXPR_BOOLOR:
            printf (" BOOL_OR");
            break;

        case EXPR_BOOLXOR:
            printf (" BOOL_XOR");
            break;

        case EXPR_MAX:
            printf (" MAX");
            break;

        case EXPR_MIN:
            printf (" MIN");
            break;

        case EXPR_UNARY_MINUS:
            printf (" NEG");
            break;

        case EXPR_NOT:
            printf (" ~");
            break;

        case EXPR_SWAP:
            printf (" SWAP");
            break;

        case EXPR_BOOLNOT:
            printf (" BOOL_NOT");
            break;

        case EXPR_BANK:
            printf (" BANK");
            break;

        case EXPR_BYTE0:
            printf (" BYTE0");
            break;

        case EXPR_BYTE1:
            printf (" BYTE1");
            break;

        case EXPR_BYTE2:
            printf (" BYTE2");
            break;

        case EXPR_BYTE3:
            printf (" BYTE3");
            break;

        case EXPR_WORD0:
            printf (" WORD0");
            break;

        case EXPR_WORD1:
            printf (" WORD1");
            break;

        case EXPR_FARADDR:
            printf (" FARADDR");
            break;

        case EXPR_DWORD:
            printf (" DWORD");
            break;

        default:
            AbEnd ("Unknown Op type: %u", Expr->Op);

    }
}
Exemple #8
0
static void DefaultCheckFailed (const char* Msg, const char* Cond,
                                const char* File, unsigned Line)
{
    /* Output a diagnostic and abort */
    AbEnd ("%s%s, file `%s', line %u", Msg, Cond, File, Line);
}