Fixed byte, string directives.

git-svn-id: http://www.cdkersey.com/harp/harptool@118 0246edb2-e076-4747-b392-db732a341fa2
This commit is contained in:
chad
2013-01-18 05:11:27 +00:00
parent ea03ccb47d
commit 4956625a86
6 changed files with 69 additions and 70 deletions

View File

@@ -1,3 +0,0 @@
_ The assembly writer for the disassembler uses the old assembly format.
_ The BYTE directive was not updated when the word directive was; inconsistent
behavior.

View File

@@ -1,15 +1,14 @@
- Anonymous chunks whose names are not saved by the object writer. - Anonymous chunks whose names are not saved by the object writer.
- 32-bit coding for larger-pointered architecture versions. - 32-bit instruction encoding for larger-pointered architecture versions.
- HOFDump mode for HARPTool/HOFTool - HOFDump mode for HARPTool/HOFTool
- Make operation information tables into functions of Instruction, if possible. - Make operation information tables into member functions of Instruction, if
possible.
- Anonymous assigned values in the assembler. - Anonymous assigned values in the assembler.
- References (pointers) as .word directive contents in the assembler. - References (pointers) as .word directive contents in the assembler.
- .byte directive for assembler.
- Make assembler writer capable of writing binary data without making size of
output a multiple of word size. Useful in pre-assembled code.
- Instruction validation before encoding. - Instruction validation before encoding.
- Make readError in obj.cpp throw something instead of printing the whine and - Make readError in obj.cpp throw something instead of printing a message and
exiting. exiting.
- Limit checking for byte/word encoders (e.g. 255 pRegs, 256 regs for byte) - Limit checking for byte/word encoders (e.g. 255 pRegs, 256 regs for byte)
- Eliminate the tmp_buf nonsense from the chunk encoder. - Eliminate the tmp_buf nonsense from the chunk encoder.
- Loosen arch restrictions imposed for interoperability. - Loosen arch restrictions imposed for interoperability (the number of lanes is
typically unimportant)

View File

@@ -213,34 +213,48 @@ Obj *AsmReader::read(std::istream &input) {
dc->contents.resize(dc->size); dc->contents.resize(dc->size);
for (size_t i = oldSize; i < dc->size; ++i) dc->contents[i] = 0; for (size_t i = oldSize; i < dc->size; ++i) dc->contents[i] = 0;
} break; } break;
case ST_BYTE1: dc->size += yylval.u; case ST_BYTE1:
state = ST_INIT; if (outstate != OS_DATACHUNK) {
break; // TODO: more of this pasted code
case ST_BYTE2: if (outstate == OS_DATACHUNK) { outstate = OS_DATACHUNK;
dc->size++; dc = new DataChunk(next_chunk_name, next_chunk_align?
dc->contents.resize(dc->size); next_chunk_align:wordSize,
*(dc->contents.end() - 1) = yylval.u; flagsToWord(permR, permW, permX));
} else { next_chunk_align = 0;
asmReaderError(yyline, "Byte not in data chunk" o->chunks.push_back(dc);
"(internal error)"); if (entry) o->entry = o->chunks.size() - 1;
} if (global) dc->setGlobal();
state = ST_INIT; }
break; dc->size++;
case ST_ALIGN: next_chunk_align = yylval.u; dc->contents.resize(dc->size);
if (outstate != OS_NOCHUNK) { *(dc->contents.end() - 1) = yylval.u;
outstate = OS_NOCHUNK; state = ST_INIT;
entry = false; break;
global = false; case ST_ALIGN:
} next_chunk_align = yylval.u;
state = ST_INIT; if (outstate != OS_NOCHUNK) {
break; outstate = OS_NOCHUNK;
entry = false;
global = false;
}
state = ST_INIT;
break;
default: asmReaderError(yyline, "Unexpected literal argument"); default: asmReaderError(yyline, "Unexpected literal argument");
} }
break; break;
case ASM_T_DIR_ARG_STRING: case ASM_T_DIR_ARG_STRING:
if (state == ST_STRING2 || if (state == ST_STRING1) {
(state == ST_STRING1 && outstate == OS_DATACHUNK)) if (outstate != OS_DATACHUNK) {
{ // TODO: pasted code (see above)
outstate = OS_DATACHUNK;
dc = new DataChunk(next_chunk_name,
next_chunk_align?next_chunk_align:wordSize,
flagsToWord(permR, permW, permX));
next_chunk_align = 0;
o->chunks.push_back(dc);
if (entry) o->entry = o->chunks.size() - 1;
if (global) dc->setGlobal();
}
const char *s = yylval.s.c_str(); const char *s = yylval.s.c_str();
do { do {
if (*s == '\\') { if (*s == '\\') {
@@ -262,26 +276,6 @@ Obj *AsmReader::read(std::istream &input) {
case ASM_T_DIR_ARG_SYM: case ASM_T_DIR_ARG_SYM:
switch (state) { switch (state) {
case ST_DEF1: string_arg = yylval.s; state = ST_DEF2; break; case ST_DEF1: string_arg = yylval.s; state = ST_DEF2; break;
case ST_BYTE1: {
state = ST_BYTE2;
outstate = OS_DATACHUNK;
dc = new DataChunk(yylval.s, next_chunk_align,
flagsToWord(permR, permW, permX));
next_chunk_align = 0;
o->chunks.push_back(dc);
if (entry) o->entry = o->chunks.size() - 1;
if (global) dc->setGlobal();
} break;
case ST_STRING1: {
state = ST_STRING2;
outstate = OS_DATACHUNK;
dc = new DataChunk(yylval.s, next_chunk_align,
flagsToWord(permR, permW, permX));
next_chunk_align = 0;
o->chunks.push_back(dc);
if (entry) o->entry = o->chunks.size() - 1;
if (global) dc->setGlobal();
} break;
default: asmReaderError(yyline, ""); default: asmReaderError(yyline, "");
}; };
break; break;
@@ -392,8 +386,6 @@ Obj *AsmReader::read(std::istream &input) {
} }
void AsmWriter::write(std::ostream &output, const Obj &obj) { void AsmWriter::write(std::ostream &output, const Obj &obj) {
unsigned anonWordNum(0);
Word prevFlags(0); Word prevFlags(0);
for (size_t j = 0; j < obj.chunks.size(); j++) { for (size_t j = 0; j < obj.chunks.size(); j++) {
@@ -439,10 +431,10 @@ void AsmWriter::write(std::ostream &output, const Obj &obj) {
} }
if (i == tmpWordSize && c->name != "") { if (i == tmpWordSize && c->name != "") {
output << ".word " << c->name << " 0x" << hex << w << '\n'; output << c->name << ':' << endl;
output << " .word " << " 0x" << hex << w << endl;
} else { } else {
output << ".word __anonWord" << anonWordNum++ << " 0x" output << " .word " << " 0x" << hex << w << endl;
<< hex << w << '\n';
} }
} }

View File

@@ -1,12 +1,15 @@
HARPLD = ../harptool -L HARPLD = ../harptool -L
HARPAS = ../harptool -A HARPAS = ../harptool -A
HARPEM = ../harptool -E HARPEM = ../harptool -E
4BARCH = 4b16/16/2 HARPDIS = ../harptool -D
4BARCH = 4b16/16/2
all: simple.bin sieve.bin 2thread.bin simple.4b.bin sieve.4b.bin 2thread.4b.bin all: simple.bin sieve.bin 2thread.bin simple.4b.bin sieve.4b.bin 2thread.4b.bin
run: simple.out sieve.out 2thread.out simple.4b.out sieve.4b.out 2thread.4b.out run: simple.out sieve.out 2thread.out simple.4b.out sieve.4b.out 2thread.4b.out
disas: simple.d sieve.d 2thread.d simple.4b.d sieve.4b.d 2thread.4b.d
%.4b.out : %.4b.bin %.4b.out : %.4b.bin
$(HARPEM) -a $(4BARCH) -c $< > $@ $(HARPEM) -a $(4BARCH) -c $< > $@
@@ -43,5 +46,11 @@ sieve.4b.bin : boot.4b.HOF lib.4b.HOF sieve.4b.HOF
%.HOF : %.s %.HOF : %.s
$(HARPAS) -o $@ $< $(HARPAS) -o $@ $<
%.4b.d : %.4b.HOF
$(HARPDIS) -o $@ --arch $(4BARCH) $<
%.d : %.HOF
$(HARPDIS) -o $@ $<
clean: clean:
rm -f *.HOF *.bin *.out *~ rm -f *.HOF *.bin *.out *.d *~

View File

@@ -78,10 +78,10 @@ loop4: ld %r1, %r0, array;
trap; /* All traps currently cause a halt. */ trap; /* All traps currently cause a halt. */
.perm rw /* TODO: How should I write section permissions? */ .perm rw /* TODO: How should I write section permissions? */
.string hello "\"Harp!\" is how a harp seal says hello!\n" hello: .string "\"Harp!\" is how a harp seal says hello!\n"
.string wrstr "Doing write\n" wrstr: .string "Doing write\n"
.string wrfin "Done write\n" wrfin: .string "Did write\n"
.string xstr "Exiting loop\n" xstr: .string "Exiting loop\n"
.global .global
array: .space 0x1000 /* SIZE words of space. */ array: .space 0x1000 /* SIZE words of space. */

View File

@@ -18,5 +18,7 @@ entry: ldi %r7, hello
trap; /* All traps currently cause a halt. */ trap; /* All traps currently cause a halt. */
.perm rw /* TODO: How should I write section permissions? */ .perm rw /* TODO: How should I write section permissions? */
/* TODO: String literals! */
.string hello "\"Harp!\" is how a harp seal says hello!\n" hello:
.byte 0x22
.string "Harp!\" is how a harp seal says hello!\n"