argument *forward_ref_arg(char *symbol, qualifier q) { argument *arg = (argument *) malloc(sizeof (argument)); arg->mode = mode_label_undef; arg->value = 0; arg->index = (sym_val_t) cpstring(symbol); arg->qual = q; arg->next = NULL; return arg; }
instruction *make_meta_instruction(char *keyword, argument *arg_chain) { instruction *instr = (instruction *) malloc(sizeof (instruction)); instr->instruction = cpstring(keyword); instr->opcode = -1; instr->meta_instruction = (meta_instruction_def *) symbol_value(keywords, keyword); instr->args = arg_chain; instr->next = NULL; return instr; }
instruction *make_instruction(char *text) { instruction *instr = (instruction *) malloc(sizeof (instruction)); instr->instruction = cpstring(text); instr->opcode = symbol_value(opcodes, text); instr->meta_instruction = NULL; instr->args = NULL; instr->next = NULL; return instr; }
new_iob_data(register io_setup *ios, char *name) #endif { register iob_data *iod; register char **s, **se; iod = (iob_data *) mem(sizeof(iob_data) + ios->nelt*sizeof(char *), 1); iod->next = iob_list; iob_list = iod; iod->type = ios->fields[0]; iod->name = cpstring(name); s = iod->fields; se = s + ios->nelt; while(s < se) *s++ = "0"; *s = 0; }
void set_output_file(output_thingy *out, char *file) { free(out->output_file); out->output_file = cpstring(file); }
int quence(char *src, char *output) { output_thingy *out; int sz_theory; int sz_actual; int success; int err; /* Parse the input file */ // if (src[0] = 0) // yyin = stdin; // else // yyin = fopen(src, "r"); err = start_preprocessor(preprocessor, src, &yyin); switch (err) { case 0 : break; case 1 : eprintf("Preprocessor executable \"%s\" not found.\n", preprocessor); break; case 2 : eprintf("Could not open input file \"%s\" for reading.\n", src); break; case 3 : eprintf("Preprocessor \"%s\" returned error on file \"%s\".\n", preprocessor, src); break; default : eprintf("Unknown preprocessor error (%d).\n", err); } if (err) return 1; asm_source_file = cpstring(src); asm_base_file = cpstring(src); asm_linenum = 1; success = (yyparse() == 0); /* Close input file, and delete temporary file if used */ if (fileno(yyin) != STDIN_FILENO) { fclose(yyin); if (preprocessor != NULL) unlink(CPP_TEMP_FILE); } if (! success) return 1; /* Check for unresolvable label refs */ if (resolve_all_label_refs(parsed_text) != 0) { eprintf("Unresolved labels (and number of occurences):\n"); print_table(0, unresolved_labels); eprintf("\n"); return 2; } /* Print parsed text */ d_printf(2, "Input file %s parsed as follows:\n", src); print_text(2, parsed_text); d_printf(2, "\n"); /* output assembled data */ out = new_output(src); if (output) set_output_file(out, output); sz_theory = encoded_text_size(parsed_text); sz_actual = compile_text(out, parsed_text); if (sz_theory == sz_actual) { output_data(out); eprintf("Syntax OK: %d bytes written.\n", sz_actual); } else { if (! safe_write) { output_data(out); eprintf("Internal compile error: %d of %d bytes written.\n", sz_actual, sz_theory); } else { eprintf("Internal compile error: %d of %d bytes generated (0 written).\n", sz_actual, sz_theory); } return 3; } return 0; }