Esempio n. 1
0
void initAssemblyOutput(char const *path) {
	output = fopen(path, "w");
	if(output == NULL) {
		fprintf(stderr, "Le fichier de sortie \"%s\" n'a pas pu être ouvert : %s\n", path, strerror(errno));
		exit(OPEN_OUTPUT_FAILURE);
	}
	assemblyBuffer = malloc(1);
	assemblyBuffer[0] = '\0';
	globalBuffer = malloc(1);
	globalBuffer[0] = '\0';

	ifLabels.size = loopLabels.size = gotoLabels.size = 0;
	ifLabels.stackSize = loopLabels.stackSize = gotoLabels.stackSize = 0;
	addressStack.size = 0;
	for(int i = 0; i < MAX_SIZE; ++i) {
		ifLabels.labels[i].jumpAddress = loopLabels.labels[i].jumpAddress = 0;
		gotoLabels.labels[i].jumpAddress = -1;
		ifLabels.stack[i] = loopLabels.stack[i] = gotoLabels.stack[i] = NULL;
		returnAddressStack.address[i] = NULL;
		gotoLabels.labels[i].name = NULL;
	}

	setGlobalScope(false);

	returnAddressStack.size = 1;
	returnAddressStack.address[0] = strdup("EOF"UNKNOWN_ADDRESS);
	assemblyOutput(JMP" EOC"UNKNOWN_ADDRESS" ; Saut à l'initialisation des variables globales");

	setGlobalScope(true);

#ifndef STRIP_COMMENTS
	assemblyOutput(COP" 0 0 ; Initialisation des variables globales");
#endif
}
Esempio n. 2
0
dereferencedSymbol_t createString(char const *value) {
	bool const oldGlobalScope = getGlobalScope();

	setGlobalScope(true);

	int len = strlen(value) + 1;
	char *interningName;
	asprintf(&interningName, "__internedString__%s", value);

	dereferencedSymbol_t deref = getExistingSymbol(interningName, false);
	symbol_t *tab = deref.symbol;
	if(tab == &dummy) {
		tab = createArray(interningName, (varType_t){.indirectionCount = 0, .baseType = BT_CHAR, .constMask = 1}, len);
Esempio n. 3
0
SymbolTable::SymbolTable(const std::string& unit)
    : _unit(unit), _typeBuilder(new TypeBuilder) {

    setGlobalScope();
}