Exemple #1
0
int DoSetups()
{
	UBYTE *setbuffer, *s, *t, *u /*, c */;
	int errors = 0;
	setbuffer = LoadInputFile((UBYTE *)setupfilename,SETUPFILE);
	if ( setbuffer ) {
/*
		The contents of the file are now in setbuffer.
		Each line is commentary or a single command.
		The buffer is terminated with a zero.
*/
		s = setbuffer;
		while ( *s ) {
			if ( *s == ' ' || *s == '\t' || *s == '*' || *s == '#' || *s == '\n' ) {
				while ( *s && *s != '\n' ) s++;
			}
			else if ( tolower(*s) < 'a' || tolower(*s) > 'z' ) {
				t = s;
				while ( *s && *s != '\n' ) s++;
/*
				c = *s; *s = 0;
				Error1("Setup file: Illegal statement: ",t);
				errors++; *s = c;
*/
			}
			else {
				t = s; /* name of the option */
				while ( tolower(*s) >= 'a' && tolower(*s) <= 'z' ) s++;
				*s++ = 0;
				while ( *s == ' ' || *s == '\t' ) s++;
				u = s; /* 'value' of the option */
				while ( *s && *s != '\n' && *s != '\r' ) s++;
				if ( *s ) *s++ = 0;
				errors += ProcessOption(t,u,0);
			}
			while ( *s == '\n' || *s == '\r' ) s++;
		}
		M_free(setbuffer,"setup file buffer");
	}
	if ( errors ) return(1);
	else return(0);
}
Exemple #2
0
int compile(int debug, int printSource, int printAssembly, int optimisation, char *fname)
{
    wchar_t *InputBuf;
    struct TokenStruct *Token;
    struct ContextStruct Context;
    int Result;

    /* Load the inputfile into memory. */
    InputBuf = LoadInputFile(fname);
    if (InputBuf == NULL) exit(1);
    
    if(printSource)
        printf("Input MAlice program:\n-- %s --\n%ls---\n\n",fname,InputBuf);

    /* Run the Parser. */
    Result = Parse(InputBuf,wcslen(InputBuf),TRIMREDUCTIONS,DEBUG,&Token);
    /* Interpret the results. */
    if (Result != PARSEACCEPT) {
        ShowErrorMessage(Token,Result);
        
        printf("\n[EXIT] Syntax Error\n");
        return 255;
    } else {
        /* Initialize the Context. */
        Context.Debug = DEBUG;
        Context.Indent = 0;
        Context.ReturnValue = NULL;

        /* Start execution by calling the subroutine of the first Token on
           the TokenStack. It's the "Start Symbol" that is defined in the
           grammar. */
        RuleJumpTable[Token->ReductionRule](Token,&Context);
    }
    
    //printTree(Token,0);
    
    int error = debug; // Used as debug flag and error reporting during CFG gen
    CFG * cfg = makeCFG(Token, optimisation, &error);
    if(error || cfg == 0)
    {
        printf("\n[EXIT] Compilation Error\n");
        return 255;
    }
    char* asmfname;
    asmfname = asmName(fname);
    
    genCode(cfg, asmfname);
    if(printAssembly)
    {
        printf("Generated assembly code:\n-- %s --\n",asmfname);
        printFile(asmfname);
        printf("---\n\n");
    }
    free(asmfname);

    char* exefname;
    exefname = exeName(fname);
    char fc[128];
    char sc[128];

    sprintf(fc ,"nasm -f elf32 %s.s -o %s.o", exefname, exefname);
    sprintf(sc ,"gcc -m32 %s.o -o %s", exefname, exefname);

    char * firstCommand = (char *)malloc(sizeof(char) * strlen(fc));
    char * secondCommand = (char *)malloc(sizeof(char) * strlen(sc));
    strcpy(firstCommand, fc);
    strcpy(secondCommand, sc);

    system(firstCommand);
    system(secondCommand);
    
    /* Cleanup. */
    DeleteTokens(Token);
    free(InputBuf);
    return 0;
}
Exemple #3
0
int main(int argc, char **argv)
{
	AdrenoVM vm;
	AdrenoContext ctx;
	AdrenoScript *script;
	AilCompiler c;
	long double start;
	int j;
	unsigned int size;
	char *data;
	
#ifdef USE_MEMORY_MANAGER
	AdrenoMM_Initialize();
#endif

	AdrenoVM_StaticInit();

	AdrenoVM_Initialize(&vm);
	AdrenoContext_Initialize(&ctx);

	AdrenoVM_LoadStdlib(&vm);

// 0 = Read Binary
// 1 = Compile
#define S_TYPE 0

#if S_TYPE == 0
	data = LoadInputFile("test.bin");
	script = AdrenoScript_Load(data);
	AdrenoFree(data);
#elif S_TYPE == 1
	AilCompiler_Initialize(&c, LoadInputFile("input.txt"));
	script = AilCompiler_Compile(&c);
	AilCompiler_Free(&c);
	AdrenoFree(c.Data);
#endif

	AdrenoContext_AttachScript(&ctx, script);

	start = GetTime();
	for (j = 0; j < 1; j++)
	{
		AdrenoContext_SetFunctionByName(&ctx, "main");
 		AdrenoVM_Run(&vm, &ctx);
	}
	start = GetTime() - start;
	printf("Time: %Lf\n", start);

	AdrenoScript_Free(script);
	AdrenoContext_Free(&ctx);
	AdrenoVM_Free(&vm);

	AdrenoVM_StaticDestroy();

#ifdef USE_MEMORY_MANAGER
	AdrenoMM_Final();
#endif

	getchar();
	return 0;
}