OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /zipcpu/trunk/sw/zasm
    from Rev 14 to Rev 13
    Reverse comparison

Rev 14 → Rev 13

/zasm.cpp
0,0 → 1,108
////////////////////////////////////////////////////////////////////////////////
//
// Filename: zasm.cpp
//
// Project: Zip CPU -- a small, lightweight, RISC CPU core
//
// Purpose: This is a placeholder assembler, kept until I can get a working
// port of the binutils assembler et. al.
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Tecnology, LLC
//
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015, Gisselquist Technology, LLC
//
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. (It's in the $(ROOT)/doc directory, run make with no
// target there if the PDF file isn't present.) If not, see
// <http://www.gnu.org/licenses/> for a copy.
//
// License: GPL, v3, as defined and found on www.gnu.org,
// http://www.gnu.org/licenses/gpl.html
//
//
////////////////////////////////////////////////////////////////////////////////
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
 
#include "zopcodes.h"
#include "zparser.h"
 
void as_file(FILE *fout, FILE *fp) {
const int NZIP = 4096;
char ln[NZIP];
ZIPI ibuf[NZIP];
int nr;
ZPARSER zp;
ZPARSER::ZIPA za = 0x01c0000, bfa = 0;
int lineno = 0;
 
while(NULL != fgets(ln, NZIP, fp)) {
ZPARSER::ZIPI zi;
 
lineno++;
if (zp.iscomment(ln))
;
else if (zp.islabel(ln))
;
else if (zp.parse_op(ln, za, zi, lineno))
ibuf[bfa++] = zi;
else printf("ERROR, line %d: %s", lineno, ln);
if (bfa >= NZIP) {
fwrite(ibuf, sizeof(ZIPI), bfa, fout);
bfa = 0;
}
 
for(int i=0; i<nr; i++) {
zipi_to_string(ibuf[i], ln);
printf("%s\n", ln);
}
}
if (bfa > 0) {
fwrite(ibuf, sizeof(ZIPI), bfa, fout);
bfa = 0;
}
}
 
void as_file(FILE *fout, const char *fn) {
FILE *fp = fopen(fn, "r");
if (!fp) {
fprintf(stderr, "ERR: Cannot open %s\n", fn);
perror("O/S Err:");
return;
} as_file(fout, fp);
fclose(fp);
}
 
int main(int argc, char **argv) {
FILE *fp = fopen("z.out","w");
 
if (!fp) {
fprintf(stderr, "Could not open z.out\n");
perror("O/S Err:");
exit(-1);
}
if (argc == 1) {
as_file(fp, stdin);
} else for(int argn=1; argn<argc; argn++) {
if(access(argv[argn], R_OK)==0)
as_file(fp, argv[argn]);
}
 
return 0;
}
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.