compiler

Unnamed Compiled Systems Language Project
git clone http://frotz.net/git/compiler.git
Log | Files | Refs

mkinstab.c (821B)


      1 // Copyright 2019, Brian Swetland <swetland@frotz.net>
      2 // Licensed under the Apache License, Version 2.0.
      3 
      4 #include <stdio.h>
      5 #include <stdint.h>
      6 #include <string.h>
      7 #include <ctype.h>
      8 
      9 int main(int argc, char** argv) {
     10 	char line[128];
     11 	while (fgets(line, sizeof(line), stdin) != NULL) {
     12 		unsigned end = strlen(line);
     13 		while (end > 0) {
     14 			end--;
     15 			if (!isspace(line[end])) break;
     16 			line[end] = 0;
     17 		}
     18 		if ((line[0] == 0) || (line[0] == '#') ||
     19 			isspace(line[0]) || (end < 34)) {
     20 			continue;
     21 		}
     22 		uint32_t mask = 0, bits = 0;
     23 		for (unsigned n = 0; n < 32; n++) {
     24 			uint32_t bit = 1U << (31 - n);
     25 			switch (line[n]) {
     26 			case '1':
     27 				mask |= bit;
     28 				bits |= bit;
     29 				break;
     30 			case '0':
     31 				mask |= bit;
     32 				break;
     33 			} 
     34 		}
     35 		printf("{ 0x%08x, 0x%08x, \"%s\" },\n", mask, bits, line + 33);
     36 	}
     37 	return 0;
     38 }